1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

spawn: Introduce *_KEEP, removing *_NULL.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2023-04-20 14:36:08 +09:00
parent 5d4c3b79ee
commit 4459d759fd
No known key found for this signature in database
GPG Key ID: 640114AF89DE6054
15 changed files with 58 additions and 98 deletions

View File

@ -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

View File

@ -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",

View File

@ -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 ();

View File

@ -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" */

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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);

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)

View File

@ -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);

View File

@ -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);