diff options
author | NIIBE Yutaka <[email protected]> | 2022-11-25 11:10:31 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2022-11-25 11:10:31 +0000 |
commit | 7571fd4cd02571ddd0ba84700c0a52704f0a9b5c (patch) | |
tree | 6ecff59b3a3346c4339ced987db8b7cd322693b5 | |
parent | Replace other use cases of gnupg_spawn_process_fd. (diff) | |
download | gnupg-7571fd4cd02571ddd0ba84700c0a52704f0a9b5c.tar.gz gnupg-7571fd4cd02571ddd0ba84700c0a52704f0a9b5c.zip |
Change spawn_cb semantics.
--
So that the callback can replace fds for stdin/out/err.
Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r-- | common/exechelp-posix.c | 24 | ||||
-rw-r--r-- | common/exechelp.h | 8 |
2 files changed, 20 insertions, 12 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index 8f21cbf75..a3237020e 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -993,31 +993,33 @@ my_exec (const char *pgmname, const char *argv[], int (*spawn_cb) (void *), void *spawn_cb_arg) { int i; - int fds[3]; int ask_inherit = 0; + struct spawn_cb_arg sca; - fds[0] = fd_in; - fds[1] = fd_out; - fds[2] = fd_err; + + sca.fds[0] = fd_in; + sca.fds[1] = fd_out; + sca.fds[2] = fd_err; + sca.arg = spawn_cb_arg; /* Assign /dev/null to unused FDs. */ for (i = 0; i <= 2; i++) if (fds[i] == -1) - fds[i] = posix_open_null (i); + sca.fds[i] = posix_open_null (i); + + if (spawn_cb) + ask_inherit = (*spawn_cb) (&sca); /* Connect the standard files. */ for (i = 0; i <= 2; i++) - if (fds[i] != i) + if (sca.fds[i] != i) { - if (dup2 (fds[i], i) == -1) + if (dup2 (sca.fds[i], i) == -1) log_fatal ("dup2 std%s failed: %s\n", i==0?"in":i==1?"out":"err", strerror (errno)); - close (fds[i]); + close (sca.fds[i]); } - if (spawn_cb) - ask_inherit = (*spawn_cb) (spawn_cb_arg); - /* Close all other files. */ if (!ask_inherit) close_all_fds (3, NULL); diff --git a/common/exechelp.h b/common/exechelp.h index fa835a033..dfca18f1e 100644 --- a/common/exechelp.h +++ b/common/exechelp.h @@ -211,6 +211,7 @@ gpg_error_t gnupg_spawn_process_detached (const char *pgmname, /* The opaque type for a subprocess. */ typedef struct gnupg_process *gnupg_process_t; #ifdef HAVE_W32_SYSTEM +struct spawn_cb_arg; #ifdef NEED_STRUCT_SPAWN_CB_ARG struct spawn_cb_arg { void *plpAttributeList; @@ -218,6 +219,11 @@ struct spawn_cb_arg { void *arg; }; #endif +#else +struct spawn_cb_arg { + int fds[3]; + void *arg; +}; #endif /* Internal flag to ihnerit file descriptor/handle */ @@ -245,7 +251,7 @@ struct spawn_cb_arg { /* Spawn PGMNAME. */ gpg_err_code_t gnupg_process_spawn (const char *pgmname, const char *argv[], unsigned int flags, - int (*spawn_cb) (void *), + int (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg, gnupg_process_t *r_process); |