diff options
author | Mike Frysinger | 2009-12-07 15:18:17 +0100 |
---|---|---|
committer | Karel Zak | 2009-12-07 15:23:40 +0100 |
commit | 60cd48bd1425610fbdcdb20249210c7f986cb31d (patch) | |
tree | 756194fdf2fac5abf447dd5458fdb2de627cb567 /sys-utils/flock.c | |
parent | docs: update TODO file (diff) | |
download | kernel-qcow2-util-linux-60cd48bd1425610fbdcdb20249210c7f986cb31d.tar.gz kernel-qcow2-util-linux-60cd48bd1425610fbdcdb20249210c7f986cb31d.tar.xz kernel-qcow2-util-linux-60cd48bd1425610fbdcdb20249210c7f986cb31d.zip |
flock: fix hang when parent ignores SIGCHLD
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.
[kzak@redhat.com: - add a check for waitpid() return value]
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/flock.c')
-rw-r--r-- | sys-utils/flock.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/sys-utils/flock.c b/sys-utils/flock.c index a53f6d317..75c007c73 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 ) { @@ -304,9 +306,15 @@ int main(int argc, char *argv[]) } else { do { w = waitpid(f, &status, 0); + if (w == -1 && errno != EINTR) + break; } while ( w != f ); - if ( WIFEXITED(status) ) + if (w == -1) { + err = errno; + status = EXIT_FAILURE; + fprintf(stderr, "%s: waitpid failed: %s\n", program, strerror(err)); + } else if ( WIFEXITED(status) ) status = WEXITSTATUS(status); else if ( WIFSIGNALED(status) ) status = WTERMSIG(status) + 128; |