Skip to contentSkip to conversation

network scripts: don't block SIGCHLD before forking

PATCH Superseded Michael Roth 4 participants 7 messages Dec 8, 2011 – Dec 15, 2011 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 network scripts: don't block SIGCHLD before forking

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.

---
 net/tap.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
net/tap.c +0 -5
index 1f26dc9..2cf79e1 100644
@@ -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;
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v2 1/1 network scripts: don't block SIGCHLD before forking

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.

---
 net/tap.c |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)
net/tap.c +0 -5
index 1f26dc9..2cf79e1 100644
@@ -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;
Signature · 1 line
1.7.4.1
#2 lore raw

Bah, missed a 'git add', will resend. Sorry for the noise.

#3 lore raw

PATCH v3 1/1 network scripts: don't block SIGCHLD before forking

In reply to Michael Roth

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.

---
 net/tap.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
net/tap.c +0 -6
index 1f26dc9..6c27a94 100644
@@ -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;
Signature · 1 line
1.7.4.1
Reviewed-by on v3 1/1
#4 lore raw
Quoted 47 lines · Michael Roth

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.

---
 net/tap.c |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
net/tap.c +0 -5
index 1f26dc9..6c27a94 100644
@@ -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) {

net/tap.c static int launch_script(const char *setup_script, const char *ifname, int fd) · line 378

Quoted 7 lines
net/tap.c +0 -1
@@ -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.

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
Reviewed-by on v3 1/1
#5 lore raw
In reply to Michael Roth
Quoted 47 lines · Michael Roth

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.

---
  net/tap.c |    6 ------
  1 files changed, 0 insertions(+), 6 deletions(-)
net/tap.c +0 -5
index 1f26dc9..6c27a94 100644
@@ -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) {

net/tap.c static int launch_script(const char *setup_script, const char *ifname, int fd) · line 378

Quoted 7 lines
net/tap.c +0 -1
@@ -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;

Paolo

#6 lore raw
In reply to Michael Roth
Quoted 16 lines · Michael Roth

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:

Quoted 6 lines

4d54ec7898bd951007cb6122d5315584bd41d0c4

As a result, we can now avoid blocking SIGCHLD in launch_script(), so drop that behavior.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 32 lines
---
  net/tap.c |    6 ------
  1 files changed, 0 insertions(+), 6 deletions(-)
net/tap.c +0 -6
index 1f26dc9..6c27a94 100644
@@ -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;