From: Ian Jackson Subject: Re: [OSSTEST PATCH] standalone-generate-dump-flight-runvars: Handle ^C properly Date: Fri, 9 Oct 2015 19:06:03 +0100 Message-ID: <22040.523.598355.581657@mariner.uk.xensource.com> References: <1444410785-1271-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Zkc3U-0006p2-2e for xen-devel@lists.xenproject.org; Fri, 09 Oct 2015 18:06:08 +0000 In-Reply-To: <1444410785-1271-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org, Ian Campbell List-Id: xen-devel@lists.xenproject.org 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 #include #include #include #include #include #include #include #include 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); } }