mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
Port Windows code to NPTH.
* agent/gpg-agent.c (get_agent_ssh_socket_name): Use INVALID_HANDLE_VALUE instead of 0. (handle_signal) [!HAVE_W32_SYSTEM]: Don't define. (handle_connections): Port Windows code to NPTH. * dirmngr/dirmngr.c (handle_connections): Port Windows code to NPTH. * g13/g13.c (handle_connections): Port Windows code to NPTH. * scd/scdaemon.c (handle_connections): Port Windows code to NPTH.
This commit is contained in:
parent
709ad62855
commit
baa383a8d5
@ -1390,9 +1390,9 @@ get_agent_ssh_socket_name (void)
|
||||
void *
|
||||
get_agent_scd_notify_event (void)
|
||||
{
|
||||
static HANDLE the_event;
|
||||
static HANDLE the_event = INVALID_HANDLE_VALUE;
|
||||
|
||||
if (!the_event)
|
||||
if (the_event == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
HANDLE h, h2;
|
||||
SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE};
|
||||
@ -1716,6 +1716,7 @@ agent_sigusr2_action (void)
|
||||
}
|
||||
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
/* The signal handler for this program. It is expected to be run in
|
||||
its own trhead and not in the context of a signal handler. */
|
||||
static void
|
||||
@ -1768,7 +1769,7 @@ handle_signal (int signo)
|
||||
log_info ("signal %d received - no action defined\n", signo);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Check the nonce on a new connection. This is a NOP unless we we
|
||||
are using our Unix domain socket emulation under Windows. */
|
||||
@ -1848,7 +1849,6 @@ static void
|
||||
handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|
||||
{
|
||||
npth_attr_t tattr;
|
||||
int signo;
|
||||
struct sockaddr_un paddr;
|
||||
socklen_t plen;
|
||||
fd_set fdset, read_fdset;
|
||||
@ -1859,6 +1859,10 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|
||||
struct timespec abstime;
|
||||
struct timespec curtime;
|
||||
struct timespec timeout;
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
HANDLE events[2];
|
||||
int events_set;
|
||||
#endif
|
||||
|
||||
ret = npth_attr_init(&tattr);
|
||||
/* FIXME: Check error. */
|
||||
@ -1878,9 +1882,8 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|
||||
sigs = 0;
|
||||
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
|
||||
# else
|
||||
sigs = 0;
|
||||
ev = pth_event (PTH_EVENT_HANDLE, get_agent_scd_notify_event ());
|
||||
signo = 0;
|
||||
events[0] = get_agent_scd_notify_event ();
|
||||
events[1] = INVALID_HANDLE_VALUE;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@ -1928,16 +1931,19 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|
||||
}
|
||||
npth_timersub (&abstime, &curtime, &timeout);
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, &timeout, npth_sigev_sigmask());
|
||||
saved_errno = errno;
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
while (npth_sigev_get_pending(&signo))
|
||||
handle_signal (signo);
|
||||
#endif
|
||||
#else
|
||||
events_set = 0;
|
||||
ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, &timeout, events, &events_set);
|
||||
saved_errno = errno;
|
||||
|
||||
#if defined(HAVE_W32_SYSTEM) && defined(PTH_EVENT_HANDLE)
|
||||
if (pth_event_occurred (ev))
|
||||
/* This is valid even if npth_eselect returns an error. */
|
||||
if (events_set & 1)
|
||||
agent_sigusr2_action ();
|
||||
#endif
|
||||
|
||||
@ -2022,7 +2028,7 @@ handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
|
||||
}
|
||||
else
|
||||
{
|
||||
pthread_t thread;
|
||||
npth_t thread;
|
||||
|
||||
agent_init_default_ctrl (ctrl);
|
||||
ctrl->thread_startup.fd = fd;
|
||||
|
@ -1749,9 +1749,6 @@ handle_connections (assuan_fd_t listen_fd)
|
||||
npth_sigev_add (SIGINT);
|
||||
npth_sigev_add (SIGTERM);
|
||||
npth_sigev_fini ();
|
||||
#else
|
||||
/* Use a dummy event. */
|
||||
sigs = 0;
|
||||
#endif
|
||||
|
||||
/* Setup the fdset. It has only one member. This is because we use
|
||||
@ -1791,12 +1788,15 @@ handle_connections (assuan_fd_t listen_fd)
|
||||
}
|
||||
npth_timersub (&abstime, &curtime, &timeout);
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, &timeout, npth_sigev_sigmask());
|
||||
saved_errno = errno;
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
while (npth_sigev_get_pending(&signo))
|
||||
handle_signal (signo);
|
||||
#else
|
||||
ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, &timeout, NULL, NULL);
|
||||
saved_errno = errno;
|
||||
#endif
|
||||
|
||||
if (ret == -1 && saved_errno != EINTR)
|
||||
|
@ -854,8 +854,6 @@ idle_task (void *dummy_arg)
|
||||
npth_sigev_add (SIGINT);
|
||||
npth_sigev_add (SIGTERM);
|
||||
npth_sigev_fini ();
|
||||
#else
|
||||
sigs = 0;
|
||||
#endif
|
||||
|
||||
npth_clock_gettime (&abstime);
|
||||
@ -882,12 +880,15 @@ idle_task (void *dummy_arg)
|
||||
}
|
||||
npth_timersub (&abstime, &curtime, &timeout);
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
ret = npth_pselect (0, NULL, NULL, NULL, &timeout, npth_sigev_sigmask());
|
||||
saved_errno = errno;
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
while (npth_sigev_get_pending(&signo))
|
||||
handle_signal (signo);
|
||||
#else
|
||||
ret = npth_eselect (0, NULL, NULL, NULL, &timeout, NULL, NULL);
|
||||
saved_errno = errno;
|
||||
#endif
|
||||
|
||||
if (ret == -1 && saved_errno != EINTR)
|
||||
@ -920,6 +921,7 @@ start_idle_task (void)
|
||||
sigset_t sigs; /* The set of signals we want to catch. */
|
||||
int err;
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
/* These signals should always go to the idle task, so they need to
|
||||
be blocked everywhere else. We assume start_idle_task is called
|
||||
from the main thread before any other threads are created. */
|
||||
@ -930,6 +932,7 @@ start_idle_task (void)
|
||||
sigaddset (&sigs, SIGINT);
|
||||
sigaddset (&sigs, SIGTERM);
|
||||
npth_sigmask (SIG_BLOCK, &sigs, NULL);
|
||||
#endif
|
||||
|
||||
npth_attr_init (&tattr);
|
||||
npth_attr_setdetachstate (&tattr, NPTH_CREATE_JOINABLE);
|
||||
|
@ -1185,9 +1185,6 @@ handle_connections (int listen_fd)
|
||||
npth_sigev_add (SIGINT);
|
||||
npth_sigev_add (SIGTERM);
|
||||
npth_sigev_fini ();
|
||||
#else
|
||||
sigs = 0;
|
||||
ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
|
||||
#endif
|
||||
|
||||
FD_ZERO (&fdset);
|
||||
@ -1234,17 +1231,20 @@ handle_connections (int listen_fd)
|
||||
thus a simple assignment is fine to copy the entire set. */
|
||||
read_fdset = fdset;
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
ret = npth_pselect (nfd+1, &read_fdset, NULL, NULL, &timeout, npth_sigev_sigmask());
|
||||
saved_errno = errno;
|
||||
|
||||
#ifndef HAVE_W32_SYSTEM
|
||||
while (npth_sigev_get_pending(&signo))
|
||||
handle_signal (signo);
|
||||
#else
|
||||
ret = npth_eselect (nfd+1, &read_fdset, NULL, NULL, &timeout, NULL, NULL);
|
||||
saved_errno = errno;
|
||||
#endif
|
||||
|
||||
if (ret == -1 && saved_errno != EINTR)
|
||||
{
|
||||
log_error (_("pth_pselect failed: %s - waiting 1s\n"),
|
||||
log_error (_("npth_pselect failed: %s - waiting 1s\n"),
|
||||
strerror (saved_errno));
|
||||
npth_sleep (1);
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user