summaryrefslogtreecommitdiff
path: root/common/exechelp-posix.c
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2022-09-16 07:45:09 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2022-09-16 07:45:09 +0900
commit1e860c1f8b2b0b48617f2ca664aa9acf2fafc8d3 (patch)
treea945f12e0ecb03e7c1db7db427f469b46f5c71f9 /common/exechelp-posix.c
parent0fca6c1d0d6088ff4558a6ffc3bc220998699392 (diff)
downloadgpg2-1e860c1f8b2b0b48617f2ca664aa9acf2fafc8d3.tar.gz
gpg2-1e860c1f8b2b0b48617f2ca664aa9acf2fafc8d3.tar.bz2
gpg2-1e860c1f8b2b0b48617f2ca664aa9acf2fafc8d3.zip
Imported Upstream version 2.2.37upstream/2.2.37
Diffstat (limited to 'common/exechelp-posix.c')
-rw-r--r--common/exechelp-posix.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c
index 347a11b..e9cb7ed 100644
--- a/common/exechelp-posix.c
+++ b/common/exechelp-posix.c
@@ -276,16 +276,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 & GNUPG_SPAWN_KEEP_STDIN);
+ nodevnull[1] = !!(flags & GNUPG_SPAWN_KEEP_STDOUT);
+ nodevnull[2] = !!(flags & GNUPG_SPAWN_KEEP_STDERR);
+
/* Create the command line argument array. */
i = 0;
if (argv)
@@ -304,7 +309,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)
@@ -316,6 +323,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)
log_fatal ("dup2 std%s failed: %s\n",
i==0?"in":i==1?"out":"err", strerror (errno));
@@ -525,7 +534,7 @@ gnupg_spawn_process (const char *pgmname, const char *argv[],
es_fclose (outfp);
es_fclose (errfp);
do_exec (pgmname, argv, inpipe[0], outpipe[1], errpipe[1],
- except, preexec);
+ except, preexec, flags);
/*NOTREACHED*/
}
@@ -575,7 +584,7 @@ gnupg_spawn_process_fd (const char *pgmname, const char *argv[],
{
gcry_control (GCRYCTL_TERM_SECMEM);
/* Run child. */
- do_exec (pgmname, argv, infd, outfd, errfd, NULL, NULL);
+ do_exec (pgmname, argv, infd, outfd, errfd, NULL, NULL, 0);
/*NOTREACHED*/
}
@@ -874,7 +883,7 @@ gnupg_spawn_process_detached (const char *pgmname, const char *argv[],
for (i=0; envp[i]; i++)
putenv (xstrdup (envp[i]));
- do_exec (pgmname, argv, -1, -1, -1, NULL, NULL);
+ do_exec (pgmname, argv, -1, -1, -1, NULL, NULL, 0);
/*NOTREACHED*/
}