[LTP] [PATCH 1/2] lib: initialize lib|main_pid to zero in the setup_ipc
Li Wang
liwang@redhat.com
Tue May 13 14:42:43 CEST 2025
On Tue, May 13, 2025 at 8:08 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > To get rid of failure from github CI.
> >
> > CI Test Job: https://github.com/wangli5665/ltp/actions/runs/14988530205
> >
> > Follow-up-fix: commit b987b8ac5 ("lib: child process exit with error due to uninitialized lib_pid")
> > Signed-off-by: Li Wang <liwang@redhat.com>
> > ---
> > lib/tst_test.c | 15 ++++++++-------
> > 1 file changed, 8 insertions(+), 7 deletions(-)
> >
> > diff --git a/lib/tst_test.c b/lib/tst_test.c
> > index b666715b9..9f11c1c47 100644
> > --- a/lib/tst_test.c
> > +++ b/lib/tst_test.c
> > @@ -59,7 +59,6 @@ static const char *tid;
> > static int iterations = 1;
> > static float duration = -1;
> > static float timeout_mul = -1;
> > -static pid_t lib_pid;
> > static int mntpoint_mounted;
> > static int ovl_mounted;
> > static struct timespec tst_start_time; /* valid only for test pid */
> > @@ -143,7 +142,9 @@ static void setup_ipc(void)
> > tst_futexes = (char *)results + sizeof(struct results);
> > tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
> > }
> > - results->lib_pid = lib_pid;
> > +
> > + results->lib_pid = 0;
> > + results->main_pid = 0;
> > }
> >
> > static void cleanup_ipc(void)
> > @@ -394,7 +395,7 @@ void tst_vbrk_(const char *file, const int lineno, int ttype, const char *fmt,
> > * If tst_brk() is called from some of the C helpers even before the
> > * library was initialized, just exit.
> > */
> > - if (!results->lib_pid)
> > + if (!results || !results->lib_pid)
> > exit(TTYPE_RESULT(ttype));
> >
> > update_results(TTYPE_RESULT(ttype));
> > @@ -1334,6 +1335,8 @@ static void do_setup(int argc, char *argv[])
> > tst_test->forks_child = 1;
> > }
> >
> > + setup_ipc();
> > +
> > if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
> > tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
> >
> > @@ -1393,8 +1396,6 @@ static void do_setup(int argc, char *argv[])
> > if (tst_test->hugepages.number)
> > tst_reserve_hugepages(&tst_test->hugepages);
> >
> > - setup_ipc();
> > -
>
> I suppose that this has to go before the tst_reserve_hugepages() so that
> we have results->lib_pid defined and properly clean up after the
> hugepages. However for that to work we have to set the
> results->lib_pid directly in the setup_ipc().
In this patch, setup_ipc() is already moved up before the
tst_reserve_hugpages(). I particularly put it after tst_test->runs_scripts,
which is mandatory to have .child_needs_reinit initialized first.
And the hugpages cleanup work is completed in tst_sys_conf_restore(0)
in the do_cleanup, so that might not be a problem.
I have validated that all hugetlb tests work well.
Also,
Or, did I miss anything?
>
> > if (tst_test->bufs)
> > tst_buffers_alloc(tst_test->bufs);
> >
> > @@ -1929,10 +1930,11 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
> > unsigned int test_variants = 1;
> > struct utsname uval;
> >
> > - lib_pid = getpid();
> > tst_test = self;
> >
> > do_setup(argc, argv);
> > +
> > + results->lib_pid = getpid();
>
> Setting it here is too late.
Since I added results exists check in tst_vbrk_(), so it should be safe
enough to set lib_pid just after setup_ipc() whatever the cleanup work
happen early or later in test lib.
if (!results || !results->lib_pid)
exit(TTYPE_RESULT(ttype));
>
> Other than that the patch looks good to me.
>
> --
> Cyril Hrubis
> chrubis@suse.cz
>
--
Regards,
Li Wang
More information about the ltp
mailing list