commit e396f10de8804d1603a907069557b80e042f56ca
parent fee495136e7ee09755ee384ad0f818571859ffe1
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Mon, 11 Sep 2023 17:26:18 +0000
Fix cspawn when lack of flags or actions
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/libstddjb/cspawn.c b/src/libstddjb/cspawn.c
@@ -145,17 +145,22 @@ static inline pid_t cspawn_pspawn (char const *prog, char const *const *argv, ch
if (flags)
{
+ short pfff = 0 ;
e = posix_spawnattr_init(&attr) ;
if (e) goto err ;
- if (flags & 3)
+ if (flags & (CSPAWN_FLAGS_SIGBLOCKNONE | CSPAWN_FLAGS_SELFPIPE_FINISH))
{
sigset_t set ;
sigemptyset(&set) ;
e = posix_spawnattr_setsigmask(&attr, &set) ;
if (e) goto errattr ;
- e = posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGMASK) ;
- if (e) goto errattr ;
+ pfff |= POSIX_SPAWN_SETSIGMASK ;
}
+#ifdef SKALIBS_HASPOSIXSPAWNSETSID
+ if (flags & CSPAWN_FLAGS_SETSID) pfff |= POSIX_SPAWN_SETSID ;
+#endif
+ e = posix_spawnattr_setflags(&attr, pfff) ;
+ if (e) goto errattr ;
}
if (n)
@@ -195,7 +200,7 @@ static inline pid_t cspawn_pspawn (char const *prog, char const *const *argv, ch
}
if (nopath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) == -1)) { e = errno ; goto erractions ; }
- e = posix_spawnp(&pid, prog, &actions, &attr, (char *const *)argv, (char *const *)envp) ;
+ e = posix_spawnp(&pid, prog, n ? &actions : 0, flags ? &attr : 0, (char *const *)argv, (char *const *)envp) ;
if (nopath) unsetenv("PATH") ;
if (e) goto errattr ;