mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
agent: Use new libassuan API for pipe server process.
* agent/call-daemon.c (struct wait_child_thread_parm_s): Remove PID field. (wait_child_thread): Don't touch the internals but call assuan_pipe_wait_server_termination. (daemon_start): Don't use PID. (agent_daemon_dump_state): Don't use PID. * agent/call-pinentry.c (watch_sock): Call assuan_pipe_kill_server. (agent_popup_message_stop): Likewise. -- GnuPG-bug-id: 6487 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
510f9185de
commit
9eb8cb642f
@ -98,7 +98,6 @@ static npth_mutex_t start_daemon_lock;
|
|||||||
struct wait_child_thread_parm_s
|
struct wait_child_thread_parm_s
|
||||||
{
|
{
|
||||||
enum daemon_type type;
|
enum daemon_type type;
|
||||||
pid_t pid;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -109,54 +108,14 @@ wait_child_thread (void *arg)
|
|||||||
int err;
|
int err;
|
||||||
struct wait_child_thread_parm_s *parm = arg;
|
struct wait_child_thread_parm_s *parm = arg;
|
||||||
enum daemon_type type = parm->type;
|
enum daemon_type type = parm->type;
|
||||||
pid_t pid = parm->pid;
|
|
||||||
#ifndef HAVE_W32_SYSTEM
|
|
||||||
int wstatus;
|
|
||||||
#endif
|
|
||||||
const char *name = opt.daemon_program[type];
|
const char *name = opt.daemon_program[type];
|
||||||
struct daemon_global_s *g = &daemon_global[type];
|
struct daemon_global_s *g = &daemon_global[type];
|
||||||
struct daemon_local_s *sl;
|
struct daemon_local_s *sl;
|
||||||
|
|
||||||
xfree (parm); /* We have copied all data to the stack. */
|
xfree (parm); /* We have copied all data to the stack. */
|
||||||
|
|
||||||
#ifdef HAVE_W32_SYSTEM
|
assuan_pipe_wait_server_termination (g->primary_ctx, NULL, 0);
|
||||||
npth_unprotect ();
|
|
||||||
/* Note that although we use a pid_t here, it is actually a HANDLE. */
|
|
||||||
WaitForSingleObject ((HANDLE)pid, INFINITE);
|
|
||||||
npth_protect ();
|
|
||||||
log_info ("daemon %s finished\n", name);
|
log_info ("daemon %s finished\n", name);
|
||||||
#else /* !HAVE_W32_SYSTEM*/
|
|
||||||
|
|
||||||
again:
|
|
||||||
npth_unprotect ();
|
|
||||||
err = waitpid (pid, &wstatus, 0);
|
|
||||||
npth_protect ();
|
|
||||||
|
|
||||||
if (err < 0)
|
|
||||||
{
|
|
||||||
if (errno == EINTR)
|
|
||||||
goto again;
|
|
||||||
log_error ("waitpid for %s failed: %s\n", name, strerror (errno));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (WIFEXITED (wstatus))
|
|
||||||
log_info ("daemon %s finished (status %d)\n",
|
|
||||||
name, WEXITSTATUS (wstatus));
|
|
||||||
else if (WIFSIGNALED (wstatus))
|
|
||||||
log_info ("daemon %s killed by signal %d\n", name, WTERMSIG (wstatus));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (WIFSTOPPED (wstatus))
|
|
||||||
log_info ("daemon %s stopped by signal %d\n",
|
|
||||||
name, WSTOPSIG (wstatus));
|
|
||||||
goto again;
|
|
||||||
}
|
|
||||||
|
|
||||||
assuan_set_flag (g->primary_ctx, ASSUAN_NO_WAITPID, 1);
|
|
||||||
}
|
|
||||||
#endif /*!HAVE_W32_SYSTEM*/
|
|
||||||
|
|
||||||
agent_flush_cache (1); /* Flush the PIN cache. */
|
agent_flush_cache (1); /* Flush the PIN cache. */
|
||||||
|
|
||||||
@ -496,7 +455,6 @@ daemon_start (enum daemon_type type, ctrl_t ctrl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
wctp->type = type;
|
wctp->type = type;
|
||||||
wctp->pid = assuan_get_pid (g->primary_ctx);
|
|
||||||
err = npth_attr_init (&tattr);
|
err = npth_attr_init (&tattr);
|
||||||
if (!err)
|
if (!err)
|
||||||
{
|
{
|
||||||
@ -561,10 +519,9 @@ agent_daemon_dump_state (void)
|
|||||||
for (i = 0; i < DAEMON_MAX_TYPE; i++) {
|
for (i = 0; i < DAEMON_MAX_TYPE; i++) {
|
||||||
struct daemon_global_s *g = &daemon_global[i];
|
struct daemon_global_s *g = &daemon_global[i];
|
||||||
|
|
||||||
log_info ("%s: name %s primary_ctx=%p pid=%ld reusable=%d\n", __func__,
|
log_info ("%s: name %s primary_ctx=%p reusable=%d\n", __func__,
|
||||||
gnupg_module_name (daemon_modules[i]),
|
gnupg_module_name (daemon_modules[i]),
|
||||||
g->primary_ctx,
|
g->primary_ctx,
|
||||||
(long)assuan_get_pid (g->primary_ctx),
|
|
||||||
g->primary_ctx_reusable);
|
g->primary_ctx_reusable);
|
||||||
if (g->socket_name)
|
if (g->socket_name)
|
||||||
log_info ("%s: socket='%s'\n", __func__, g->socket_name);
|
log_info ("%s: socket='%s'\n", __func__, g->socket_name);
|
||||||
|
@ -1288,8 +1288,6 @@ build_cmd_setdesc (char *line, size_t linelen, const char *desc)
|
|||||||
static void *
|
static void *
|
||||||
watch_sock (void *arg)
|
watch_sock (void *arg)
|
||||||
{
|
{
|
||||||
pid_t pid = assuan_get_pid (entry_ctx);
|
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -1317,17 +1315,7 @@ watch_sock (void *arg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid == (pid_t)(-1))
|
assuan_pipe_kill_server (entry_ctx);
|
||||||
; /* No pid available can't send a kill. */
|
|
||||||
#ifdef HAVE_W32_SYSTEM
|
|
||||||
/* Older versions of assuan set PID to 0 on Windows to indicate an
|
|
||||||
invalid value. */
|
|
||||||
else if (pid != (pid_t) INVALID_HANDLE_VALUE && pid != 0)
|
|
||||||
TerminateProcess ((HANDLE)pid, 1);
|
|
||||||
#else
|
|
||||||
else if (pid > 0)
|
|
||||||
kill (pid, SIGINT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2122,7 +2110,6 @@ void
|
|||||||
agent_popup_message_stop (ctrl_t ctrl)
|
agent_popup_message_stop (ctrl_t ctrl)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
(void)ctrl;
|
(void)ctrl;
|
||||||
|
|
||||||
@ -2135,26 +2122,10 @@ agent_popup_message_stop (ctrl_t ctrl)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid = assuan_get_pid (entry_ctx);
|
if (popup_finished)
|
||||||
if (pid == (pid_t)(-1))
|
|
||||||
; /* No pid available can't send a kill. */
|
|
||||||
else if (popup_finished)
|
|
||||||
; /* Already finished and ready for joining. */
|
; /* Already finished and ready for joining. */
|
||||||
#ifdef HAVE_W32_SYSTEM
|
else
|
||||||
/* Older versions of assuan set PID to 0 on Windows to indicate an
|
assuan_pipe_kill_server (entry_ctx);
|
||||||
invalid value. */
|
|
||||||
else if (pid != (pid_t) INVALID_HANDLE_VALUE
|
|
||||||
&& pid != 0)
|
|
||||||
{
|
|
||||||
HANDLE process = (HANDLE) pid;
|
|
||||||
|
|
||||||
/* Arbitrary error code. */
|
|
||||||
TerminateProcess (process, 1);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
else if (pid > 0)
|
|
||||||
kill (pid, SIGINT);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Now wait for the thread to terminate. */
|
/* Now wait for the thread to terminate. */
|
||||||
rc = npth_join (popup_tid, NULL);
|
rc = npth_join (popup_tid, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user