[LTP] [PATCH 1/2] lib: initialize lib|main_pid to zero in the setup_ipc

Li Wang liwang@redhat.com
Wed May 14 10:18:53 CEST 2025


On Wed, May 14, 2025 at 4:00 PM Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > > > @@ -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?
>
> The problem is that no library cleanup will happen unless lib_pid is
> set, that means that tst_brk() will be triggered anywhere in do_setup()
> the clanup will not be run because we set the lib_pid after the
> do_setup() in the patch.

I see, and you're right we have to set lib_pid before any real setup.

Does this change below make sense (based on the v2 I just sent)?

--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -144,6 +144,8 @@ static void setup_ipc(void)
        }

        memset(results, 0 , size);
+
+       results->lib_pid = getpid();
 }

 static void cleanup_ipc(void)
@@ -1933,7 +1935,6 @@ void tst_run_tcases(int argc, char *argv[],
struct tst_test *self)

        do_setup(argc, argv);

-       results->lib_pid = getpid();
        tst_enable_oom_protection(results->lib_pid);

        SAFE_SIGNAL(SIGALRM, alarm_handler);



-- 
Regards,
Li Wang



More information about the ltp mailing list