summaryrefslogtreecommitdiff
path: root/src/sysdeps/tryposixspawnsetsid.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-10 04:59:41 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-10 04:59:41 +0000
commit252e2ad869637ca3ef8690854a8fac784b869ec9 (patch)
tree4c5b015828fdfc70fcc920b858892688d5c6ce8b /src/sysdeps/tryposixspawnsetsid.c
parent8ba811fb48d666a23d60a5ce3a947dcac7baf6ea (diff)
downloadskalibs-252e2ad869637ca3ef8690854a8fac784b869ec9.tar.xz
Add POSIX_SPAWN_SETSID support to cspawn
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/sysdeps/tryposixspawnsetsid.c')
-rw-r--r--src/sysdeps/tryposixspawnsetsid.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/sysdeps/tryposixspawnsetsid.c b/src/sysdeps/tryposixspawnsetsid.c
new file mode 100644
index 0000000..10e4e2e
--- /dev/null
+++ b/src/sysdeps/tryposixspawnsetsid.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) ;
+ posix_spawn_file_actions_init(&actions) ;
+ return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ;
+}