diff options
author | NIIBE Yutaka <[email protected]> | 2022-10-19 05:10:03 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2022-10-19 05:10:03 +0000 |
commit | 494886acb0bf3d536f4e620340e42c8ec8947742 (patch) | |
tree | 7896f5e3692b0b685c1acc77847b6eeed9502766 /src/spawn-posix.c | |
parent | build: Remove potomo from repo. (diff) | |
download | libgpg-error-494886acb0bf3d536f4e620340e42c8ec8947742.tar.gz libgpg-error-494886acb0bf3d536f4e620340e42c8ec8947742.zip |
spawn: Update changes from gnupg.
* src/gpg-error.h.in (GPGRT_SPAWN_KEEP_STDIN): New.
(GPGRT_SPAWN_KEEP_STDOUT, GPGRT_SPAWN_KEEP_STDERR): New.
* src/gpgrt-int.h: Add comment.
* src/spawn-posix.c (do_exec): Add the argument FLAGS.
(_gpgrt_spawn_process): Add FLAGS.
(_gpgrt_spawn_process_fd): Follow the change.
(_gpgrt_spawn_process_detached): Likewise.
* src/spawn-w32.c (_gpgrt_spawn_process): Handle FLAGS.
--
This commit imports GnuPG master commit of:
6d6438a361d25f3b269f702e017f5e39fd1f5c38
GnuPG-bug-id: 6249
Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'src/spawn-posix.c')
-rw-r--r-- | src/spawn-posix.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/spawn-posix.c b/src/spawn-posix.c index 54a6a68..eb4f534 100644 --- a/src/spawn-posix.c +++ b/src/spawn-posix.c @@ -258,16 +258,21 @@ get_all_open_fds (void) static void do_exec (const char *pgmname, const char *argv[], int fd_in, int fd_out, int fd_err, - int *except, void (*preexec)(void) ) + int *except, void (*preexec)(void), unsigned int flags) { char **arg_list; int i, j; int fds[3]; + int nodevnull[3]; fds[0] = fd_in; fds[1] = fd_out; fds[2] = fd_err; + nodevnull[0] = !!(flags & GPGRT_SPAWN_KEEP_STDIN); + nodevnull[1] = !!(flags & GPGRT_SPAWN_KEEP_STDOUT); + nodevnull[2] = !!(flags & GPGRT_SPAWN_KEEP_STDERR); + /* Create the command line argument array. */ i = 0; if (argv) @@ -292,7 +297,9 @@ do_exec (const char *pgmname, const char *argv[], /* Assign /dev/null to unused FDs. */ for (i=0; i <= 2; i++) { - if (fds[i] == -1 ) + if (nodevnull[i]) + continue; + if (fds[i] == -1) { fds[i] = open ("/dev/null", i? O_WRONLY : O_RDONLY); if (fds[i] == -1) @@ -304,6 +311,8 @@ do_exec (const char *pgmname, const char *argv[], /* Connect the standard files. */ for (i=0; i <= 2; i++) { + if (nodevnull[i]) + continue; if (fds[i] != i && dup2 (fds[i], i) == -1) _gpgrt_log_fatal ("dup2 std%s failed: %s\n", i==0?"in":i==1?"out":"err", strerror (errno)); @@ -503,7 +512,7 @@ _gpgrt_spawn_process (const char *pgmname, const char *argv[], _gpgrt_fclose (outfp); _gpgrt_fclose (errfp); do_exec (pgmname, argv, inpipe[0], outpipe[1], errpipe[1], - except, preexec); + except, preexec, flags); /*NOTREACHED*/ } @@ -549,7 +558,7 @@ _gpgrt_spawn_process_fd (const char *pgmname, const char *argv[], gcry_control (GCRYCTL_TERM_SECMEM); can be done. */ /* Run child. */ - do_exec (pgmname, argv, infd, outfd, errfd, NULL, NULL); + do_exec (pgmname, argv, infd, outfd, errfd, NULL, NULL, 0); /*NOTREACHED*/ } @@ -849,7 +858,7 @@ _gpgrt_spawn_process_detached (const char *pgmname, const char *argv[], putenv (p); } - do_exec (pgmname, argv, -1, -1, -1, NULL, NULL); + do_exec (pgmname, argv, -1, -1, -1, NULL, NULL, 0); /*NOTREACHED*/ } |