* [Qemu-devel] [PATCH] network scripts: don't block SIGCHLD before forking @ 2011-12-08 3:36 Michael Roth 2011-12-08 3:43 ` [Qemu-devel] [PATCH v2] " Michael Roth 2011-12-08 3:48 ` [Qemu-devel] [PATCH v3] " Michael Roth 0 siblings, 2 replies; 7+ messages in thread From: Michael Roth @ 2011-12-08 3:36 UTC (permalink / raw) To: qemu-devel; +Cc: jan.kiszka, mdroth, pbonzini This patch fixes a bug where child processes of launch_script() can misbehave due to SIGCHLD being blocked. In the case of `sudo`, this causes a permanent hang. Previously a SIGCHLD handler was added to reap fork_exec()'d zombie processes by calling waitpid(-1, ...). This required other fork()/waitpid() callers to temporarilly block SIGCHILD to avoid having the final wait status being intercepted by the SIGCHLD handler: 7c3370d4fe3fa6cda8655f109e4659afc8ca4269 Since then, the qemu_add_child_watch() interface was added to allow registration of such processes and reap only from that specific set of PIDs: 4d54ec7898bd951007cb6122d5315584bd41d0c4 As a result, we can now avoid blocking SIGCHLD in launch_script(), so drop that behavior. Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> --- net/tap.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 1f26dc9..2cf79e1 100644 --- a/net/tap.c +++ b/net/tap.c @@ -351,10 +351,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) char *args[3]; char **parg; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - /* try to launch network script */ pid = fork(); if (pid == 0) { @@ -378,7 +374,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) while (waitpid(pid, &status, 0) != pid) { /* loop */ } - sigprocmask(SIG_SETMASK, &oldmask, NULL); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { return 0; -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v2] network scripts: don't block SIGCHLD before forking 2011-12-08 3:36 [Qemu-devel] [PATCH] network scripts: don't block SIGCHLD before forking Michael Roth @ 2011-12-08 3:43 ` Michael Roth 2011-12-08 3:50 ` Michael Roth 2011-12-08 3:48 ` [Qemu-devel] [PATCH v3] " Michael Roth 1 sibling, 1 reply; 7+ messages in thread From: Michael Roth @ 2011-12-08 3:43 UTC (permalink / raw) To: qemu-devel; +Cc: jan.kiszka, mdroth, pbonzini This patch fixes a bug where child processes of launch_script() can misbehave due to SIGCHLD being blocked. In the case of `sudo`, this causes a permanent hang. Previously a SIGCHLD handler was added to reap fork_exec()'d zombie processes by calling waitpid(-1, ...). This required other fork()/waitpid() callers to temporarilly block SIGCHILD to avoid having the final wait status being intercepted by the SIGCHLD handler: 7c3370d4fe3fa6cda8655f109e4659afc8ca4269 Since then, the qemu_add_child_watch() interface was added to allow registration of such processes and reap only from that specific set of PIDs: 4d54ec7898bd951007cb6122d5315584bd41d0c4 As a result, we can now avoid blocking SIGCHLD in launch_script(), so drop that behavior. Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> --- net/tap.c | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index 1f26dc9..2cf79e1 100644 --- a/net/tap.c +++ b/net/tap.c @@ -351,10 +351,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) char *args[3]; char **parg; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - /* try to launch network script */ pid = fork(); if (pid == 0) { @@ -378,7 +374,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) while (waitpid(pid, &status, 0) != pid) { /* loop */ } - sigprocmask(SIG_SETMASK, &oldmask, NULL); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { return 0; -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] network scripts: don't block SIGCHLD before forking 2011-12-08 3:43 ` [Qemu-devel] [PATCH v2] " Michael Roth @ 2011-12-08 3:50 ` Michael Roth 0 siblings, 0 replies; 7+ messages in thread From: Michael Roth @ 2011-12-08 3:50 UTC (permalink / raw) To: Michael Roth; +Cc: jan.kiszka, qemu-devel, pbonzini Bah, missed a 'git add', will resend. Sorry for the noise. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [Qemu-devel] [PATCH v3] network scripts: don't block SIGCHLD before forking 2011-12-08 3:36 [Qemu-devel] [PATCH] network scripts: don't block SIGCHLD before forking Michael Roth 2011-12-08 3:43 ` [Qemu-devel] [PATCH v2] " Michael Roth @ 2011-12-08 3:48 ` Michael Roth 2011-12-08 13:36 ` Jan Kiszka ` (2 more replies) 1 sibling, 3 replies; 7+ messages in thread From: Michael Roth @ 2011-12-08 3:48 UTC (permalink / raw) To: qemu-devel; +Cc: jan.kiszka, mdroth, pbonzini This patch fixes a bug where child processes of launch_script() can misbehave due to SIGCHLD being blocked. In the case of `sudo`, this causes a permanent hang. Previously a SIGCHLD handler was added to reap fork_exec()'d zombie processes by calling waitpid(-1, ...). This required other fork()/waitpid() callers to temporarilly block SIGCHILD to avoid having the final wait status being intercepted by the SIGCHLD handler: 7c3370d4fe3fa6cda8655f109e4659afc8ca4269 Since then, the qemu_add_child_watch() interface was added to allow registration of such processes and reap only from that specific set of PIDs: 4d54ec7898bd951007cb6122d5315584bd41d0c4 As a result, we can now avoid blocking SIGCHLD in launch_script(), so drop that behavior. Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> --- net/tap.c | 6 ------ 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index 1f26dc9..6c27a94 100644 --- a/net/tap.c +++ b/net/tap.c @@ -346,15 +346,10 @@ static TAPState *net_tap_fd_init(VLANState *vlan, static int launch_script(const char *setup_script, const char *ifname, int fd) { - sigset_t oldmask, mask; int pid, status; char *args[3]; char **parg; - sigemptyset(&mask); - sigaddset(&mask, SIGCHLD); - sigprocmask(SIG_BLOCK, &mask, &oldmask); - /* try to launch network script */ pid = fork(); if (pid == 0) { @@ -378,7 +373,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) while (waitpid(pid, &status, 0) != pid) { /* loop */ } - sigprocmask(SIG_SETMASK, &oldmask, NULL); if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { return 0; -- 1.7.4.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] network scripts: don't block SIGCHLD before forking 2011-12-08 3:48 ` [Qemu-devel] [PATCH v3] " Michael Roth @ 2011-12-08 13:36 ` Jan Kiszka 2011-12-12 8:01 ` Paolo Bonzini 2011-12-15 18:09 ` Anthony Liguori 2 siblings, 0 replies; 7+ messages in thread From: Jan Kiszka @ 2011-12-08 13:36 UTC (permalink / raw) To: Michael Roth; +Cc: pbonzini@redhat.com, qemu-devel@nongnu.org On 2011-12-08 04:48, Michael Roth wrote: > This patch fixes a bug where child processes of launch_script() can > misbehave due to SIGCHLD being blocked. In the case of `sudo`, this > causes a permanent hang. > > Previously a SIGCHLD handler was added to reap fork_exec()'d zombie > processes by calling waitpid(-1, ...). This required other > fork()/waitpid() callers to temporarilly block SIGCHILD to avoid > having the final wait status being intercepted by the SIGCHLD > handler: > > 7c3370d4fe3fa6cda8655f109e4659afc8ca4269 > > Since then, the qemu_add_child_watch() interface was added to allow > registration of such processes and reap only from that specific set > of PIDs: > > 4d54ec7898bd951007cb6122d5315584bd41d0c4 > > As a result, we can now avoid blocking SIGCHLD in launch_script(), so > drop that behavior. > > Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> > --- > net/tap.c | 6 ------ > 1 files changed, 0 insertions(+), 6 deletions(-) > > diff --git a/net/tap.c b/net/tap.c > index 1f26dc9..6c27a94 100644 > --- a/net/tap.c > +++ b/net/tap.c > @@ -346,15 +346,10 @@ static TAPState *net_tap_fd_init(VLANState *vlan, > > static int launch_script(const char *setup_script, const char *ifname, int fd) > { > - sigset_t oldmask, mask; > int pid, status; > char *args[3]; > char **parg; > > - sigemptyset(&mask); > - sigaddset(&mask, SIGCHLD); > - sigprocmask(SIG_BLOCK, &mask, &oldmask); > - > /* try to launch network script */ > pid = fork(); > if (pid == 0) { > @@ -378,7 +373,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) > while (waitpid(pid, &status, 0) != pid) { > /* loop */ > } > - sigprocmask(SIG_SETMASK, &oldmask, NULL); > > if (WIFEXITED(status) && WEXITSTATUS(status) == 0) { > return 0; Looks sane. Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com> -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] network scripts: don't block SIGCHLD before forking 2011-12-08 3:48 ` [Qemu-devel] [PATCH v3] " Michael Roth 2011-12-08 13:36 ` Jan Kiszka @ 2011-12-12 8:01 ` Paolo Bonzini 2011-12-15 18:09 ` Anthony Liguori 2 siblings, 0 replies; 7+ messages in thread From: Paolo Bonzini @ 2011-12-12 8:01 UTC (permalink / raw) To: Michael Roth; +Cc: jan.kiszka, qemu-devel On 12/08/2011 04:48 AM, Michael Roth wrote: > This patch fixes a bug where child processes of launch_script() can > misbehave due to SIGCHLD being blocked. In the case of `sudo`, this > causes a permanent hang. > > Previously a SIGCHLD handler was added to reap fork_exec()'d zombie > processes by calling waitpid(-1, ...). This required other > fork()/waitpid() callers to temporarilly block SIGCHILD to avoid > having the final wait status being intercepted by the SIGCHLD > handler: > > 7c3370d4fe3fa6cda8655f109e4659afc8ca4269 > > Since then, the qemu_add_child_watch() interface was added to allow > registration of such processes and reap only from that specific set > of PIDs: > > 4d54ec7898bd951007cb6122d5315584bd41d0c4 > > As a result, we can now avoid blocking SIGCHLD in launch_script(), so > drop that behavior. > > Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com> > --- > net/tap.c | 6 ------ > 1 files changed, 0 insertions(+), 6 deletions(-) > > diff --git a/net/tap.c b/net/tap.c > index 1f26dc9..6c27a94 100644 > --- a/net/tap.c > +++ b/net/tap.c > @@ -346,15 +346,10 @@ static TAPState *net_tap_fd_init(VLANState *vlan, > > static int launch_script(const char *setup_script, const char *ifname, int fd) > { > - sigset_t oldmask, mask; > int pid, status; > char *args[3]; > char **parg; > > - sigemptyset(&mask); > - sigaddset(&mask, SIGCHLD); > - sigprocmask(SIG_BLOCK,&mask,&oldmask); > - > /* try to launch network script */ > pid = fork(); > if (pid == 0) { > @@ -378,7 +373,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) > while (waitpid(pid,&status, 0) != pid) { > /* loop */ > } > - sigprocmask(SIG_SETMASK,&oldmask, NULL); > > if (WIFEXITED(status)&& WEXITSTATUS(status) == 0) { > return 0; Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Paolo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v3] network scripts: don't block SIGCHLD before forking 2011-12-08 3:48 ` [Qemu-devel] [PATCH v3] " Michael Roth 2011-12-08 13:36 ` Jan Kiszka 2011-12-12 8:01 ` Paolo Bonzini @ 2011-12-15 18:09 ` Anthony Liguori 2 siblings, 0 replies; 7+ messages in thread From: Anthony Liguori @ 2011-12-15 18:09 UTC (permalink / raw) To: Michael Roth; +Cc: jan.kiszka, qemu-devel, pbonzini On 12/07/2011 09:48 PM, Michael Roth wrote: > This patch fixes a bug where child processes of launch_script() can > misbehave due to SIGCHLD being blocked. In the case of `sudo`, this > causes a permanent hang. > > Previously a SIGCHLD handler was added to reap fork_exec()'d zombie > processes by calling waitpid(-1, ...). This required other > fork()/waitpid() callers to temporarilly block SIGCHILD to avoid > having the final wait status being intercepted by the SIGCHLD > handler: > > 7c3370d4fe3fa6cda8655f109e4659afc8ca4269 > > Since then, the qemu_add_child_watch() interface was added to allow > registration of such processes and reap only from that specific set > of PIDs: > > 4d54ec7898bd951007cb6122d5315584bd41d0c4 > > As a result, we can now avoid blocking SIGCHLD in launch_script(), so > drop that behavior. > > Signed-off-by: Michael Roth<mdroth@linux.vnet.ibm.com> Applied. Thanks. Regards, Anthony Liguori > --- > net/tap.c | 6 ------ > 1 files changed, 0 insertions(+), 6 deletions(-) > > diff --git a/net/tap.c b/net/tap.c > index 1f26dc9..6c27a94 100644 > --- a/net/tap.c > +++ b/net/tap.c > @@ -346,15 +346,10 @@ static TAPState *net_tap_fd_init(VLANState *vlan, > > static int launch_script(const char *setup_script, const char *ifname, int fd) > { > - sigset_t oldmask, mask; > int pid, status; > char *args[3]; > char **parg; > > - sigemptyset(&mask); > - sigaddset(&mask, SIGCHLD); > - sigprocmask(SIG_BLOCK,&mask,&oldmask); > - > /* try to launch network script */ > pid = fork(); > if (pid == 0) { > @@ -378,7 +373,6 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) > while (waitpid(pid,&status, 0) != pid) { > /* loop */ > } > - sigprocmask(SIG_SETMASK,&oldmask, NULL); > > if (WIFEXITED(status)&& WEXITSTATUS(status) == 0) { > return 0; ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-12-15 18:09 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2011-12-08 3:36 [Qemu-devel] [PATCH] network scripts: don't block SIGCHLD before forking Michael Roth 2011-12-08 3:43 ` [Qemu-devel] [PATCH v2] " Michael Roth 2011-12-08 3:50 ` Michael Roth 2011-12-08 3:48 ` [Qemu-devel] [PATCH v3] " Michael Roth 2011-12-08 13:36 ` Jan Kiszka 2011-12-12 8:01 ` Paolo Bonzini 2011-12-15 18:09 ` Anthony Liguori
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).