summaryrefslogtreecommitdiff
path: root/src/sysdeps
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-11 18:24:05 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-11 18:24:05 +0000
commit1b0fce052f0adf2e4f3da7762cd9f4885a5d9da8 (patch)
treeed62766bb1e9c9ec7a326e2a33424840c4dfdb23 /src/sysdeps
parente396f10de8804d1603a907069557b80e042f56ca (diff)
downloadskalibs-1b0fce052f0adf2e4f3da7762cd9f4885a5d9da8.tar.xz
Add posix_spawn_file_actions_addchdir() support
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/sysdeps')
-rw-r--r--src/sysdeps/tryposixspawnchdir.c31
-rw-r--r--src/sysdeps/tryposixspawnchdirnp.c31
2 files changed, 62 insertions, 0 deletions
diff --git a/src/sysdeps/tryposixspawnchdir.c b/src/sysdeps/tryposixspawnchdir.c
new file mode 100644
index 0000000..7c08346
--- /dev/null
+++ b/src/sysdeps/tryposixspawnchdir.c
@@ -0,0 +1,31 @@
+/* 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_spawn_file_actions_init(&actions) ;
+ posix_spawn_file_actions_addchdir(&actions, "/") ;
+ posix_spawn_file_actions_addfchdir(&actions, -1) ;
+ return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ;
+}
diff --git a/src/sysdeps/tryposixspawnchdirnp.c b/src/sysdeps/tryposixspawnchdirnp.c
new file mode 100644
index 0000000..19481f3
--- /dev/null
+++ b/src/sysdeps/tryposixspawnchdirnp.c
@@ -0,0 +1,31 @@
+/* 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_spawn_file_actions_init(&actions) ;
+ posix_spawn_file_actions_addchdir_np(&actions, "/") ;
+ posix_spawn_file_actions_addfchdir_np(&actions, -1) ;
+ return posix_spawn(&pid, argv[0], 0, 0, argv, envp) ;
+}