diff options
author | Marcus Brinkmann <[email protected]> | 2011-02-02 13:07:05 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2011-02-02 13:11:18 +0000 |
commit | 129741d2f713305a862a1505f20738a0ce2ea656 (patch) | |
tree | b737e85be31ea6076b36b1ec546581eb1c2c7dab /src/w32-io.c | |
parent | Merge commit 'a2b9adafe46c55a2c26dd46163055bbdf3526835' (diff) | |
download | gpgme-129741d2f713305a862a1505f20738a0ce2ea656.tar.gz gpgme-129741d2f713305a862a1505f20738a0ce2ea656.zip |
Fix Windows port (spawn and assuan engine).
2011-02-02 Marcus Brinkmann <[email protected]>
* configure.ac (NEED_LIBASSUAN_VERSION): Bump to 2.0.2 for system hooks.
src/
2011-02-02 Marcus Brinkmann <[email protected]>
* 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.
Diffstat (limited to 'src/w32-io.c')
-rw-r--r-- | src/w32-io.c | 52 |
1 files changed, 9 insertions, 43 deletions
diff --git a/src/w32-io.c b/src/w32-io.c index 168177e5..10e0dade 100644 --- a/src/w32-io.c +++ b/src/w32-io.c @@ -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 ()); |