[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [OSSTEST PATCH] standalone-generate-dump-flight-runvars: Handle ^C properly



Ian Jackson writes ("[OSSTEST PATCH] standalone-generate-dump-flight-runvars: 
Handle ^C properly"):
> This is all mad.
...
> +# I _think_ that that any signal which arrives before the assignment
> +# to $SIG{} will definitely have caused our parent to vanish and us to
> +# be reparented to pid 1 by the time we do the getppid check.  But TBH
> +# I can't find any clear support for this requirement.  So the result
> +# may still be slightly racy in the case that s-g-d-f-r is ^C'd right
> +# after starting.

The test program below demonstrates that this assuption is not true.
However, a better approach is likely to be absurdly complex, involving
the parent shell having an INT trap which conducts an explicit
rendezvous with ?each child.

Ian.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <assert.h>
#include <sys/poll.h>
#include <sys/types.h>
#include <sys/wait.h>

static pid_t willdie, child, parent;

static void runtest(void) {
    willdie = getpid();  assert(willdie>=0);
    child = fork();  assert(child>=0);
    if (!child) {
        kill(willdie, SIGUSR1);
        parent = getppid();
        //        sleep(1);
        if (parent==1) _exit(0);
        fprintf(stderr,"willdie=%ld parent=%ld\n",
                (long)willdie,(long)parent);
        _exit(1);
    }
    for (;;)
        ;
}

int main(int argc, char **argv) {
    int st;

    for (;;) {
        willdie = fork();  assert(willdie>=0);
        if (!willdie) runtest();
        pid_t got = waitpid(willdie, &st, 0);
        assert(got==willdie);
        assert(WIFSIGNALED(st) && WTERMSIG(st)==SIGUSR1);
    }
}

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.