[systemd-devel] [PATCH 2/2] test: wait for cloned thread to exit
Lennart Poettering
lennart at poettering.net
Tue Dec 23 06:43:05 PST 2014
On Mon, 22.12.14 11:57, Filipe Brandenburger (filbranden at google.com) wrote:
> Ping?
I got none of these emails, and they are neither shown in the mailing
list archives. There must be something wrong in the mail delivery
between google.com and fdo?
> On Thu, Dec 18, 2014 at 11:24 AM, Filipe Brandenburger
> <filbranden at google.com> wrote:
> > In test_raw_clone, make sure the cloned thread calls _exit() and in the parent
> > thread call waitpid(..., __WCLONE) to wait for the child thread to terminate,
> > otherwise there is a race condition where the child thread will log to the
> > console after the test process has already exited and the assertion from the
> > child thread might not be enforced.
> >
> > The absence of this patch might also create problems for other tests that would
> > be added after this one, since potentially both parent and child would run
> > those tests as the child would continue running.
> >
> > Tested by confirming that the logs from the child are printed before the test
> > terminates and that a false assertion in the child aborts the test with a core
> > dump.
> > ---
> > src/test/test-util.c | 9 +++++++--
> > 1 file changed, 7 insertions(+), 2 deletions(-)
> >
> > diff --git a/src/test/test-util.c b/src/test/test-util.c
> > index ec04744..997e3df 100644
> > --- a/src/test/test-util.c
> > +++ b/src/test/test-util.c
> > @@ -1325,10 +1325,15 @@ static void test_raw_clone(void) {
> > pid2 = raw_getpid();
> > log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT,
> > pid, getpid(), pid2);
> > - if (pid == 0)
> > + if (pid == 0) {
> > assert_se(pid2 != parent);
> > - else
> > + _exit(EXIT_SUCCESS);
> > + } else {
> > + int status;
> > assert_se(pid2 == parent);
> > +
> > + waitpid(pid, &status, __WCLONE);
> > + }
> > }
> >
> > int main(int argc, char *argv[]) {
> > --
> > 1.8.3.1
> >
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list