mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Replace pipe+gnupg_spawn_process_fd by gnupg_process_spawn.
-- For g13. Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
2227411d77
commit
d579fa1b04
@ -28,10 +28,10 @@
|
||||
#include "g13.h"
|
||||
#include "../common/i18n.h"
|
||||
#include "keyblob.h"
|
||||
#include "be-encfs.h"
|
||||
#include "runner.h"
|
||||
#include "../common/sysutils.h"
|
||||
#include "../common/exechelp.h"
|
||||
#include "runner.h"
|
||||
#include "be-encfs.h"
|
||||
|
||||
|
||||
/* Command values used to run the encfs tool. */
|
||||
@ -218,12 +218,11 @@ run_encfs_tool (ctrl_t ctrl, enum encfs_cmds cmd,
|
||||
gpg_error_t err;
|
||||
encfs_parm_t parm;
|
||||
runner_t runner = NULL;
|
||||
int outbound[2] = { -1, -1 };
|
||||
int inbound[2] = { -1, -1 };
|
||||
const char *pgmname;
|
||||
const char *argv[10];
|
||||
pid_t pid = (pid_t)(-1);
|
||||
int idx;
|
||||
gnupg_process_t proc;
|
||||
int inbound, outbound;
|
||||
|
||||
(void)ctrl;
|
||||
|
||||
@ -246,15 +245,6 @@ run_encfs_tool (ctrl_t ctrl, enum encfs_cmds cmd,
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
err = gnupg_create_inbound_pipe (inbound, NULL, 0);
|
||||
if (!err)
|
||||
err = gnupg_create_outbound_pipe (outbound, NULL, 0);
|
||||
if (err)
|
||||
{
|
||||
log_error (_("error creating a pipe: %s\n"), gpg_strerror (err));
|
||||
goto leave;
|
||||
}
|
||||
|
||||
pgmname = ENCFS;
|
||||
idx = 0;
|
||||
argv[idx++] = "-f";
|
||||
@ -267,47 +257,42 @@ run_encfs_tool (ctrl_t ctrl, enum encfs_cmds cmd,
|
||||
argv[idx++] = NULL;
|
||||
assert (idx <= DIM (argv));
|
||||
|
||||
err = gnupg_spawn_process_fd (pgmname, argv,
|
||||
outbound[0], -1, inbound[1], &pid);
|
||||
err = gnupg_process_spawn (pgmname, argv,
|
||||
(GNUPG_PROCESS_STDIN_PIPE | GNUPG_PROCESS_STDOUT_NULL
|
||||
| GNUPG_PROCESS_STDERR_PIPE),
|
||||
NULL, NULL, &proc);
|
||||
if (err)
|
||||
{
|
||||
log_error ("error spawning '%s': %s\n", pgmname, gpg_strerror (err));
|
||||
goto leave;
|
||||
}
|
||||
close (outbound[0]); outbound[0] = -1;
|
||||
close ( inbound[1]); inbound[1] = -1;
|
||||
|
||||
runner_set_fds (runner, inbound[0], outbound[1]);
|
||||
inbound[0] = -1; /* Now owned by RUNNER. */
|
||||
outbound[1] = -1; /* Now owned by RUNNER. */
|
||||
err = gnupg_process_get_fds (proc, 0, &outbound, NULL, &inbound);
|
||||
if (err)
|
||||
{
|
||||
log_error ("error get fds '%s': %s\n", pgmname, gpg_strerror (err));
|
||||
gnupg_process_release (proc);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
runner_set_fds (runner, inbound, outbound);
|
||||
|
||||
runner_set_handler (runner, encfs_handler, encfs_handler_cleanup, parm);
|
||||
parm = NULL; /* Now owned by RUNNER. */
|
||||
|
||||
runner_set_pid (runner, pid);
|
||||
pid = (pid_t)(-1); /* The process is now owned by RUNNER. */
|
||||
runner_set_proc (runner, proc);
|
||||
|
||||
err = runner_spawn (runner);
|
||||
if (err)
|
||||
goto leave;
|
||||
{
|
||||
gnupg_process_release (proc);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
*r_id = runner_get_rid (runner);
|
||||
log_info ("running '%s' in the background\n", pgmname);
|
||||
|
||||
leave:
|
||||
if (inbound[0] != -1)
|
||||
close (inbound[0]);
|
||||
if (inbound[1] != -1)
|
||||
close (inbound[1]);
|
||||
if (outbound[0] != -1)
|
||||
close (outbound[0]);
|
||||
if (outbound[1] != -1)
|
||||
close (outbound[1]);
|
||||
if (pid != (pid_t)(-1))
|
||||
{
|
||||
gnupg_wait_process (pgmname, pid, 1, NULL);
|
||||
gnupg_release_process (pid);
|
||||
}
|
||||
runner_release (runner);
|
||||
encfs_handler_cleanup (parm);
|
||||
return err;
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include "../common/gc-opt-flags.h"
|
||||
#include "../common/asshelp.h"
|
||||
#include "../common/init.h"
|
||||
#include "../common/exechelp.h"
|
||||
#include "keyblob.h"
|
||||
#include "server.h"
|
||||
#include "runner.h"
|
||||
|
@ -34,10 +34,11 @@
|
||||
#include "backend.h"
|
||||
#include "g13tuple.h"
|
||||
#include "mountinfo.h"
|
||||
#include "runner.h"
|
||||
#include "../common/host2net.h"
|
||||
#include "server.h" /*(g13_keyblob_decrypt)*/
|
||||
#include "../common/sysutils.h"
|
||||
#include "../common/exechelp.h"
|
||||
#include "runner.h"
|
||||
#include "call-syshelp.h"
|
||||
|
||||
|
||||
|
36
g13/runner.c
36
g13/runner.c
@ -29,8 +29,8 @@
|
||||
#include "g13.h"
|
||||
#include "../common/i18n.h"
|
||||
#include "keyblob.h"
|
||||
#include "runner.h"
|
||||
#include "../common/exechelp.h"
|
||||
#include "runner.h"
|
||||
#include "mountinfo.h"
|
||||
|
||||
/* The runner object. */
|
||||
@ -55,7 +55,7 @@ struct runner_s
|
||||
2 = Thread is running and someone is holding a reference. */
|
||||
int refcount;
|
||||
|
||||
pid_t pid; /* PID of the backend's process (the engine). */
|
||||
gnupg_process_t proc; /* Process of the backend's process (the engine). */
|
||||
int in_fd; /* File descriptors to read from the engine. */
|
||||
int out_fd; /* File descriptors to write to the engine. */
|
||||
engine_handler_fnc_t handler; /* The handler functions. */
|
||||
@ -157,16 +157,16 @@ runner_release (runner_t runner)
|
||||
if (runner->handler_cleanup)
|
||||
runner->handler_cleanup (runner->handler_data);
|
||||
|
||||
if (runner->pid != (pid_t)(-1))
|
||||
if (runner->proc)
|
||||
{
|
||||
/* The process has not been cleaned up - do it now. */
|
||||
gnupg_kill_process (runner->pid);
|
||||
gnupg_process_terminate (runner->proc);
|
||||
/* (Actually we should use the program name and not the
|
||||
arbitrary NAME of the runner object. However it does not
|
||||
matter because that information is only used for
|
||||
diagnostics.) */
|
||||
gnupg_wait_process (runner->name, runner->pid, 1, NULL);
|
||||
gnupg_release_process (runner->pid);
|
||||
gnupg_process_wait (runner->proc, 1);
|
||||
gnupg_process_release (runner->proc);
|
||||
}
|
||||
|
||||
xfree (runner->name);
|
||||
@ -212,7 +212,7 @@ runner_new (runner_t *r_runner, const char *name)
|
||||
return gpg_error_from_syserror ();
|
||||
}
|
||||
runner->refcount = 1;
|
||||
runner->pid = (pid_t)(-1);
|
||||
runner->proc = NULL;
|
||||
runner->in_fd = -1;
|
||||
runner->out_fd = -1;
|
||||
|
||||
@ -266,15 +266,15 @@ runner_set_fds (runner_t runner, int in_fd, int out_fd)
|
||||
}
|
||||
|
||||
|
||||
/* Set the PID of the backend engine. After this call the engine is
|
||||
/* Set the PROC of the backend engine. After this call the engine is
|
||||
owned by the runner object. */
|
||||
void
|
||||
runner_set_pid (runner_t runner, pid_t pid)
|
||||
runner_set_proc (runner_t runner, gnupg_process_t proc)
|
||||
{
|
||||
if (check_already_spawned (runner, "runner_set_fds"))
|
||||
if (check_already_spawned (runner, "runner_set_proc"))
|
||||
return;
|
||||
|
||||
runner->pid = pid;
|
||||
runner->proc = proc;
|
||||
}
|
||||
|
||||
|
||||
@ -366,15 +366,17 @@ runner_thread (void *arg)
|
||||
}
|
||||
|
||||
/* Now wait for the process to finish. */
|
||||
if (!err && runner->pid != (pid_t)(-1))
|
||||
if (!err && runner->proc)
|
||||
{
|
||||
int exitcode;
|
||||
|
||||
log_debug ("runner thread waiting ...\n");
|
||||
err = gnupg_wait_process (runner->name, runner->pid, 1, &exitcode);
|
||||
gnupg_release_process (runner->pid);
|
||||
runner->pid = (pid_t)(-1);
|
||||
if (err)
|
||||
err = gnupg_process_wait (runner->proc, 1);
|
||||
if (!err)
|
||||
gnupg_process_ctl (runner->proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode);
|
||||
gnupg_process_release (runner->proc);
|
||||
runner->proc = NULL;
|
||||
if (exitcode)
|
||||
log_error ("running '%s' failed (exitcode=%d): %s\n",
|
||||
runner->name, exitcode, gpg_strerror (err));
|
||||
log_debug ("runner thread waiting finished\n");
|
||||
@ -473,7 +475,7 @@ runner_cancel (runner_t runner)
|
||||
need to change the thread to wait on an event. */
|
||||
runner->cancel_flag = 1;
|
||||
/* For now we use the brutal way and kill the process. */
|
||||
gnupg_kill_process (runner->pid);
|
||||
gnupg_process_terminate (runner->proc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ runner_t runner_find_by_rid (unsigned int rid);
|
||||
/* Functions to set properties of the runner. */
|
||||
void runner_set_fds (runner_t runner, int in_fd, int out_fd);
|
||||
|
||||
void runner_set_pid (runner_t runner, pid_t pid);
|
||||
void runner_set_proc (runner_t runner, gnupg_process_t proc);
|
||||
|
||||
/* Register the handler functions with a runner. */
|
||||
void runner_set_handler (runner_t runner,
|
||||
|
Loading…
x
Reference in New Issue
Block a user