[PATCH] flock: fix hang when parent ignores SIGCHLD

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

 



If flock is executed from a process which has set SIGCHLD to SIG_IGN, then
flock will eat cpu and hang indefinitely if given a command to execute.
So before we fork(), make sure to set SIGCHLD handling back to the default
so that the later waitpid() doesn't freak out on us.

Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>
---
issue can be seen with simple test:

$ cat test.c
#include <signal.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
	signal(SIGCHLD, SIG_IGN);
	return execv(argv[1], argv+1);
}

$ gcc test.c -o foo
$ ./foo ./flock . -c "ls -d /"
/
<hangs here>

$ strace -p <flock pid>
wait4(7053, 0x7fff5d03fed8, 0, NULL)    = -1 ECHILD (No child processes)
wait4(7053, 0x7fff5d03fed8, 0, NULL)    = -1 ECHILD (No child processes)
wait4(7053, 0x7fff5d03fed8, 0, NULL)    = -1 ECHILD (No child processes)
wait4(7053, 0x7fff5d03fed8, 0, NULL)    = -1 ECHILD (No child processes)
....

 sys-utils/flock.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index a53f6d3..6a9acb8 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -287,6 +287,8 @@ int main(int argc, char *argv[])
   if ( cmd_argv ) {
     pid_t w, f;
 
+    /* Clear any inherited settings */
+    signal(SIGCHLD, SIG_DFL);
     f = fork();
 
     if ( f < 0 ) {
-- 
1.6.5.4

--
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