|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
commit 14d0e87d9b8caaa2eca7ca81f1189596671fe4fb
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Date: Wed Sep 12 10:32:05 2018 -0300
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
posix: Use posix_spawn on popen
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
This patch uses posix_spawn on popen instead of fork and execl. On Linux
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
this has the advantage of much lower memory consumption (usually 32 Kb
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
minimum for the mmap stack area).
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Two issues are also fixed with this change:
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
* BZ#17490: although POSIX pthread_atfork description only list 'fork'
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
as the function that should execute the atfork handlers, popen
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
description states that:
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
'[...] shall be *as if* a child process were created within the popen()
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
call using the fork() function [...]'
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Other libc/system seems to follow the idea atfork handlers should not be
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
executed for popen:
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
libc/system | run atfork handles | notes
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
------------|----------------------|---------------------------------------
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Freebsd | no | uses vfork
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Solaris 11 | no |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
MacOSX 11 | no | implemented through posix_spawn syscall
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
------------|----------------------|----------------------------------------
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Similar to posix_spawn and system, popen idea is to spawn a different
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
binary so all the POSIX rationale to run the atfork handlers to avoid
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
internal process inconsistency is not really required and in some cases
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
might be unsafe.
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
* BZ#22834: the described scenario, where the forked process might access
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
invalid memory due an inconsistent state in multithreaded environment,
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
should not happen because posix_spawn does not access the affected
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
data structure (proc_file_chain).
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
Checked on x86_64-linux-gnu and i686-linux-gnu.
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
[BZ #22834]
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
[BZ #17490]
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
* NEWS: Add new semantic for atfork with popen and system.
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
* libio/iopopen.c (_IO_new_proc_open): use posix_spawn instead of
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
fork and execl.
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
diff --git a/libio/iopopen.c b/libio/iopopen.c
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
index 2eff45b4c80b5cd6..c768295180fdf809 100644
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
--- a/libio/iopopen.c
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+++ b/libio/iopopen.c
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
@@ -34,7 +34,8 @@
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#include <not-cancel.h>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#include <sys/types.h>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#include <sys/wait.h>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
-#include <kernel-features.h>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+#include <spawn.h>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+#include <paths.h>
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
struct _IO_proc_file
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
{
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
@@ -59,13 +60,60 @@ unlock (void *not_used)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
}
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#endif
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+/* POSIX states popen shall ensure that any streams from previous popen()
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ calls that remain open in the parent process should be closed in the new
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child process.
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ To avoid a race-condition between checking which file descriptors need to
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ be close (by transversing the proc_file_chain list) and the insertion of a
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ new one after a successful posix_spawn this function should be called
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ with proc_file_chain_lock acquired. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+static bool
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+spawn_process (posix_spawn_file_actions_t *fa, FILE *fp, const char *command,
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ int do_cloexec, int pipe_fds[2], int parent_end, int child_end,
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ int child_pipe_fd)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+{
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ for (struct _IO_proc_file *p = proc_file_chain; p; p = p->next)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ {
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ int fd = _IO_fileno ((FILE *) p);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ /* If any stream from previous popen() calls has fileno
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child_pipe_fd, it has been already closed by the adddup2 action
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ above. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (fd != child_pipe_fd
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ && __posix_spawn_file_actions_addclose (fa, fd) != 0)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ return false;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (__posix_spawn (&((_IO_proc_file *) fp)->pid, _PATH_BSHELL, fa, 0,
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ (char *const[]){ (char*) "sh", (char*) "-c",
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ (char *) command, NULL }, __environ) != 0)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ return false;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __close_nocancel (pipe_fds[child_end]);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (!do_cloexec)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ /* Undo the effects of the pipe2 call which set the
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ close-on-exec flag. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __fcntl (pipe_fds[parent_end], F_SETFD, 0);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ _IO_fileno (fp) = pipe_fds[parent_end];
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ ((_IO_proc_file *) fp)->next = proc_file_chain;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ proc_file_chain = (_IO_proc_file *) fp;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ return true;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+}
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
FILE *
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
_IO_new_proc_open (FILE *fp, const char *command, const char *mode)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
{
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
int read_or_write;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ /* These are indexes for pipe_fds. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
int parent_end, child_end;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
int pipe_fds[2];
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- pid_t child_pid;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ int child_pipe_fd;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ bool spawn_ok;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
int do_read = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
int do_write = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
@@ -108,72 +156,62 @@ _IO_new_proc_open (FILE *fp, const char *command, const char *mode)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
if (do_read)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
{
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- parent_end = pipe_fds[0];
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- child_end = pipe_fds[1];
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ parent_end = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child_end = 1;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
read_or_write = _IO_NO_WRITES;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child_pipe_fd = 1;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
}
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
else
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
{
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- parent_end = pipe_fds[1];
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- child_end = pipe_fds[0];
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ parent_end = 1;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child_end = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
read_or_write = _IO_NO_READS;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child_pipe_fd = 0;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
}
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- ((_IO_proc_file *) fp)->pid = child_pid = __fork ();
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- if (child_pid == 0)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- {
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- int child_std_end = do_read ? 1 : 0;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- struct _IO_proc_file *p;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
-
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- if (child_end != child_std_end)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- __dup2 (child_end, child_std_end);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- else
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- /* The descriptor is already the one we will use. But it must
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- not be marked close-on-exec. Undo the effects. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- __fcntl (child_end, F_SETFD, 0);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- /* POSIX.2: "popen() shall ensure that any streams from previous
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- popen() calls that remain open in the parent process are closed
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- in the new child process." */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- for (p = proc_file_chain; p; p = p->next)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- {
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- int fd = _IO_fileno ((FILE *) p);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ posix_spawn_file_actions_t fa;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ /* posix_spawn_file_actions_init does not fail. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __posix_spawn_file_actions_init (&fa);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- /* If any stream from previous popen() calls has fileno
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- child_std_end, it has been already closed by the dup2 syscall
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- above. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- if (fd != child_std_end)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- __close_nocancel (fd);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- }
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
-
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- execl ("/bin/sh", "sh", "-c", command, (char *) 0);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- _exit (127);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- }
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- __close_nocancel (child_end);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- if (child_pid < 0)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ /* The descriptor is already the one the child will use. In this case
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ it must be moved to another one otherwise, there is no safe way to
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ remove the close-on-exec flag in the child without creating a FD leak
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ race in the parent. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (pipe_fds[child_end] == child_pipe_fd)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
{
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- __close_nocancel (parent_end);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- return NULL;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ int tmp = __fcntl (child_pipe_fd, F_DUPFD_CLOEXEC, 0);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (tmp < 0)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ goto spawn_failure;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __close_nocancel (pipe_fds[child_end]);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ pipe_fds[child_end] = tmp;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
}
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- if (!do_cloexec)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- /* Undo the effects of the pipe2 call which set the
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- close-on-exec flag. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- __fcntl (parent_end, F_SETFD, 0);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (__posix_spawn_file_actions_adddup2 (&fa, pipe_fds[child_end],
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ child_pipe_fd) != 0)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ goto spawn_failure;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- _IO_fileno (fp) = parent_end;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
-
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- /* Link into proc_file_chain. */
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#ifdef _IO_MTSAFE_IO
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
_IO_cleanup_region_start_noarg (unlock);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
_IO_lock_lock (proc_file_chain_lock);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#endif
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- ((_IO_proc_file *) fp)->next = proc_file_chain;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
- proc_file_chain = (_IO_proc_file *) fp;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ spawn_ok = spawn_process (&fa, fp, command, do_cloexec, pipe_fds,
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ parent_end, child_end, child_pipe_fd);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#ifdef _IO_MTSAFE_IO
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
_IO_lock_unlock (proc_file_chain_lock);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
_IO_cleanup_region_end (0);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
#endif
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __posix_spawn_file_actions_destroy (&fa);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ if (!spawn_ok)
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ {
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ spawn_failure:
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __close_nocancel (pipe_fds[child_end]);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __close_nocancel (pipe_fds[parent_end]);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ __set_errno (ENOMEM);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ return NULL;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
+
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
_IO_mask_flags (fp, read_or_write, _IO_NO_READS|_IO_NO_WRITES);
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
return fp;
|
|
![](https://seccdn.libravatar.org/avatar/fcc0873d860f7e6944b3abea5b6b447609288dcd55d37b92d3e9e9b1a1e81f06?s=16&d=retro) |
28653a |
}
|