summaryrefslogtreecommitdiff
path: root/src/libstddjb/child_spawn0.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-03-09 17:18:15 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-03-09 17:18:15 +0000
commit34673241173ebcb143df9652e67ac077ba7176c0 (patch)
tree46fadd1d151cc3fb3693c4b0793271b8171046fa /src/libstddjb/child_spawn0.c
parent4dc49226555d272d4e5deea86fddaa13595f18f0 (diff)
downloadskalibs-34673241173ebcb143df9652e67ac077ba7176c0.tar.xz
- reset all signals to default in child_spawn*
- cosmetic fix in INSTALL - version: rc for 2.3.1.2
Diffstat (limited to 'src/libstddjb/child_spawn0.c')
-rw-r--r--src/libstddjb/child_spawn0.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c
index b96b2ef..7129515 100644
--- a/src/libstddjb/child_spawn0.c
+++ b/src/libstddjb/child_spawn0.c
@@ -6,6 +6,7 @@
#ifdef SKALIBS_HASPOSIXSPAWN
+#include <signal.h>
#include <spawn.h>
#include <stdlib.h>
#include <skalibs/config.h>
@@ -13,13 +14,33 @@
pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const *envp)
{
- pid_t pid ;
+ posix_spawnattr_t attr ;
int e ;
+ pid_t pid ;
int haspath = !!env_get("PATH") ;
- if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) return 0 ;
- e = posix_spawnp(&pid, prog, 0, 0, (char *const *)argv, (char *const *)envp) ;
+ e = posix_spawnattr_init(&attr) ;
+ if (e) goto err ;
+ {
+ sigset_t set ;
+ sigemptyset(&set) ;
+ e = posix_spawnattr_setsigmask(&attr, &set) ;
+ if (e) goto errattr ;
+ sigfillset(&set) ;
+ e = posix_spawnattr_setsigdefault(&attr, &set) ;
+ if (e) goto errattr ;
+ }
+ if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0)) { e = errno ; goto errattr ; }
+ e = posix_spawnp(&pid, prog, 0, &attr, (char *const *)argv, (char *const *)envp) ;
if (!haspath) unsetenv("PATH") ;
- return e ? (errno = e, 0) : pid ;
+ posix_spawnattr_destroy(&attr) ;
+ if (e) goto err ;
+ return pid ;
+
+ errattr:
+ posix_spawnattr_destroy(&attr) ;
+ err:
+ errno = e ;
+ return 0 ;
}
#else