Re: [PATCH] script: preserve child exit status

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

 



Hi,

On Tue, Mar 10, 2009 at 4:49 AM, Karel Zak <kzak@xxxxxxxxxx> wrote:
>>
>>@@ -202,13 +207,23 @@
>>       sa.sa_handler = finish;
>>       sigaction(SIGCHLD, &sa, NULL);
>>
>>+      if(eflg)
>>+              sighold(SIGCHLD);
>>       child = fork();
>>+      if(eflg)
>>+              sigrelse(SIGCHLD);
>>+
>
>  Why we need this SIGCHLD "decoration" around fork(2)? Note that

They were put there because when I was testing my changes I ran script
-e -c 'bash -c exit 1', for a simple test.  Occasionally I would get
an exit code of 0 and this was because the SIGCHLD was getting to the
parent process before the pid was assigned to the child variable.
Since the child was unassigned the if statement in the SIGCHLD handler
would be false and the exit status would be lost.  This happened
pretty frequently on the subchild fork and occasionally on the first
child fork.

>  sig{hold,relse} are obsolete.

Hmm, ok I was unaware since it isn't marked deprecated in signal.h or
in sigset(3), but feel free to change them if you like.

>> void
>>@@ -436,6 +453,13 @@
>>               if (!qflg)
>>                       printf(_("Script done, file is %s\n"), fname);
>>       }
>>+
>>+      if(eflg)
>>+              if (WIFSIGNALED(childstatus))
>>+                      exit(WTERMSIG(childstatus) + 0x80);
>>+              else
>>+                      exit(WEXITSTATUS(childstatus));
>>+
>
>  I guess it should be "if (eflg) { .... }".

Yes it probably should be.

-nate
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux