aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2022-11-28 00:43:24 +0000
committerNIIBE Yutaka <[email protected]>2022-11-28 00:43:24 +0000
commit60b6cfe71f15e68c8c21daf5da9f4609318e2500 (patch)
tree316a088251faaf4117b8dbd13131aa4e6181e6f0
parentChange spawn_cb semantics. (diff)
downloadgnupg-60b6cfe71f15e68c8c21daf5da9f4609318e2500.tar.gz
gnupg-60b6cfe71f15e68c8c21daf5da9f4609318e2500.zip
posix: Fix for spawn_cb.
-- Fixes: 7571fd4cd02571ddd0ba84700c0a52704f0a9b5c Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r--common/exechelp-posix.c8
-rw-r--r--common/exechelp.h1
-rw-r--r--common/exectool.c10
3 files changed, 11 insertions, 8 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c
index a3237020e..f44256703 100644
--- a/common/exechelp-posix.c
+++ b/common/exechelp-posix.c
@@ -1000,11 +1000,12 @@ my_exec (const char *pgmname, const char *argv[],
sca.fds[0] = fd_in;
sca.fds[1] = fd_out;
sca.fds[2] = fd_err;
+ sca.except_fds = NULL;
sca.arg = spawn_cb_arg;
/* Assign /dev/null to unused FDs. */
for (i = 0; i <= 2; i++)
- if (fds[i] == -1)
+ if (sca.fds[i] == -1)
sca.fds[i] = posix_open_null (i);
if (spawn_cb)
@@ -1022,7 +1023,7 @@ my_exec (const char *pgmname, const char *argv[],
/* Close all other files. */
if (!ask_inherit)
- close_all_fds (3, NULL);
+ close_all_fds (3, sca.except_fds);
execv (pgmname, (char *const *)argv);
/* No way to print anything, as we have may have closed all streams. */
@@ -1106,7 +1107,8 @@ spawn_detached (gnupg_process_t process,
gpg_err_code_t
gnupg_process_spawn (const char *pgmname, const char *argv1[],
unsigned int flags,
- int (*spawn_cb) (void *), void *spawn_cb_arg,
+ int (*spawn_cb) (struct spawn_cb_arg *),
+ void *spawn_cb_arg,
gnupg_process_t *r_process)
{
gpg_err_code_t ec;
diff --git a/common/exechelp.h b/common/exechelp.h
index dfca18f1e..05254cd21 100644
--- a/common/exechelp.h
+++ b/common/exechelp.h
@@ -222,6 +222,7 @@ struct spawn_cb_arg {
#else
struct spawn_cb_arg {
int fds[3];
+ int *except_fds;
void *arg;
};
#endif
diff --git a/common/exectool.c b/common/exectool.c
index a09747d88..02b99458e 100644
--- a/common/exectool.c
+++ b/common/exectool.c
@@ -302,12 +302,12 @@ copy_buffer_flush (struct copy_buffer *c, estream_t sink)
static int
-close_all_except (void *arg)
+setup_close_all (struct spawn_cb_arg *sca)
{
- int *exceptclose = arg;
+ int *user_except = sca->arg;
- close_all_fds (3, exceptclose);
- return 1;
+ sca->except_fds = user_except;
+ return 0;
}
/* Run the program PGMNAME with the command line arguments given in
@@ -424,7 +424,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[],
: GNUPG_PROCESS_STDIN_NULL)
| GNUPG_PROCESS_STDOUT_PIPE
| GNUPG_PROCESS_STDERR_PIPE),
- close_all_except, exceptclose, &proc);
+ setup_close_all, exceptclose, &proc);
gnupg_process_get_streams (proc, GNUPG_PROCESS_STREAM_NONBLOCK,
input? &infp : NULL, &outfp, &errfp);
if (extrapipe[0] != -1)