Fix Windows port (spawn and assuan engine).

2011-02-02  Marcus Brinkmann  <mb@g10code.com>

        * configure.ac (NEED_LIBASSUAN_VERSION): Bump to 2.0.2 for system hooks.

src/
2011-02-02  Marcus Brinkmann  <mb@g10code.com>

        * assuan-support.c (my_socket, my_connect): New functions.
        (_gpgme_assuan_system_hooks): Add my_Socket, my_connect.
        * priv-io.h (_gpgme_io_socket): New prototype.
        * w32-io.c (pid_to_handle, handle_to_oid, fd_to_handle): Remove macros.
        (is_socket): Remove function.
        (_gpgme_io_spawn) [HAVE_W32CE_SYSTEM]: Remove some dead code.
        (_gpgme_io_spawn): Translate handles before DuplicateHandle them.
This commit is contained in:
Marcus Brinkmann 2011-02-02 14:07:05 +01:00
parent de287a7996
commit 129741d2f7
6 changed files with 43 additions and 45 deletions

View File

@ -1,3 +1,7 @@
2011-02-02 Marcus Brinkmann <mb@g10code.com>
* configure.ac (NEED_LIBASSUAN_VERSION): Bump to 2.0.2 for system hooks.
2010-12-30 Werner Koch <wk@g10code.com>
* configure.ac: Support a git revision.

View File

@ -62,7 +62,7 @@ GPGME_CONFIG_API_VERSION=1
##############################################
NEED_LIBASSUAN_API=2
NEED_LIBASSUAN_VERSION=2.0.0
NEED_LIBASSUAN_VERSION=2.0.2
m4_define([git_brevis],m4_esyscmd(printf "%u" 0x[]m4_substr(git_revision,0,4)))

View File

@ -1,3 +1,13 @@
2011-02-02 Marcus Brinkmann <mb@g10code.com>
* assuan-support.c (my_socket, my_connect): New functions.
(_gpgme_assuan_system_hooks): Add my_Socket, my_connect.
* priv-io.h (_gpgme_io_socket): New prototype.
* w32-io.c (pid_to_handle, handle_to_oid, fd_to_handle): Remove macros.
(is_socket): Remove function.
(_gpgme_io_spawn) [HAVE_W32CE_SYSTEM]: Remove some dead code.
(_gpgme_io_spawn): Translate handles before DuplicateHandle them.
2011-02-02 Marcus Brinkmann <mb@g10code.com>
* w32-util.c (mkstemp): Don't use CreateFile instead of open (the

View File

@ -222,6 +222,21 @@ my_socketpair (assuan_context_t ctx, int namespace, int style,
}
static int
my_socket (assuan_context_t ctx, int namespace, int style, int protocol)
{
return _gpgme_io_socket (namespace, style, protocol);
}
static int
my_connect (assuan_context_t ctx, int sock, struct sockaddr *addr,
socklen_t length)
{
return _gpgme_io_connect (sock, addr, length);
}
struct assuan_system_hooks _gpgme_assuan_system_hooks =
{
ASSUAN_SYSTEM_HOOKS_VERSION,
@ -234,6 +249,8 @@ struct assuan_system_hooks _gpgme_assuan_system_hooks =
my_sendmsg,
my_spawn,
my_waitpid,
my_socketpair
my_socketpair,
my_socket,
my_connect
};

View File

@ -64,6 +64,7 @@ struct io_select_fd_s
/* These function are either defined in posix-io.c or w32-io.c. */
void _gpgme_io_subsystem_init (void);
int _gpgme_io_socket (int namespace, int style, int protocol);
int _gpgme_io_connect (int fd, struct sockaddr *addr, int addrlen);
int _gpgme_io_read (int fd, void *buffer, size_t count);
int _gpgme_io_write (int fd, const void *buffer, size_t count);

View File

@ -125,9 +125,6 @@ release_fd (int fd)
}
#define pid_to_handle(a) ((HANDLE)(a))
#define handle_to_pid(a) ((int)(a))
#define fd_to_handle(a) ((HANDLE)(a))
#define handle_to_fd(a) ((int)(a))
#define READBUF_SIZE 4096
@ -260,40 +257,6 @@ set_synchronize (HANDLE hd)
}
/* Return 1 if HD refers to a socket, 0 if it does not refer to a
socket, and -1 for unknown (autodetect). */
static int
is_socket (HANDLE hd)
{
#ifdef HAVE_W32CE_SYSTEM
return -1;
#else
/* We need to figure out whether we are working on a socket or on a
handle. A trivial way would be to check for the return code of
recv and see if it is WSAENOTSOCK. However the recv may block
after the server process died and thus the destroy_reader will
hang. Another option is to use getsockopt to test whether it is
a socket. The bug here is that once a socket with a certain
values has been opened, closed and later a CreatePipe returned
the same value (i.e. handle), getsockopt still believes it is a
socket. What we do now is to use a combination of GetFileType
and GetNamedPipeInfo. The specs say that the latter may be used
on anonymous pipes as well. Note that there are claims that
since winsocket version 2 ReadFile may be used on a socket but
only if it is supported by the service provider. Tests on a
stock XP using a local TCP socket show that it does not work. */
DWORD dummyflags, dummyoutsize, dummyinsize, dummyinst;
if (GetFileType (hd) == FILE_TYPE_PIPE
&& !GetNamedPipeInfo (hd, &dummyflags, &dummyoutsize,
&dummyinsize, &dummyinst))
return 1; /* Function failed; thus we assume it is a socket. */
else
return 0; /* Success; this is not a socket. */
#endif
}
static DWORD CALLBACK
reader (void *arg)
{
@ -1605,11 +1568,9 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
si.hStdOutput = INVALID_HANDLE_VALUE;
si.hStdError = INVALID_HANDLE_VALUE;
cr_flags |= CREATE_SUSPENDED;
#ifndef HAVE_W32CE_SYSTEM
cr_flags |= CREATE_SUSPENDED;
cr_flags |= DETACHED_PROCESS;
cr_flags |= GetPriorityClass (GetCurrentProcess ());
#endif
if (!CreateProcessA (_gpgme_get_w32spawn_path (),
arg_string,
&sec_attr, /* process security attributes */
@ -1639,10 +1600,15 @@ _gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
/* Insert the inherited handles. */
for (i = 0; fd_list[i].fd != -1; i++)
{
HANDLE hd;
int fd = fd_list[i].fd;
HANDLE ohd = INVALID_HANDLE_VALUE;
HANDLE hd = INVALID_HANDLE_VALUE;
/* Make it inheritable for the wrapper process. */
if (!DuplicateHandle (GetCurrentProcess(), fd_to_handle (fd_list[i].fd),
if (fd >= 0 && fd < MAX_SLAFD && fd_table[fd].used)
ohd = fd_table[fd].handle;
if (!DuplicateHandle (GetCurrentProcess(), ohd,
pi.hProcess, &hd, 0, TRUE, DUPLICATE_SAME_ACCESS))
{
TRACE_LOG1 ("DuplicateHandle failed: ec=%d", (int) GetLastError ());