diff options
-rw-r--r-- | common/exechelp-posix.c | 22 | ||||
-rw-r--r-- | common/exechelp.h | 3 | ||||
-rw-r--r-- | common/exectool.c | 3 |
3 files changed, 14 insertions, 14 deletions
diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index f44256703..32ab4de76 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -990,27 +990,24 @@ posix_open_null (int for_write) static void my_exec (const char *pgmname, const char *argv[], int fd_in, int fd_out, int fd_err, - int (*spawn_cb) (void *), void *spawn_cb_arg) + void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg) { int i; - int ask_inherit = 0; struct spawn_cb_arg sca; - sca.fds[0] = fd_in; sca.fds[1] = fd_out; sca.fds[2] = fd_err; sca.except_fds = NULL; sca.arg = spawn_cb_arg; + if (spawn_cb) + (*spawn_cb) (&sca); /* Assign /dev/null to unused FDs. */ for (i = 0; i <= 2; i++) if (sca.fds[i] == -1) 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 (sca.fds[i] != i) @@ -1018,12 +1015,15 @@ my_exec (const char *pgmname, const char *argv[], 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 (sca.fds[i]); + /* + * We don't close sca.fds[i] here, but close them by + * close_all_fds. Note that there may be same one in three of + * sca.fds[i]. + */ } /* Close all other files. */ - if (!ask_inherit) - close_all_fds (3, sca.except_fds); + 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. */ @@ -1033,7 +1033,7 @@ my_exec (const char *pgmname, const char *argv[], static gpg_err_code_t spawn_detached (gnupg_process_t process, const char *pgmname, const char *argv[], - int (*spawn_cb) (void *), void *spawn_cb_arg) + void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg) { gpg_err_code_t ec; pid_t pid; @@ -1107,7 +1107,7 @@ 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) (struct spawn_cb_arg *), + void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg, gnupg_process_t *r_process) { diff --git a/common/exechelp.h b/common/exechelp.h index 05254cd21..d2b601a51 100644 --- a/common/exechelp.h +++ b/common/exechelp.h @@ -214,6 +214,7 @@ typedef struct gnupg_process *gnupg_process_t; struct spawn_cb_arg; #ifdef NEED_STRUCT_SPAWN_CB_ARG struct spawn_cb_arg { + int ask_inherit; void *plpAttributeList; HANDLE hd[16]; void *arg; @@ -252,7 +253,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) (struct spawn_cb_arg *), + void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg, gnupg_process_t *r_process); diff --git a/common/exectool.c b/common/exectool.c index 02b99458e..3cbf3abb2 100644 --- a/common/exectool.c +++ b/common/exectool.c @@ -301,13 +301,12 @@ copy_buffer_flush (struct copy_buffer *c, estream_t sink) } -static int +static void setup_close_all (struct spawn_cb_arg *sca) { int *user_except = sca->arg; sca->except_fds = user_except; - return 0; } /* Run the program PGMNAME with the command line arguments given in |