libport: Reset SIGCHLD and SIGPIPE unconditionally

Ilya Basin basinilya at gmail.com
Wed May 4 07:38:00 CDT 2011


fix for http://bugs.winehq.org/show_bug.cgi?id=27014
Makes sure that signals reset before execvp(). Logic kept.
---
 libs/port/spawn.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/libs/port/spawn.c b/libs/port/spawn.c
index 38c2944..1d27ac0 100644
--- a/libs/port/spawn.c
+++ b/libs/port/spawn.c
@@ -36,29 +36,37 @@
 int spawnvp(int mode, const char *cmdname, const char *const argv[])
 {
 #ifndef HAVE__SPAWNVP
-    int pid = 0, status, wret;
-    struct sigaction dfl_act, old_act;
+    int pid, status, wret;
+    struct sigaction dfl_act, old_act_chld, old_act_pipe;
+
+    dfl_act.sa_handler = SIG_DFL;
+    dfl_act.sa_flags = 0;
+    sigemptyset( &dfl_act.sa_mask );
 
     if (mode == _P_OVERLAY)
     {
+        sigaction( SIGCHLD, &dfl_act, &old_act_chld );
+        sigaction( SIGPIPE, &dfl_act, &old_act_pipe );
+
         execvp(cmdname, (char **)argv);
         /* if we get here it failed */
+        status = errno;
+        sigaction( SIGCHLD, &old_act_chld, NULL );
+        sigaction( SIGPIPE, &old_act_pipe, NULL );
+        errno = status;
 #ifdef ENOTSUP
         if (errno != ENOTSUP)  /* exec fails on MacOS if the process has multiple threads */
 #endif
             return -1;
     }
 
-    dfl_act.sa_handler = SIG_DFL;
-    dfl_act.sa_flags = 0;
-    sigemptyset( &dfl_act.sa_mask );
-
-    if (mode == _P_WAIT) sigaction( SIGCHLD, &dfl_act, &old_act );
+    if (mode == _P_WAIT) sigaction( SIGCHLD, &dfl_act, &old_act_chld );
 
     pid = fork();
     if (pid == 0)
     {
-        sigaction( SIGPIPE, &dfl_act, NULL );
+        if (mode != _P_WAIT) signal( SIGCHLD, SIG_DFL );
+        signal( SIGPIPE, SIG_DFL );
         execvp(cmdname, (char **)argv);
         _exit(1);
     }
@@ -74,7 +82,7 @@ int spawnvp(int mode, const char *cmdname, const char *const argv[])
         else pid = 255; /* abnormal exit with an abort or an interrupt */
     }
 
-    if (mode == _P_WAIT) sigaction( SIGCHLD, &old_act, NULL );
+    if (mode == _P_WAIT) sigaction( SIGCHLD, &old_act_chld, NULL );
     return pid;
 #else   /* HAVE__SPAWNVP */
     return _spawnvp(mode, cmdname, argv);
-- 
1.7.5




More information about the wine-patches mailing list