diff --git a/agent/genkey.c b/agent/genkey.c index e2c6335bc..563407253 100644 --- a/agent/genkey.c +++ b/agent/genkey.c @@ -143,9 +143,7 @@ do_check_passphrase_pattern (ctrl_t ctrl, const char *pw, unsigned int flags) log_assert (i < sizeof argv); if (gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_PIPE - | GNUPG_PROCESS_STDOUT_NULL - | GNUPG_PROCESS_STDERR_NULL), + GNUPG_PROCESS_STDIN_PIPE, NULL, NULL, &proc)) result = 1; /* Execute error - assume password should no be used. */ else diff --git a/common/asshelp.c b/common/asshelp.c index 2053c55e6..8b3df2a4b 100644 --- a/common/asshelp.c +++ b/common/asshelp.c @@ -528,10 +528,7 @@ start_new_service (assuan_context_t *r_ctx, NULL, NULL, NULL); #else /*!W32*/ err = gnupg_process_spawn (program? program : program_name, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, NULL); + 0, NULL, NULL, NULL); #endif /*!W32*/ if (err) log_error ("failed to start %s '%s': %s\n", diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index 8e37473d8..6db7fdff1 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -646,14 +646,14 @@ gnupg_process_spawn (const char *pgmname, const char *argv1[], return ec; } } - else if ((flags & GNUPG_PROCESS_STDIN_NULL)) + else if ((flags & GNUPG_PROCESS_STDIN_KEEP)) { - fd_in[0] = -1; + fd_in[0] = 0; fd_in[1] = -1; } else { - fd_in[0] = 0; + fd_in[0] = -1; fd_in[1] = -1; } @@ -671,15 +671,15 @@ gnupg_process_spawn (const char *pgmname, const char *argv1[], return ec; } } - else if ((flags & GNUPG_PROCESS_STDOUT_NULL)) + else if ((flags & GNUPG_PROCESS_STDOUT_KEEP)) { fd_out[0] = -1; - fd_out[1] = -1; + fd_out[1] = 1; } else { fd_out[0] = -1; - fd_out[1] = 1; + fd_out[1] = -1; } } @@ -701,15 +701,15 @@ gnupg_process_spawn (const char *pgmname, const char *argv1[], return ec; } } - else if ((flags & GNUPG_PROCESS_STDERR_NULL)) + else if ((flags & GNUPG_PROCESS_STDERR_KEEP)) { fd_err[0] = -1; - fd_err[1] = -1; + fd_err[1] = 2; } else { fd_err[0] = -1; - fd_err[1] = 2; + fd_err[1] = -1; } pre_syscall (); diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c index 3ef261fa3..9da82304d 100644 --- a/common/exechelp-w32.c +++ b/common/exechelp-w32.c @@ -639,14 +639,14 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], return ec; } } - else if ((flags & GNUPG_PROCESS_STDIN_NULL)) + else if ((flags & GNUPG_PROCESS_STDIN_KEEP)) { - hd_in[0] = w32_open_null (0); + hd_in[0] = GetStdHandle (STD_INPUT_HANDLE); hd_in[1] = INVALID_HANDLE_VALUE; } else { - hd_in[0] = GetStdHandle (STD_INPUT_HANDLE); + hd_in[0] = w32_open_null (0); hd_in[1] = INVALID_HANDLE_VALUE; } @@ -664,15 +664,15 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], return ec; } } - else if ((flags & GNUPG_PROCESS_STDOUT_NULL)) + else if ((flags & GNUPG_PROCESS_STDOUT_KEEP)) { hd_out[0] = INVALID_HANDLE_VALUE; - hd_out[1] = w32_open_null (1); + hd_out[1] = GetStdHandle (STD_OUTPUT_HANDLE); } else { hd_out[0] = INVALID_HANDLE_VALUE; - hd_out[1] = GetStdHandle (STD_OUTPUT_HANDLE); + hd_out[1] = w32_open_null (1); } if ((flags & GNUPG_PROCESS_STDERR_PIPE)) @@ -693,15 +693,15 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], return ec; } } - else if ((flags & GNUPG_PROCESS_STDERR_NULL)) + else if ((flags & GNUPG_PROCESS_STDERR_KEEP)) { hd_err[0] = INVALID_HANDLE_VALUE; - hd_err[1] = w32_open_null (1); + hd_err[1] = GetStdHandle (STD_ERROR_HANDLE); } else { hd_err[0] = INVALID_HANDLE_VALUE; - hd_err[1] = GetStdHandle (STD_ERROR_HANDLE); + hd_err[1] = w32_open_null (1); } memset (&si, 0, sizeof si); @@ -754,19 +754,19 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], if (si.lpAttributeList == NULL) { if ((flags & GNUPG_PROCESS_STDIN_PIPE) - || (flags & GNUPG_PROCESS_STDIN_NULL)) + || !(flags & GNUPG_PROCESS_STDIN_KEEP)) CloseHandle (hd_in[0]); if ((flags & GNUPG_PROCESS_STDIN_PIPE)) CloseHandle (hd_in[1]); if ((flags & GNUPG_PROCESS_STDOUT_PIPE)) CloseHandle (hd_out[0]); if ((flags & GNUPG_PROCESS_STDOUT_PIPE) - || (flags & GNUPG_PROCESS_STDOUT_NULL)) + || !(flags & GNUPG_PROCESS_STDOUT_KEEP)) CloseHandle (hd_out[1]); if ((flags & GNUPG_PROCESS_STDERR_PIPE)) CloseHandle (hd_err[0]); if ((flags & GNUPG_PROCESS_STDERR_PIPE) - || (flags & GNUPG_PROCESS_STDERR_NULL)) + || !(flags & GNUPG_PROCESS_STDERR_KEEP)) CloseHandle (hd_err[1]); xfree (wpgmname); xfree (wcmdline); @@ -824,19 +824,19 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], log_error ("CreateProcess failed: ec=%d\n", (int)GetLastError ()); if ((flags & GNUPG_PROCESS_STDIN_PIPE) - || (flags & GNUPG_PROCESS_STDIN_NULL)) + || !(flags & GNUPG_PROCESS_STDIN_KEEP)) CloseHandle (hd_in[0]); if ((flags & GNUPG_PROCESS_STDIN_PIPE)) CloseHandle (hd_in[1]); if ((flags & GNUPG_PROCESS_STDOUT_PIPE)) CloseHandle (hd_out[0]); if ((flags & GNUPG_PROCESS_STDOUT_PIPE) - || (flags & GNUPG_PROCESS_STDOUT_NULL)) + || !(flags & GNUPG_PROCESS_STDOUT_KEEP)) CloseHandle (hd_out[1]); if ((flags & GNUPG_PROCESS_STDERR_PIPE)) CloseHandle (hd_err[0]); if ((flags & GNUPG_PROCESS_STDERR_PIPE) - || (flags & GNUPG_PROCESS_STDERR_NULL)) + || !(flags & GNUPG_PROCESS_STDERR_KEEP)) CloseHandle (hd_err[1]); xfree (wpgmname); xfree (wcmdline); @@ -852,13 +852,13 @@ gnupg_process_spawn (const char *pgmname, const char *argv[], xfree (cmdline); if ((flags & GNUPG_PROCESS_STDIN_PIPE) - || (flags & GNUPG_PROCESS_STDIN_NULL)) + || !(flags & GNUPG_PROCESS_STDIN_KEEP)) CloseHandle (hd_in[0]); if ((flags & GNUPG_PROCESS_STDOUT_PIPE) - || (flags & GNUPG_PROCESS_STDOUT_NULL)) + || !(flags & GNUPG_PROCESS_STDOUT_KEEP)) CloseHandle (hd_out[1]); if ((flags & GNUPG_PROCESS_STDERR_PIPE) - || (flags & GNUPG_PROCESS_STDERR_NULL)) + || !(flags & GNUPG_PROCESS_STDERR_KEEP)) CloseHandle (hd_err[1]); /* log_debug ("CreateProcess ready: hProcess=%p hThread=%p" */ diff --git a/common/exechelp.h b/common/exechelp.h index 1e80a7597..7ef2234c8 100644 --- a/common/exechelp.h +++ b/common/exechelp.h @@ -101,13 +101,13 @@ struct spawn_cb_arg { #define GNUPG_PROCESS_STDOUT_PIPE (1 << 9) #define GNUPG_PROCESS_STDERR_PIPE (1 << 10) #define GNUPG_PROCESS_STDINOUT_SOCKETPAIR (1 << 11) -#define GNUPG_PROCESS_STDIN_NULL (1 << 12) -#define GNUPG_PROCESS_STDOUT_NULL (1 << 13) -#define GNUPG_PROCESS_STDERR_NULL (1 << 14) +#define GNUPG_PROCESS_STDIN_KEEP (1 << 12) +#define GNUPG_PROCESS_STDOUT_KEEP (1 << 13) +#define GNUPG_PROCESS_STDERR_KEEP (1 << 14) #define GNUPG_PROCESS_STDFDS_SETTING ( GNUPG_PROCESS_STDIN_PIPE \ | GNUPG_PROCESS_STDOUT_PIPE | GNUPG_PROCESS_STDERR_PIPE \ - | GNUPG_PROCESS_STDINOUT_SOCKETPAIR | GNUPG_PROCESS_STDIN_NULL \ - | GNUPG_PROCESS_STDOUT_NULL | GNUPG_PROCESS_STDERR_NULL) + | GNUPG_PROCESS_STDINOUT_SOCKETPAIR | GNUPG_PROCESS_STDIN_KEEP \ + | GNUPG_PROCESS_STDOUT_KEEP | GNUPG_PROCESS_STDERR_KEEP) #define GNUPG_PROCESS_STREAM_NONBLOCK (1 << 16) diff --git a/common/exectool.c b/common/exectool.c index 9a8e61c20..3505c25f1 100644 --- a/common/exectool.c +++ b/common/exectool.c @@ -416,7 +416,7 @@ gnupg_exec_tool_stream (const char *pgmname, const char *argv[], err = gnupg_process_spawn (pgmname, argv, ((input ? GNUPG_PROCESS_STDIN_PIPE - : GNUPG_PROCESS_STDIN_NULL) + : 0) | GNUPG_PROCESS_STDOUT_PIPE | GNUPG_PROCESS_STDERR_PIPE), gnupg_spawn_helper, exceptclose, &proc); diff --git a/dirmngr/ldap-wrapper.c b/dirmngr/ldap-wrapper.c index 096642fda..1a3c50087 100644 --- a/dirmngr/ldap-wrapper.c +++ b/dirmngr/ldap-wrapper.c @@ -849,8 +849,7 @@ ldap_wrapper (ctrl_t ctrl, ksba_reader_t *reader, const char *argv[]) } err = gnupg_process_spawn (pgmname, arg_list, - (GNUPG_PROCESS_STDIN_NULL - | GNUPG_PROCESS_STDOUT_PIPE + (GNUPG_PROCESS_STDOUT_PIPE | GNUPG_PROCESS_STDERR_PIPE), NULL, NULL, &process); if (err) diff --git a/g10/photoid.c b/g10/photoid.c index 6f04f5ea2..a866eb083 100644 --- a/g10/photoid.c +++ b/g10/photoid.c @@ -599,9 +599,7 @@ run_with_pipe (struct spawn_info *info, const void *image, u32 len) gnupg_process_t proc; fill_command_argv (argv, info->command); - err = gnupg_process_spawn (argv[0], argv+1, - (GNUPG_PROCESS_STDIN_PIPE | GNUPG_PROCESS_STDOUT_NULL - | GNUPG_PROCESS_STDERR_NULL), + err = gnupg_process_spawn (argv[0], argv+1, GNUPG_PROCESS_STDIN_PIPE, NULL, NULL, &proc); if (err) log_error (_("unable to execute shell '%s': %s\n"), @@ -696,11 +694,7 @@ show_photo (const char *command, const char *name, const void *image, u32 len) const char *argv[4]; fill_command_argv (argv, spawn->command); - err = gnupg_process_spawn (argv[0], argv+1, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, NULL); + err = gnupg_process_spawn (argv[0], argv+1, 0, NULL, NULL, NULL); if (err) log_error (_("unnatural exit of external program\n")); #endif diff --git a/g13/be-encfs.c b/g13/be-encfs.c index c7873816b..ac6d6d6cd 100644 --- a/g13/be-encfs.c +++ b/g13/be-encfs.c @@ -260,7 +260,7 @@ run_encfs_tool (ctrl_t ctrl, enum encfs_cmds cmd, assert (idx <= DIM (argv)); err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_PIPE | GNUPG_PROCESS_STDOUT_NULL + (GNUPG_PROCESS_STDIN_PIPE | GNUPG_PROCESS_STDERR_PIPE), NULL, NULL, &proc); if (err) diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 3034a14c5..919e61195 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -3670,8 +3670,10 @@ cmd_gpg (card_info_t info, char *argstr, int use_gpgsm) } err = gnupg_process_spawn (use_gpgsm? opt.gpgsm_program:opt.gpg_program, - argv, GNUPG_PROCESS_STDIN_NULL, NULL, NULL, - &proc); + argv, + (GNUPG_PROCESS_STDOUT_KEEP + | GNUPG_PROCESS_STDERR_KEEP), + NULL, NULL, &proc); if (!err) { err = gnupg_process_wait (proc, 1); diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index f89ab3b9c..d6aa9d61b 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -761,11 +761,7 @@ gpg_agent_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, &proc); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) err = gnupg_process_wait (proc, 1); if (err) @@ -809,11 +805,7 @@ scdaemon_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, &proc); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) err = gnupg_process_wait (proc, 1); if (err) @@ -858,11 +850,7 @@ tpm2daemon_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, &proc); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) err = gnupg_process_wait (proc, 1); if (err) @@ -897,11 +885,7 @@ dirmngr_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, &proc); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) err = gnupg_process_wait (proc, 1); if (err) @@ -935,11 +919,7 @@ keyboxd_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, &proc); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) err = gnupg_process_wait (proc, 1); if (err) @@ -1005,11 +985,7 @@ gc_component_launch (int component) argv[i] = NULL; log_assert (i < DIM(argv)); - err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - |GNUPG_PROCESS_STDOUT_NULL - |GNUPG_PROCESS_STDERR_NULL), - NULL, NULL, &proc); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) err = gnupg_process_wait (proc, 1); if (err) @@ -1394,9 +1370,7 @@ gc_component_check_options (int component, estream_t out, const char *conf_file) result = 0; errlines = NULL; err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - | GNUPG_PROCESS_STDOUT_NULL - | GNUPG_PROCESS_STDERR_PIPE), + GNUPG_PROCESS_STDERR_PIPE, NULL, NULL, &proc); if (err) result |= 1; /* Program could not be run. */ @@ -1790,9 +1764,7 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) argv[0] = "--dump-option-table"; argv[1] = NULL; err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - | GNUPG_PROCESS_STDOUT_PIPE - | GNUPG_PROCESS_STDERR_NULL), + GNUPG_PROCESS_STDOUT_PIPE, NULL, NULL, &proc); if (err) { @@ -1981,9 +1953,7 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) argv[0] = "--gpgconf-list"; argv[1] = NULL; err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - | GNUPG_PROCESS_STDOUT_PIPE - | GNUPG_PROCESS_STDERR_NULL), + GNUPG_PROCESS_STDOUT_PIPE, NULL, NULL, &proc); if (err) { diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 46489df1f..522ce517b 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -1182,9 +1182,7 @@ show_versions_via_dirmngr (estream_t fp) argv[0] = "--gpgconf-versions"; argv[1] = NULL; err = gnupg_process_spawn (pgmname, argv, - (GNUPG_PROCESS_STDIN_NULL - | GNUPG_PROCESS_STDOUT_PIPE - | GNUPG_PROCESS_STDERR_NULL), + GNUPG_PROCESS_STDOUT_PIPE, NULL, NULL, &proc); if (err) { diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c index c239b0fc6..e6f5b55a2 100644 --- a/tools/gpgtar-create.c +++ b/tools/gpgtar-create.c @@ -1285,7 +1285,9 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, } err = gnupg_process_spawn (opt.gpg_program, argv, - GNUPG_PROCESS_STDIN_PIPE, + (GNUPG_PROCESS_STDIN_PIPE + | GNUPG_PROCESS_STDOUT_KEEP + | GNUPG_PROCESS_STDERR_KEEP), gnupg_spawn_helper, except, &proc); xfree (argv); if (err) diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c index c8e4a4571..be483f87c 100644 --- a/tools/gpgtar-extract.c +++ b/tools/gpgtar-extract.c @@ -426,7 +426,7 @@ gpgtar_extract (const char *filename, int decrypt) } err = gnupg_process_spawn (opt.gpg_program, argv, - ((filename ? GNUPG_PROCESS_STDIN_NULL : 0) + ((filename ? 0 : GNUPG_PROCESS_STDIN_KEEP) | GNUPG_PROCESS_STDOUT_PIPE), gnupg_spawn_helper, except, &proc); xfree (argv); diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c index 6d824d35c..31bcd8d46 100644 --- a/tools/gpgtar-list.c +++ b/tools/gpgtar-list.c @@ -504,7 +504,7 @@ gpgtar_list (const char *filename, int decrypt) } err = gnupg_process_spawn (opt.gpg_program, argv, - ((filename ? GNUPG_PROCESS_STDIN_NULL : 0) + ((filename ? 0 : GNUPG_PROCESS_STDIN_KEEP) | GNUPG_PROCESS_STDOUT_PIPE), gnupg_spawn_helper, except, &proc); xfree (argv);