pid_t child = -1;
int stdin_pipe[2], stdout_pipe[2], tmp;
-#if (HAVE_FORK || HAVE_VFORK) && (HAVE_CLOSEFROM || HAVE_CLOSE_RANGE)
+#if !defined(POSIX_SPAWN_CLOEXEC_DEFAULT) && \
+ (HAVE_FORK || HAVE_VFORK) && (HAVE_CLOSEFROM || HAVE_CLOSE_RANGE)
#undef HAVE_POSIX_SPAWNP
#endif
#if HAVE_POSIX_SPAWNP
+ posix_spawnattr_t attr;
posix_spawn_file_actions_t actions;
int r;
#endif
#if HAVE_POSIX_SPAWNP
- r = posix_spawn_file_actions_init(&actions);
+ r = posix_spawnattr_init(&attr);
if (r != 0) {
errno = r;
goto stdout_opened;
}
+ r = posix_spawn_file_actions_init(&actions);
+ if (r != 0) {
+ errno = r;
+ goto attr_inited;
+ }
+#ifdef POSIX_SPAWN_CLOEXEC_DEFAULT
+ r = posix_spawnattr_setflags(&attr, POSIX_SPAWN_CLOEXEC_DEFAULT);
+ if (r != 0)
+ goto actions_inited;
+#endif
r = posix_spawn_file_actions_addclose(&actions, stdin_pipe[1]);
if (r != 0)
goto actions_inited;
if (r != 0)
goto actions_inited;
}
- r = posix_spawnp(&child, cmdline->path, &actions, NULL,
+ r = posix_spawnp(&child, cmdline->path, &actions, &attr,
cmdline->argv, NULL);
if (r != 0)
goto actions_inited;
posix_spawn_file_actions_destroy(&actions);
+ posix_spawnattr_destroy(&attr);
#else /* HAVE_POSIX_SPAWNP */
actions_inited:
errno = r;
posix_spawn_file_actions_destroy(&actions);
+attr_inited:
+ posix_spawnattr_destroy(&attr);
#endif
stdout_opened:
close(stdout_pipe[0]);