skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 32544468e5db6a2635b6c0f9e261a288fe7179e9
parent beb9f82f12972b4f4b8830701c4d7ba02ddfbceb
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Mon, 11 Sep 2023 22:57:08 +0000

 Add POSIX_SPAWN_SETSID_NP support

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Mconfigure | 1+
Msrc/libstddjb/cspawn.c | 8++++++--
Asrc/sysdeps/tryposixspawnsetsidnp.c | 30++++++++++++++++++++++++++++++
Mtools/convert-leapsecs.c | 1-
4 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/configure b/configure @@ -642,6 +642,7 @@ choose cl getrandom 'getrandom()' choose cl grndinsecure 'GRND_INSECURE' choose cl chroot 'chroot()' choose cl posixspawnsetsid 'POSIX_SPAWN_SETSID' $spawn_lib +choose cl posixspawnsetsidnp 'POSIX_SPAWN_SETSID_NP' $spawn_lib choose cl posixspawnchdir 'posix_spawn_file_actions_addchdir()' $spawn_lib choose cl posixspawnchdirnp 'posix_spawn_file_actions_addchdir_np()' $spawn_lib diff --git a/src/libstddjb/cspawn.c b/src/libstddjb/cspawn.c @@ -165,6 +165,10 @@ static inline pid_t cspawn_pspawn (char const *prog, char const *const *argv, ch } #ifdef SKALIBS_HASPOSIXSPAWNSETSID if (flags & CSPAWN_FLAGS_SETSID) pfff |= POSIX_SPAWN_SETSID ; +#else +#ifdef SKALIBS_HASPOSIXSPAWNSETSIDNP + if (flags & CSPAWN_FLAGS_SETSID) pfff |= POSIX_SPAWN_SETSID_NP ; +#endif #endif e = posix_spawnattr_setflags(&attr, pfff) ; if (e) goto errattr ; @@ -253,7 +257,7 @@ static inline pid_t cspawn_pspawn (char const *prog, char const *const *argv, ch return 0 ; } -#if defined(SKALIBS_HASPOSIXSPAWNSETSID) && (defined(SKALIBS_HASPOSIXSPAWNCHDIR) || defined(SKALIBS_HASPOSIXSPAWNCHDIRNP)) +#if (defined(SKALIBS_HASPOSIXSPAWNSETSID) || defined(SKALIBS_HASPOSIXSPAWNSETSIDNP)) && (defined(SKALIBS_HASPOSIXSPAWNCHDIR) || defined(SKALIBS_HASPOSIXSPAWNCHDIRNP)) pid_t cspawn (char const *prog, char const *const *argv, char const *const *envp, uint16_t flags, cspawn_fileaction const *fa, size_t n) { @@ -264,7 +268,7 @@ pid_t cspawn (char const *prog, char const *const *argv, char const *const *envp pid_t cspawn (char const *prog, char const *const *argv, char const *const *envp, uint16_t flags, cspawn_fileaction const *fa, size_t n) { -#if !defined(SKALIBS_HASPOSIXSPAWNSETSID) +#if !defined(SKALIBS_HASPOSIXSPAWNSETSID) && !defined(SKALIBS_HASPOSIXSPAWNSETSIDNP) if (flags & CSPAWN_FLAGS_SETSID) goto dofork ; #endif #if !defined(SKALIBS_HASPOSIXSPAWNCHDIR) && !defined(SKALIBS_HASPOSIXSPAWNCHDIRNP) diff --git a/src/sysdeps/tryposixspawnsetsidnp.c b/src/sysdeps/tryposixspawnsetsidnp.c @@ -0,0 +1,30 @@ +/* ISC license. */ + +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef _XPG4_2 +#define _XPG4_2 +#endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + +#include <spawn.h> + +int main (void) +{ + pid_t pid ; + posix_spawn_file_actions_t actions ; + posix_spawnattr_t attr ; + char *const argv[2] = { "/bin/true", 0 } ; + char *const envp[1] = { 0 } ; + posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSID_NP) ; + posix_spawn_file_actions_init(&actions) ; + return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ; +} diff --git a/tools/convert-leapsecs.c b/tools/convert-leapsecs.c @@ -28,7 +28,6 @@ int main (int argc, char const *const *argv) struct tm tm ; uint64_t tt ; time_t t ; - char *p ; int r ; char fmt[UINT64_FMT] ; sa.len = 0 ;