diff options
author | NIIBE Yutaka <[email protected]> | 2022-11-29 10:27:15 +0000 |
---|---|---|
committer | NIIBE Yutaka <[email protected]> | 2022-11-29 10:27:15 +0000 |
commit | 236a8a3cfb5e52b57844e91db27e702312c035a6 (patch) | |
tree | a2a38899a3a1b813c70fa2b8a5e465480dfb4d3a | |
parent | Replace gnupg_spawn_process_detached for POSIX. (diff) | |
download | gnupg-236a8a3cfb5e52b57844e91db27e702312c035a6.tar.gz gnupg-236a8a3cfb5e52b57844e91db27e702312c035a6.zip |
common: Support new spawn functions for Windows.
--
Signed-off-by: NIIBE Yutaka <[email protected]>
-rw-r--r-- | common/exechelp-w32.c | 22 | ||||
-rw-r--r-- | common/exechelp.h | 2 | ||||
-rw-r--r-- | common/exectool.c | 12 | ||||
-rw-r--r-- | scd/app.c | 4 |
4 files changed, 29 insertions, 11 deletions
diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c index 1c4b8ac36..2140a4c0a 100644 --- a/common/exechelp-w32.c +++ b/common/exechelp-w32.c @@ -1098,7 +1098,7 @@ post_syscall (void) static gpg_err_code_t spawn_detached (gnupg_process_t process, const char *pgmname, char *cmdline, - int (*spawn_cb) (void *), void *spawn_cb_arg) + void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg) { SECURITY_ATTRIBUTES sec_attr; PROCESS_INFORMATION pi = { NULL, 0, 0, 0 }; @@ -1106,7 +1106,7 @@ spawn_detached (gnupg_process_t process, int cr_flags; wchar_t *wcmdline = NULL; wchar_t *wpgmname = NULL; - BOOL ask_inherit = FALSE; + BOOL ask_inherit; gpg_err_code_t ec; int ret; struct spawn_cb_arg sca; @@ -1121,11 +1121,13 @@ spawn_detached (gnupg_process_t process, memset (&si, 0, sizeof si); + sca.ask_inherit = FALSE; sca.plpAttributeList = &si.lpAttributeList; sca.arg = spawn_cb_arg; sca.hd[0] = INVALID_HANDLE_VALUE; - if (spawn_cb && (*spawn_cb) (&sca)) - ask_inherit = TRUE; + if (spawn_cb) + (*spawn_cb) (&sca); + ask_inherit = sca.ask_inherit; /* Prepare security attributes. */ memset (&sec_attr, 0, sizeof sec_attr ); @@ -1201,7 +1203,7 @@ spawn_detached (gnupg_process_t process, gpg_err_code_t gnupg_process_spawn (const char *pgmname, const char *argv[], unsigned int flags, - int (*spawn_cb) (void *), + void (*spawn_cb) (struct spawn_cb_arg *), void *spawn_cb_arg, gnupg_process_t *r_process) { @@ -1215,7 +1217,7 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], wchar_t *wcmdline = NULL; wchar_t *wpgmname = NULL; int ret; - BOOL ask_inherit = FALSE; + BOOL ask_inherit; HANDLE hd_in[2]; HANDLE hd_out[2]; HANDLE hd_err[2]; @@ -1339,6 +1341,7 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], memset (&si, 0, sizeof si); + sca.ask_inherit = FALSE; sca.plpAttributeList = &si.lpAttributeList; sca.arg = spawn_cb_arg; i = 0; @@ -1349,10 +1352,11 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], if (hd_err[1] != INVALID_HANDLE_VALUE) sca.hd[i++] = hd_err[1]; sca.hd[i] = INVALID_HANDLE_VALUE; + if (spawn_cb) + (*spawn_cb) (&sca); + ask_inherit = sca.ask_inherit; - if (spawn_cb && (*spawn_cb) (&sca)) - ask_inherit = TRUE; - else if (i != 0) + if (i != 0) { SIZE_T attr_list_size = 0; diff --git a/common/exechelp.h b/common/exechelp.h index d2b601a51..aca707bbd 100644 --- a/common/exechelp.h +++ b/common/exechelp.h @@ -214,7 +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; + BOOL ask_inherit; void *plpAttributeList; HANDLE hd[16]; void *arg; diff --git a/common/exectool.c b/common/exectool.c index 3cbf3abb2..b7882b401 100644 --- a/common/exectool.c +++ b/common/exectool.c @@ -38,10 +38,14 @@ #include <gpg-error.h> #include <assuan.h> + #include "i18n.h" #include "logging.h" #include "membuf.h" #include "mischelp.h" +#ifdef HAVE_W32_SYSTEM +#define NEED_STRUCT_SPAWN_CB_ARG 1 +#endif #include "exechelp.h" #include "sysutils.h" #include "util.h" @@ -305,8 +309,14 @@ static void setup_close_all (struct spawn_cb_arg *sca) { int *user_except = sca->arg; - +#ifdef HAVE_W32_SYSTEM + if (user_except[0] == -1) + sca->ask_inherit = 0; + else + sca->ask_inherit = 1; +#else sca->except_fds = user_except; +#endif } /* Run the program PGMNAME with the command line arguments given in @@ -2318,9 +2318,13 @@ app_check_pin (card_t card, ctrl_t ctrl, const char *keyidstr, static void setup_env (struct spawn_cb_arg *sca) { +#ifdef HAVE_W32_SYSTEM + (void)sca; /* Not supported on Windows. */ +#else char *v = sca->arg; putenv (v); +#endif } static void |