1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

common,tools,dirmngr: Introduce gnupg_process_spawn.

--

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2022-11-17 14:12:51 +09:00
parent 18a3ce1c9b
commit 729951f4c2
No known key found for this signature in database
GPG key ID: 640114AF89DE6054
12 changed files with 1629 additions and 140 deletions

View file

@ -1336,8 +1336,7 @@ gc_component_check_options (int component, estream_t out, const char *conf_file)
const char *pgmname;
const char *argv[6];
int i;
pid_t pid;
int exitcode;
gnupg_process_t proc;
estream_t errfp;
error_line_t errlines;
@ -1370,22 +1369,30 @@ gc_component_check_options (int component, estream_t out, const char *conf_file)
result = 0;
errlines = NULL;
err = gnupg_spawn_process (pgmname, argv, NULL, 0,
NULL, NULL, &errfp, &pid);
err = gnupg_process_spawn (pgmname, argv,
(GNUPG_PROCESS_STDIN_NULL
| GNUPG_PROCESS_STDOUT_NULL
| GNUPG_PROCESS_STDERR_PIPE),
NULL, NULL, &proc);
if (err)
result |= 1; /* Program could not be run. */
else
{
gnupg_process_get_streams (proc, 0, NULL, NULL, &errfp);
errlines = collect_error_output (errfp,
gc_component[component].name);
if (gnupg_wait_process (pgmname, pid, 1, &exitcode))
if (!gnupg_process_wait (proc, 1))
{
int exitcode;
gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode);
if (exitcode == -1)
result |= 1; /* Program could not be run or it
terminated abnormally. */
result |= 2; /* Program returned an error. */
else if (exitcode)
result |= 2; /* Program returned an error. */
}
gnupg_release_process (pid);
gnupg_process_release (proc);
es_fclose (errfp);
}
@ -1725,8 +1732,7 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed)
const char *pgmname;
const char *argv[2];
estream_t outfp;
int exitcode;
pid_t pid;
gnupg_process_t proc;
known_option_t *known_option;
gc_option_t *option;
char *line = NULL;
@ -1759,14 +1765,19 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed)
/* First we need to read the option table from the program. */
argv[0] = "--dump-option-table";
argv[1] = NULL;
err = gnupg_spawn_process (pgmname, argv, NULL, 0,
NULL, &outfp, NULL, &pid);
err = gnupg_process_spawn (pgmname, argv,
(GNUPG_PROCESS_STDIN_NULL
| GNUPG_PROCESS_STDOUT_PIPE
| GNUPG_PROCESS_STDERR_NULL),
NULL, NULL, &proc);
if (err)
{
gc_error (1, 0, "could not gather option table from '%s': %s",
pgmname, gpg_strerror (err));
}
gnupg_process_get_streams (proc, 0, NULL, &outfp, NULL);
read_line_parm.pgmname = pgmname;
read_line_parm.fp = outfp;
read_line_parm.line = line;
@ -1925,12 +1936,17 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed)
line_len = read_line_parm.line_len;
log_assert (opt_table_used + pseudo_count == opt_info_used);
err = gnupg_process_wait (proc, 1);
if (!err)
{
int exitcode;
err = gnupg_wait_process (pgmname, pid, 1, &exitcode);
if (err)
gc_error (1, 0, "running %s failed (exitcode=%d): %s",
pgmname, exitcode, gpg_strerror (err));
gnupg_release_process (pid);
gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode);
if (exitcode)
gc_error (1, 0, "running %s failed (exitcode=%d): %s",
pgmname, exitcode, gpg_strerror (err));
}
gnupg_process_release (proc);
/* Make the gpgrt option table and the internal option table available. */
gc_component[component].opt_table = opt_table;
@ -1940,14 +1956,19 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed)
/* Now read the default options. */
argv[0] = "--gpgconf-list";
argv[1] = NULL;
err = gnupg_spawn_process (pgmname, argv, NULL, 0,
NULL, &outfp, NULL, &pid);
err = gnupg_process_spawn (pgmname, argv,
(GNUPG_PROCESS_STDIN_NULL
| GNUPG_PROCESS_STDOUT_PIPE
| GNUPG_PROCESS_STDERR_NULL),
NULL, NULL, &proc);
if (err)
{
gc_error (1, 0, "could not gather active options from '%s': %s",
pgmname, gpg_strerror (err));
}
gnupg_process_get_streams (proc, 0, NULL, &outfp, NULL);
while ((length = es_read_line (outfp, &line, &line_len, NULL)) > 0)
{
char *linep;
@ -2030,11 +2051,17 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed)
if (es_fclose (outfp))
gc_error (1, errno, "error closing %s", pgmname);
err = gnupg_wait_process (pgmname, pid, 1, &exitcode);
if (err)
gc_error (1, 0, "running %s failed (exitcode=%d): %s",
pgmname, exitcode, gpg_strerror (err));
gnupg_release_process (pid);
err = gnupg_process_wait (proc, 1);
if (!err)
{
int exitcode;
gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode);
if (exitcode)
gc_error (1, 0, "running %s failed (exitcode=%d): %s",
pgmname, exitcode, gpg_strerror (err));
}
gnupg_process_release (proc);
/* At this point, we can parse the configuration file. */