mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-07 17:33:02 +01:00
More fixes. First successful use; leaks threads, though.
This commit is contained in:
parent
837ce29cbc
commit
2946819dfc
@ -446,6 +446,9 @@ main (int argc, char **argv )
|
|||||||
gpg_strerror (err));
|
gpg_strerror (err));
|
||||||
}
|
}
|
||||||
#endif /*USE_GNU_PTH && !HAVE_W32_SYSTEM*/
|
#endif /*USE_GNU_PTH && !HAVE_W32_SYSTEM*/
|
||||||
|
#ifdef HAVE_W32_SYSTEM
|
||||||
|
pth_init ();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Check that the libraries are suitable. Do it here because
|
/* Check that the libraries are suitable. Do it here because
|
||||||
the option parsing may need services of the library. */
|
the option parsing may need services of the library. */
|
||||||
@ -728,7 +731,6 @@ main (int argc, char **argv )
|
|||||||
; /* NOTREACHED */
|
; /* NOTREACHED */
|
||||||
else
|
else
|
||||||
{ /* Regular server mode */
|
{ /* Regular server mode */
|
||||||
#ifndef HAVE_W32_SYSTEM
|
|
||||||
int fd;
|
int fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int len;
|
int len;
|
||||||
@ -739,8 +741,10 @@ main (int argc, char **argv )
|
|||||||
default to a specific display. There is still a default
|
default to a specific display. There is still a default
|
||||||
display when gpg-agent weas started using --display or a
|
display when gpg-agent weas started using --display or a
|
||||||
client requested this using an OPTION command. */
|
client requested this using an OPTION command. */
|
||||||
|
#ifndef HAVE_W32_SYSTEM
|
||||||
if (!opt.keep_display)
|
if (!opt.keep_display)
|
||||||
unsetenv ("DISPLAY");
|
unsetenv ("DISPLAY");
|
||||||
|
#endif
|
||||||
|
|
||||||
*socket_name = 0;
|
*socket_name = 0;
|
||||||
snprintf (socket_name, DIM(socket_name)-1,
|
snprintf (socket_name, DIM(socket_name)-1,
|
||||||
@ -750,12 +754,15 @@ main (int argc, char **argv )
|
|||||||
if (!p)
|
if (!p)
|
||||||
BUG ();
|
BUG ();
|
||||||
*p = 0;;
|
*p = 0;;
|
||||||
|
|
||||||
|
#ifndef HAVE_W32_SYSTEM
|
||||||
if (!mkdtemp(socket_name))
|
if (!mkdtemp(socket_name))
|
||||||
{
|
{
|
||||||
log_error ("can't create directory `%s': %s\n",
|
log_error ("can't create directory `%s': %s\n",
|
||||||
socket_name, strerror(errno) );
|
socket_name, strerror(errno) );
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
*p = '/';
|
*p = '/';
|
||||||
|
|
||||||
if (strchr (socket_name, ':') )
|
if (strchr (socket_name, ':') )
|
||||||
@ -769,8 +776,11 @@ main (int argc, char **argv )
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_W32_SYSTEM
|
||||||
|
fd = _w32_sock_new (AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
#else
|
||||||
fd = socket (AF_UNIX, SOCK_STREAM, 0);
|
fd = socket (AF_UNIX, SOCK_STREAM, 0);
|
||||||
|
#endif
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
{
|
{
|
||||||
log_error ("can't create socket: %s\n", strerror(errno) );
|
log_error ("can't create socket: %s\n", strerror(errno) );
|
||||||
@ -783,7 +793,13 @@ main (int argc, char **argv )
|
|||||||
len = (offsetof (struct sockaddr_un, sun_path)
|
len = (offsetof (struct sockaddr_un, sun_path)
|
||||||
+ strlen(serv_addr.sun_path) + 1);
|
+ strlen(serv_addr.sun_path) + 1);
|
||||||
|
|
||||||
if (bind (fd, (struct sockaddr*)&serv_addr, len) == -1)
|
if (
|
||||||
|
#ifdef HAVE_W32_SYSTEM
|
||||||
|
_w32_sock_bind
|
||||||
|
#else
|
||||||
|
bind
|
||||||
|
#endif
|
||||||
|
(fd, (struct sockaddr*)&serv_addr, len) == -1)
|
||||||
{
|
{
|
||||||
log_error ("error binding socket to `%s': %s\n",
|
log_error ("error binding socket to `%s': %s\n",
|
||||||
serv_addr.sun_path, strerror (errno) );
|
serv_addr.sun_path, strerror (errno) );
|
||||||
@ -803,6 +819,7 @@ main (int argc, char **argv )
|
|||||||
|
|
||||||
|
|
||||||
fflush (NULL);
|
fflush (NULL);
|
||||||
|
#ifndef HAVE_W32_SYSTEM
|
||||||
pid = fork ();
|
pid = fork ();
|
||||||
if (pid == (pid_t)-1)
|
if (pid == (pid_t)-1)
|
||||||
{
|
{
|
||||||
@ -857,7 +874,6 @@ main (int argc, char **argv )
|
|||||||
}
|
}
|
||||||
/*NEVER REACHED*/
|
/*NEVER REACHED*/
|
||||||
} /* end parent */
|
} /* end parent */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This is the child
|
This is the child
|
||||||
@ -893,6 +909,8 @@ main (int argc, char **argv )
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /*!HAVE_W32_SYSTEM*/
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_GNU_PTH
|
#ifdef USE_GNU_PTH
|
||||||
if (!disable_pth)
|
if (!disable_pth)
|
||||||
@ -931,7 +949,6 @@ main (int argc, char **argv )
|
|||||||
start_command_handler (fd, -1);
|
start_command_handler (fd, -1);
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
134
jnlib/w32-pth.c
134
jnlib/w32-pth.c
@ -573,8 +573,8 @@ pth_attr_set (pth_attr_t hd, int field, ...)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pth_t
|
static pth_t
|
||||||
pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg)
|
do_pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg)
|
||||||
{
|
{
|
||||||
SECURITY_ATTRIBUTES sa;
|
SECURITY_ATTRIBUTES sa;
|
||||||
DWORD tid;
|
DWORD tid;
|
||||||
@ -584,9 +584,6 @@ pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg)
|
|||||||
if (!hd)
|
if (!hd)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
implicit_init ();
|
|
||||||
enter_pth (__FUNCTION__);
|
|
||||||
|
|
||||||
memset (&sa, 0, sizeof sa);
|
memset (&sa, 0, sizeof sa);
|
||||||
sa.bInheritHandle = TRUE;
|
sa.bInheritHandle = TRUE;
|
||||||
sa.lpSecurityDescriptor = NULL;
|
sa.lpSecurityDescriptor = NULL;
|
||||||
@ -594,21 +591,32 @@ pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg)
|
|||||||
|
|
||||||
ctx = calloc (1, sizeof * ctx);
|
ctx = calloc (1, sizeof * ctx);
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
{
|
return NULL;
|
||||||
leave_pth (__FUNCTION__);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
ctx->thread = func;
|
ctx->thread = func;
|
||||||
ctx->arg = arg;
|
ctx->arg = arg;
|
||||||
|
|
||||||
/* XXX: we don't use all thread attributes. */
|
/* XXX: we don't use all thread attributes. */
|
||||||
|
|
||||||
fprintf (stderr, "pth_spawn creating thread ...\n");
|
fprintf (stderr, "do_pth_spawn creating thread ...\n");
|
||||||
th = CreateThread (&sa, hd->stack_size,
|
th = CreateThread (&sa, hd->stack_size,
|
||||||
(LPTHREAD_START_ROUTINE)helper_thread,
|
(LPTHREAD_START_ROUTINE)helper_thread,
|
||||||
ctx, 0, &tid);
|
ctx, 0, &tid);
|
||||||
fprintf (stderr, "pth_spawn created thread %p\n", th);
|
fprintf (stderr, "do_pth_spawn created thread %p\n", th);
|
||||||
|
|
||||||
|
return th;
|
||||||
|
}
|
||||||
|
|
||||||
|
pth_t
|
||||||
|
pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg)
|
||||||
|
{
|
||||||
|
HANDLE th;
|
||||||
|
|
||||||
|
if (!hd)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
implicit_init ();
|
||||||
|
enter_pth (__FUNCTION__);
|
||||||
|
th = do_pth_spawn (hd, func, arg);
|
||||||
leave_pth (__FUNCTION__);
|
leave_pth (__FUNCTION__);
|
||||||
return th;
|
return th;
|
||||||
}
|
}
|
||||||
@ -895,33 +903,6 @@ helper_thread (void * ctx)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *
|
|
||||||
wait_fd_thread (void * ctx)
|
|
||||||
{
|
|
||||||
pth_event_t ev = ctx;
|
|
||||||
|
|
||||||
wait_for_fd (ev->u.fd, ev->flags & PTH_UNTIL_FD_READABLE, 3600);
|
|
||||||
fprintf (stderr, "wait_fd_thread: exit.\n");
|
|
||||||
SetEvent (ev->hd);
|
|
||||||
ExitThread (0);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void *
|
|
||||||
wait_timer_thread (void * ctx)
|
|
||||||
{
|
|
||||||
pth_event_t ev = ctx;
|
|
||||||
int n = ev->u.tv.tv_sec*1000;
|
|
||||||
Sleep (n);
|
|
||||||
SetEvent (ev->hd);
|
|
||||||
fprintf (stderr, "wait_timer_thread: exit.\n");
|
|
||||||
ExitThread (0);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* void */
|
/* void */
|
||||||
/* sigemptyset (struct sigset_s * ss) */
|
/* sigemptyset (struct sigset_s * ss) */
|
||||||
/* { */
|
/* { */
|
||||||
@ -1079,16 +1060,6 @@ pth_event_isolate (pth_event_t ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_threads (HANDLE *waitbuf, int *hdidx, int n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i=0; i < n; i++)
|
|
||||||
CloseHandle (waitbuf[hdidx[i]]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
pth_event_count (pth_event_t ev)
|
pth_event_count (pth_event_t ev)
|
||||||
{
|
{
|
||||||
@ -1103,6 +1074,65 @@ pth_event_count (pth_event_t ev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static pth_t
|
||||||
|
spawn_helper_thread (pth_attr_t hd, void *(*func)(void *), void *arg)
|
||||||
|
{
|
||||||
|
SECURITY_ATTRIBUTES sa;
|
||||||
|
DWORD tid;
|
||||||
|
HANDLE th;
|
||||||
|
|
||||||
|
memset (&sa, 0, sizeof sa);
|
||||||
|
sa.bInheritHandle = TRUE;
|
||||||
|
sa.lpSecurityDescriptor = NULL;
|
||||||
|
sa.nLength = sizeof sa;
|
||||||
|
|
||||||
|
fprintf (stderr, "spawn_helper_thread creating thread ...\n");
|
||||||
|
th = CreateThread (&sa, hd->stack_size,
|
||||||
|
(LPTHREAD_START_ROUTINE)func,
|
||||||
|
arg, 0, &tid);
|
||||||
|
fprintf (stderr, "spawn_helper_thread created thread %p\n", th);
|
||||||
|
|
||||||
|
return th;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_helper_threads (HANDLE *waitbuf, int *hdidx, int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i=0; i < n; i++)
|
||||||
|
CloseHandle (waitbuf[hdidx[i]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void *
|
||||||
|
wait_fd_thread (void * ctx)
|
||||||
|
{
|
||||||
|
pth_event_t ev = ctx;
|
||||||
|
|
||||||
|
wait_for_fd (ev->u.fd, ev->flags & PTH_UNTIL_FD_READABLE, 3600);
|
||||||
|
fprintf (stderr, "wait_fd_thread: exit.\n");
|
||||||
|
SetEvent (ev->hd);
|
||||||
|
ExitThread (0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void *
|
||||||
|
wait_timer_thread (void * ctx)
|
||||||
|
{
|
||||||
|
pth_event_t ev = ctx;
|
||||||
|
int n = ev->u.tv.tv_sec*1000;
|
||||||
|
Sleep (n);
|
||||||
|
SetEvent (ev->hd);
|
||||||
|
fprintf (stderr, "wait_timer_thread: exit.\n");
|
||||||
|
ExitThread (0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
do_pth_wait (pth_event_t ev)
|
do_pth_wait (pth_event_t ev)
|
||||||
{
|
{
|
||||||
@ -1125,7 +1155,7 @@ do_pth_wait (pth_event_t ev)
|
|||||||
{
|
{
|
||||||
if (pos+1 > MAXIMUM_WAIT_OBJECTS/2)
|
if (pos+1 > MAXIMUM_WAIT_OBJECTS/2)
|
||||||
{
|
{
|
||||||
free_threads (waitbuf, hdidx, i);
|
free_helper_threads (waitbuf, hdidx, i);
|
||||||
pth_attr_destroy (attr);
|
pth_attr_destroy (attr);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1143,13 +1173,13 @@ do_pth_wait (pth_event_t ev)
|
|||||||
case PTH_EVENT_FD:
|
case PTH_EVENT_FD:
|
||||||
fprintf (stderr, "pth_wait: spawn event wait thread.\n");
|
fprintf (stderr, "pth_wait: spawn event wait thread.\n");
|
||||||
hdidx[i++] = pos;
|
hdidx[i++] = pos;
|
||||||
waitbuf[pos++] = pth_spawn (attr, wait_fd_thread, tmp);
|
waitbuf[pos++] = spawn_helper_thread (attr, wait_fd_thread, tmp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTH_EVENT_TIME:
|
case PTH_EVENT_TIME:
|
||||||
fprintf (stderr, "pth_wait: spawn event timer thread.\n");
|
fprintf (stderr, "pth_wait: spawn event timer thread.\n");
|
||||||
hdidx[i++] = pos;
|
hdidx[i++] = pos;
|
||||||
waitbuf[pos++] = pth_spawn (attr, wait_timer_thread, tmp);
|
waitbuf[pos++] = spawn_helper_thread (attr, wait_timer_thread, tmp);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PTH_EVENT_MUTEX:
|
case PTH_EVENT_MUTEX:
|
||||||
@ -1162,7 +1192,7 @@ do_pth_wait (pth_event_t ev)
|
|||||||
}
|
}
|
||||||
fprintf (stderr, "pth_wait: set %d\n", pos);
|
fprintf (stderr, "pth_wait: set %d\n", pos);
|
||||||
n = WaitForMultipleObjects (pos, waitbuf, FALSE, INFINITE);
|
n = WaitForMultipleObjects (pos, waitbuf, FALSE, INFINITE);
|
||||||
free_threads (waitbuf, hdidx, i);
|
free_helper_threads (waitbuf, hdidx, i);
|
||||||
pth_attr_destroy (attr);
|
pth_attr_destroy (attr);
|
||||||
fprintf (stderr, "pth_wait: n %ld\n", n);
|
fprintf (stderr, "pth_wait: n %ld\n", n);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user