2003-01-29 20:03:24 +00:00
|
|
|
|
/* w32-io.c - W32 API I/O functions.
|
2018-10-31 13:58:23 +00:00
|
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
|
|
|
|
* Copyright (C) 2001-2004, 2007, 2010, 2018 g10 Code GmbH
|
|
|
|
|
*
|
|
|
|
|
* This file is part of GPGME.
|
|
|
|
|
*
|
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify it
|
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* GPGME is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this program; if not, see <https://gnu.org/licenses/>.
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
|
*/
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <config.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#endif
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <fcntl.h>
|
2010-11-02 16:27:46 +00:00
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
|
# include <sys/time.h>
|
|
|
|
|
#endif
|
2010-11-03 09:56:27 +00:00
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
#endif
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#include <io.h>
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2010-11-02 16:27:46 +00:00
|
|
|
|
#include "util.h"
|
2001-01-30 11:01:41 +00:00
|
|
|
|
#include "sema.h"
|
2005-03-24 13:05:12 +00:00
|
|
|
|
#include "priv-io.h"
|
2005-03-09 11:47:21 +00:00
|
|
|
|
#include "debug.h"
|
2016-08-18 14:56:58 +00:00
|
|
|
|
#include "sys-util.h"
|
2000-11-23 15:28:15 +00:00
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* The number of entries in our file table. We may eventually use a
|
|
|
|
|
* lower value and dynamically resize the table. */
|
2010-06-10 13:49:19 +00:00
|
|
|
|
#define MAX_SLAFD 512
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
#define handle_to_fd(a) ((int)(a))
|
|
|
|
|
|
|
|
|
|
#define READBUF_SIZE 4096
|
|
|
|
|
#define WRITEBUF_SIZE 4096
|
|
|
|
|
#define PIPEBUF_SIZE 4096
|
|
|
|
|
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
/* An object to store handles or sockets. */
|
|
|
|
|
struct hddesc_s
|
|
|
|
|
{
|
|
|
|
|
HANDLE hd;
|
|
|
|
|
SOCKET sock;
|
|
|
|
|
int refcount;
|
|
|
|
|
};
|
|
|
|
|
typedef struct hddesc_s *hddesc_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* The context used by a reader thread. */
|
|
|
|
|
struct reader_context_s
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
hddesc_t hdd;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
HANDLE thread_hd;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
int refcount; /* Bumped if the FD has been duped and thus we have
|
|
|
|
|
* another FD referencing this context. */
|
2018-11-01 08:53:48 +00:00
|
|
|
|
|
|
|
|
|
DECLARE_LOCK (mutex);
|
|
|
|
|
|
|
|
|
|
int stop_me;
|
|
|
|
|
int eof;
|
|
|
|
|
int eof_shortcut;
|
|
|
|
|
int error;
|
|
|
|
|
int error_code;
|
|
|
|
|
|
|
|
|
|
/* This is manually reset. */
|
|
|
|
|
HANDLE have_data_ev;
|
|
|
|
|
/* This is automatically reset. */
|
|
|
|
|
HANDLE have_space_ev;
|
|
|
|
|
/* This is manually reset but actually only triggered once. */
|
|
|
|
|
HANDLE close_ev;
|
|
|
|
|
|
|
|
|
|
size_t readpos, writepos;
|
|
|
|
|
char buffer[READBUF_SIZE];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The context used by a writer thread. */
|
|
|
|
|
struct writer_context_s
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
hddesc_t hdd;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
HANDLE thread_hd;
|
|
|
|
|
int refcount;
|
|
|
|
|
|
|
|
|
|
DECLARE_LOCK (mutex);
|
|
|
|
|
|
|
|
|
|
int stop_me;
|
|
|
|
|
int error;
|
|
|
|
|
int error_code;
|
|
|
|
|
|
|
|
|
|
/* This is manually reset. */
|
|
|
|
|
HANDLE have_data;
|
|
|
|
|
HANDLE is_empty;
|
|
|
|
|
HANDLE close_ev;
|
|
|
|
|
size_t nbytes;
|
|
|
|
|
char buffer[WRITEBUF_SIZE];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
/* An object to keep track of HANDLEs and sockets and map them to an
|
|
|
|
|
* integer similar to what we use in Unix. Note that despite this
|
|
|
|
|
* integer is often named "fd", it is not a file descriptor but really
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* only an index into this table. Never ever pass such an fd to any
|
2018-10-31 13:58:23 +00:00
|
|
|
|
* other function except for those implemented here. */
|
2010-06-10 13:49:19 +00:00
|
|
|
|
static struct
|
|
|
|
|
{
|
|
|
|
|
int used;
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
/* The handle descriptor. */
|
|
|
|
|
hddesc_t hdd;
|
|
|
|
|
|
|
|
|
|
/* DUP_FROM is just a debug helper to show from which fd this fd was
|
|
|
|
|
* dup-ed. */
|
2010-06-10 13:49:19 +00:00
|
|
|
|
int dup_from;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
/* Two flags to indicate whether a reader or writer (or both) are
|
|
|
|
|
* needed. This is so that we can delay the actual thread creation
|
|
|
|
|
* until they are needed. */
|
|
|
|
|
unsigned int want_reader:1;
|
|
|
|
|
unsigned int want_writer:1;
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* The context of an associated reader object or NULL. */
|
|
|
|
|
struct reader_context_s *reader;
|
|
|
|
|
|
|
|
|
|
/* The context of an associated writer object or NULL. */
|
|
|
|
|
struct writer_context_s *writer;
|
|
|
|
|
|
2018-11-08 05:34:27 +00:00
|
|
|
|
/* A notification handler. Noet that we current support only one
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* callback per fd. */
|
|
|
|
|
struct {
|
|
|
|
|
_gpgme_close_notify_handler_t handler;
|
|
|
|
|
void *value;
|
|
|
|
|
} notify;
|
|
|
|
|
|
2012-09-25 13:29:49 +00:00
|
|
|
|
} fd_table[MAX_SLAFD];
|
2018-11-01 08:53:48 +00:00
|
|
|
|
static size_t fd_table_size = MAX_SLAFD;
|
|
|
|
|
|
2016-11-09 07:33:02 +00:00
|
|
|
|
DEFINE_STATIC_LOCK (fd_table_lock);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
/* We use a single global lock for all hddesc_t objects. */
|
|
|
|
|
DEFINE_STATIC_LOCK (hddesc_lock);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-02 11:28:17 +00:00
|
|
|
|
/* Wrapper around CloseHandle to print an error. */
|
|
|
|
|
#define close_handle(hd) _close_handle ((hd), __LINE__);
|
|
|
|
|
static void
|
|
|
|
|
_close_handle (HANDLE hd, int line)
|
|
|
|
|
{
|
|
|
|
|
if (!CloseHandle (hd))
|
|
|
|
|
{
|
|
|
|
|
TRACE2 (DEBUG_INIT, "w32-io", hd, "CloseHandle failed at line %d: ec=%d",
|
|
|
|
|
line, (int) GetLastError ());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wrapper around WaitForSingleObject to print an error. */
|
|
|
|
|
#define wait_for_single_object(hd,msec) \
|
|
|
|
|
_wait_for_single_object ((hd), (msec), __LINE__)
|
|
|
|
|
static DWORD
|
|
|
|
|
_wait_for_single_object (HANDLE hd, DWORD msec, int line)
|
|
|
|
|
{
|
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
|
|
res = WaitForSingleObject (hd, msec);
|
|
|
|
|
if (res == WAIT_FAILED)
|
|
|
|
|
{
|
|
|
|
|
TRACE2 (DEBUG_INIT, "w32-io", hd,
|
|
|
|
|
"WFSO failed at line %d: ec=%d", line, (int) GetLastError ());
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
/* Create a new handle descriptor object. */
|
|
|
|
|
static hddesc_t
|
|
|
|
|
new_hddesc (void)
|
|
|
|
|
{
|
|
|
|
|
hddesc_t hdd;
|
|
|
|
|
|
|
|
|
|
hdd = malloc (sizeof *hdd);
|
|
|
|
|
if (!hdd)
|
|
|
|
|
return NULL;
|
|
|
|
|
hdd->hd = INVALID_HANDLE_VALUE;
|
|
|
|
|
hdd->sock = INVALID_SOCKET;
|
|
|
|
|
hdd->refcount = 0;
|
|
|
|
|
|
|
|
|
|
return hdd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static hddesc_t
|
|
|
|
|
ref_hddesc (hddesc_t hdd)
|
|
|
|
|
{
|
|
|
|
|
LOCK (hddesc_lock);
|
|
|
|
|
hdd->refcount++;
|
|
|
|
|
UNLOCK (hddesc_lock);
|
|
|
|
|
return hdd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Release a handle descriptor object and close its handle or socket
|
|
|
|
|
* if needed. */
|
|
|
|
|
static void
|
|
|
|
|
release_hddesc (hddesc_t hdd)
|
|
|
|
|
{
|
|
|
|
|
if (!hdd)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
LOCK (hddesc_lock);
|
|
|
|
|
hdd->refcount--;
|
|
|
|
|
if (hdd->refcount < 1)
|
|
|
|
|
{
|
2018-11-08 05:34:27 +00:00
|
|
|
|
/* Holds a valid handle or was never initialized (in which case
|
2018-11-02 08:14:07 +00:00
|
|
|
|
* REFCOUNT would be -1 here). */
|
|
|
|
|
TRACE_BEG3 (DEBUG_SYSIO, "gpgme:release_hddesc", hdd,
|
|
|
|
|
"hd=%p, sock=%d, refcount=%d",
|
|
|
|
|
hdd->hd, hdd->sock, hdd->refcount);
|
|
|
|
|
|
|
|
|
|
if (hdd->hd != INVALID_HANDLE_VALUE)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (hdd->hd);
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (hdd->sock != INVALID_SOCKET)
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("closing socket %d", hdd->sock);
|
|
|
|
|
if (closesocket (hdd->sock))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("closesocket failed: ec=%d", (int)WSAGetLastError ());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free (hdd);
|
|
|
|
|
TRACE_SUC ();
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (hddesc_lock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
/* Returns our FD or -1 on resource limit. The returned integer
|
2018-11-08 05:34:27 +00:00
|
|
|
|
* references a new object which has not been initialized but can be
|
2018-10-31 13:58:23 +00:00
|
|
|
|
* release with release_fd. */
|
2018-11-02 08:14:07 +00:00
|
|
|
|
static int
|
2010-06-10 13:49:19 +00:00
|
|
|
|
new_fd (void)
|
|
|
|
|
{
|
|
|
|
|
int idx;
|
|
|
|
|
|
2016-11-09 07:33:02 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
for (idx = 0; idx < fd_table_size; idx++)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
if (! fd_table[idx].used)
|
|
|
|
|
break;
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (idx == fd_table_size)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_err_set_errno (EIO);
|
2016-11-09 07:33:02 +00:00
|
|
|
|
idx = -1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fd_table[idx].used = 1;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd_table[idx].hdd = NULL;
|
2016-11-09 07:33:02 +00:00
|
|
|
|
fd_table[idx].dup_from = -1;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd_table[idx].want_reader = 0;
|
|
|
|
|
fd_table[idx].want_writer = 0;
|
|
|
|
|
fd_table[idx].reader = NULL;
|
|
|
|
|
fd_table[idx].writer = NULL;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
fd_table[idx].notify.handler = NULL;
|
|
|
|
|
fd_table[idx].notify.value = NULL;
|
2010-06-10 13:49:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 07:33:02 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
/* Releases our FD but it this is just this entry. No close operation
|
|
|
|
|
* is involved here; it must be done prior to calling this
|
|
|
|
|
* function. */
|
2018-11-02 08:14:07 +00:00
|
|
|
|
static void
|
2010-06-10 13:49:19 +00:00
|
|
|
|
release_fd (int fd)
|
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (fd < 0 || fd >= fd_table_size)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-11-09 07:33:02 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
|
|
|
|
|
if (fd_table[fd].used)
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (fd_table[fd].hdd);
|
2016-11-09 07:33:02 +00:00
|
|
|
|
fd_table[fd].used = 0;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd_table[fd].hdd = NULL;
|
2016-11-09 07:33:02 +00:00
|
|
|
|
fd_table[fd].dup_from = -1;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd_table[fd].want_reader = 0;
|
|
|
|
|
fd_table[fd].want_writer = 0;
|
|
|
|
|
fd_table[fd].reader = NULL;
|
|
|
|
|
fd_table[fd].writer = NULL;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
fd_table[fd].notify.handler = NULL;
|
|
|
|
|
fd_table[fd].notify.value = NULL;
|
2016-11-09 07:33:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UNLOCK (fd_table_lock);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2006-01-26 10:23:15 +00:00
|
|
|
|
static int
|
|
|
|
|
get_desired_thread_priority (void)
|
|
|
|
|
{
|
|
|
|
|
int value;
|
|
|
|
|
|
|
|
|
|
if (!_gpgme_get_conf_int ("IOThreadPriority", &value))
|
|
|
|
|
{
|
|
|
|
|
value = THREAD_PRIORITY_HIGHEST;
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE1 (DEBUG_SYSIO, "gpgme:get_desired_thread_priority", 0,
|
|
|
|
|
"%d (default)", value);
|
2006-01-26 10:23:15 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
|
|
|
|
TRACE1 (DEBUG_SYSIO, "gpgme:get_desired_thread_priority", 0,
|
|
|
|
|
"%d (configured)", value);
|
|
|
|
|
}
|
2006-01-26 10:23:15 +00:00
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* The reader thread. Created on the fly by gpgme_io_read and
|
|
|
|
|
* destroyed by destroy_reader. Note that this functions works with a
|
|
|
|
|
* copy of the value of the HANDLE variable frm the FS_TABLE. */
|
2012-09-25 13:29:49 +00:00
|
|
|
|
static DWORD CALLBACK
|
2001-01-30 11:01:41 +00:00
|
|
|
|
reader (void *arg)
|
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
struct reader_context_s *ctx = arg;
|
|
|
|
|
int nbytes;
|
|
|
|
|
DWORD nread;
|
2010-04-16 14:08:41 +00:00
|
|
|
|
int sock;
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_BEG4 (DEBUG_SYSIO, "gpgme:reader", ctx->hdd,
|
|
|
|
|
"hd=%p, sock=%d, thread=%p, refcount=%d",
|
|
|
|
|
ctx->hdd->hd, ctx->hdd->sock, ctx->thread_hd, ctx->refcount);
|
|
|
|
|
|
|
|
|
|
if (ctx->hdd->hd != INVALID_HANDLE_VALUE)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
sock = 0;
|
|
|
|
|
else
|
|
|
|
|
sock = 1;
|
2010-04-16 14:08:41 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
/* Leave a 1 byte gap so that we can see whether it is empty or
|
|
|
|
|
full. */
|
|
|
|
|
if ((ctx->writepos + 1) % READBUF_SIZE == ctx->readpos)
|
2012-09-25 13:29:49 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Wait for space. */
|
|
|
|
|
if (!ResetEvent (ctx->have_space_ev))
|
2018-11-02 08:14:07 +00:00
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOG1 ("waiting for space (refcnt=%d)", ctx->refcount);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->have_space_ev, INFINITE);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG ("got space");
|
|
|
|
|
LOCK (ctx->mutex);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->stop_me)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
break;
|
2001-02-20 13:31:56 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
nbytes = (ctx->readpos + READBUF_SIZE
|
|
|
|
|
- ctx->writepos - 1) % READBUF_SIZE;
|
|
|
|
|
if (nbytes > READBUF_SIZE - ctx->writepos)
|
|
|
|
|
nbytes = READBUF_SIZE - ctx->writepos;
|
|
|
|
|
UNLOCK (ctx->mutex);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2010-04-16 14:08:41 +00:00
|
|
|
|
TRACE_LOG2 ("%s %d bytes", sock? "receiving":"reading", nbytes);
|
2010-01-25 16:04:27 +00:00
|
|
|
|
|
2010-06-10 13:49:19 +00:00
|
|
|
|
if (sock)
|
2010-01-25 16:04:27 +00:00
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
n = recv (ctx->hdd->sock, ctx->buffer + ctx->writepos, nbytes, 0);
|
2010-04-16 14:08:41 +00:00
|
|
|
|
if (n < 0)
|
2010-01-25 16:04:27 +00:00
|
|
|
|
{
|
|
|
|
|
ctx->error_code = (int) WSAGetLastError ();
|
|
|
|
|
if (ctx->error_code == ERROR_BROKEN_PIPE)
|
|
|
|
|
{
|
|
|
|
|
ctx->eof = 1;
|
|
|
|
|
TRACE_LOG ("got EOF (broken connection)");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-04-25 11:00:16 +00:00
|
|
|
|
/* Check whether the shutdown triggered the error -
|
|
|
|
|
no need to to print a warning in this case. */
|
|
|
|
|
if ( ctx->error_code == WSAECONNABORTED
|
|
|
|
|
|| ctx->error_code == WSAECONNRESET)
|
|
|
|
|
{
|
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
if (ctx->stop_me)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
TRACE_LOG ("got shutdown");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 16:04:27 +00:00
|
|
|
|
ctx->error = 1;
|
|
|
|
|
TRACE_LOG1 ("recv error: ec=%d", ctx->error_code);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-01-31 12:39:53 +00:00
|
|
|
|
}
|
2010-04-16 14:08:41 +00:00
|
|
|
|
nread = n;
|
2010-01-25 16:04:27 +00:00
|
|
|
|
}
|
2010-04-16 14:08:41 +00:00
|
|
|
|
else
|
2010-01-25 16:04:27 +00:00
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (!ReadFile (ctx->hdd->hd,
|
2010-01-25 16:04:27 +00:00
|
|
|
|
ctx->buffer + ctx->writepos, nbytes, &nread, NULL))
|
|
|
|
|
{
|
|
|
|
|
ctx->error_code = (int) GetLastError ();
|
|
|
|
|
if (ctx->error_code == ERROR_BROKEN_PIPE)
|
|
|
|
|
{
|
|
|
|
|
ctx->eof = 1;
|
|
|
|
|
TRACE_LOG ("got EOF (broken pipe)");
|
|
|
|
|
}
|
2018-11-02 08:14:07 +00:00
|
|
|
|
else if (ctx->error_code == ERROR_OPERATION_ABORTED)
|
|
|
|
|
{
|
|
|
|
|
ctx->eof = 1;
|
|
|
|
|
TRACE_LOG ("got EOF (closed by us)");
|
|
|
|
|
}
|
2010-01-25 16:04:27 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ctx->error = 1;
|
|
|
|
|
TRACE_LOG1 ("read error: ec=%d", ctx->error_code);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-01-31 12:39:53 +00:00
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2010-06-09 13:33:31 +00:00
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
if (ctx->stop_me)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!nread)
|
|
|
|
|
{
|
|
|
|
|
ctx->eof = 1;
|
|
|
|
|
TRACE_LOG ("got eof");
|
2010-06-09 13:33:31 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
break;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOG2 ("got %u bytes (refcnt=%d)", nread, ctx->refcount);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
ctx->writepos = (ctx->writepos + nread) % READBUF_SIZE;
|
|
|
|
|
if (!SetEvent (ctx->have_data_ev))
|
2018-11-02 08:14:07 +00:00
|
|
|
|
{
|
|
|
|
|
TRACE_LOG2 ("SetEvent (0x%x) failed: ec=%d", ctx->have_data_ev,
|
|
|
|
|
(int) GetLastError ());
|
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Indicate that we have an error or EOF. */
|
|
|
|
|
if (!SetEvent (ctx->have_data_ev))
|
2018-11-02 08:14:07 +00:00
|
|
|
|
{
|
|
|
|
|
TRACE_LOG2 ("SetEvent (0x%x) failed: ec=%d", ctx->have_data_ev,
|
2013-04-25 11:00:16 +00:00
|
|
|
|
(int) GetLastError ());
|
2018-11-02 08:14:07 +00:00
|
|
|
|
}
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
|
|
|
|
TRACE_LOG ("waiting for close");
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->close_ev, INFINITE);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (ctx->hdd);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->close_ev);
|
|
|
|
|
close_handle (ctx->have_data_ev);
|
|
|
|
|
close_handle (ctx->have_space_ev);
|
|
|
|
|
close_handle (ctx->thread_hd);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
DESTROY_LOCK (ctx->mutex);
|
|
|
|
|
free (ctx);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SUC ();
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Create a new reader thread and return its context object. The
|
2018-11-02 08:14:07 +00:00
|
|
|
|
* input is the handle descriptor HDD. This function may not call any
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* fd based functions because the caller already holds a lock on the
|
|
|
|
|
* fd_table. */
|
2001-01-30 11:01:41 +00:00
|
|
|
|
static struct reader_context_s *
|
2018-11-02 08:14:07 +00:00
|
|
|
|
create_reader (hddesc_t hdd)
|
2001-01-30 11:01:41 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
struct reader_context_s *ctx;
|
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
DWORD tid;
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_BEG3 (DEBUG_SYSIO, "gpgme:create_reader", hdd,
|
|
|
|
|
"handle=%p sock=%d refhdd=%d",
|
|
|
|
|
hdd->hd, hdd->sock, hdd->refcount);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr);
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
ctx = calloc (1, sizeof *ctx);
|
|
|
|
|
if (!ctx)
|
|
|
|
|
{
|
2018-11-02 11:54:22 +00:00
|
|
|
|
TRACE_SYSERR_NR (errno);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return NULL;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
ctx->hdd = ref_hddesc (hdd);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
ctx->refcount = 1;
|
|
|
|
|
ctx->have_data_ev = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
if (ctx->have_data_ev)
|
|
|
|
|
ctx->have_space_ev = CreateEvent (&sec_attr, FALSE, TRUE, NULL);
|
|
|
|
|
if (ctx->have_space_ev)
|
2013-04-25 11:00:16 +00:00
|
|
|
|
ctx->close_ev = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
if (!ctx->have_data_ev || !ctx->have_space_ev || !ctx->close_ev)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("CreateEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
if (ctx->have_data_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->have_data_ev);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->have_space_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->have_space_ev);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
if (ctx->close_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->close_ev);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (ctx->hdd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
free (ctx);
|
2018-11-02 11:54:22 +00:00
|
|
|
|
TRACE_SYSERR_NR (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INIT_LOCK (ctx->mutex);
|
|
|
|
|
|
|
|
|
|
ctx->thread_hd = CreateThread (&sec_attr, 0, reader, ctx, 0, &tid);
|
2010-11-23 10:47:59 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ctx->thread_hd)
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
DESTROY_LOCK (ctx->mutex);
|
|
|
|
|
if (ctx->have_data_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->have_data_ev);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->have_space_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->have_space_ev);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
if (ctx->close_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->close_ev);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (ctx->hdd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
free (ctx);
|
2018-11-02 11:54:22 +00:00
|
|
|
|
TRACE_SYSERR_NR (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return NULL;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2005-09-23 13:29:04 +00:00
|
|
|
|
/* We set the priority of the thread higher because we know that
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
it only runs for a short time. This greatly helps to
|
|
|
|
|
increase the performance of the I/O. */
|
|
|
|
|
SetThreadPriority (ctx->thread_hd, get_desired_thread_priority ());
|
2005-09-23 13:29:04 +00:00
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_SUC ();
|
|
|
|
|
return ctx;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2013-04-25 11:00:16 +00:00
|
|
|
|
/* Prepare destruction of the reader thread for CTX. Returns 0 if a
|
|
|
|
|
call to this function is sufficient and destroy_reader_finish shall
|
|
|
|
|
not be called. */
|
2001-02-20 13:31:56 +00:00
|
|
|
|
static void
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
destroy_reader (struct reader_context_s *ctx)
|
2001-02-20 13:31:56 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
ctx->refcount--;
|
|
|
|
|
if (ctx->refcount != 0)
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE2 (DEBUG_SYSIO, "gpgme:destroy_reader", ctx,
|
|
|
|
|
"hdd=%p refcount now %d", ctx->hdd, ctx->refcount);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ctx->stop_me = 1;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
if (ctx->have_space_ev)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
SetEvent (ctx->have_space_ev);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE1 (DEBUG_SYSIO, "gpgme:destroy_reader", ctx,
|
|
|
|
|
"hdd=%p close triggered", ctx->hdd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
|
2013-04-25 11:00:16 +00:00
|
|
|
|
/* The reader thread is usually blocking in recv or ReadFile. If
|
|
|
|
|
the peer does not send an EOF or breaks the pipe the WFSO might
|
|
|
|
|
get stuck waiting for the termination of the reader thread. This
|
|
|
|
|
happens quite often with sockets, thus we definitely need to get
|
|
|
|
|
out of the recv. A shutdown does this nicely. For handles
|
|
|
|
|
(i.e. pipes) it would also be nice to cancel the operation, but
|
|
|
|
|
such a feature is only available since Vista. Thus we need to
|
|
|
|
|
dlopen that syscall. */
|
2018-11-02 08:14:07 +00:00
|
|
|
|
assert (ctx->hdd);
|
|
|
|
|
if (ctx->hdd && ctx->hdd->hd != INVALID_HANDLE_VALUE)
|
2013-04-25 11:00:16 +00:00
|
|
|
|
{
|
2018-11-01 08:55:24 +00:00
|
|
|
|
_gpgme_w32_cancel_synchronous_io (ctx->thread_hd);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
}
|
2018-11-02 08:14:07 +00:00
|
|
|
|
else if (ctx->hdd && ctx->hdd->sock != INVALID_SOCKET)
|
2013-04-25 11:00:16 +00:00
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (shutdown (ctx->hdd->sock, 2))
|
|
|
|
|
TRACE2 (DEBUG_SYSIO, "gpgme:destroy_reader", ctx,
|
2013-04-25 11:00:16 +00:00
|
|
|
|
"shutdown socket %d failed: %s",
|
2018-11-02 08:14:07 +00:00
|
|
|
|
ctx->hdd->sock, (int) WSAGetLastError ());
|
2013-04-25 11:00:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 11:00:16 +00:00
|
|
|
|
/* After setting this event CTX is void. */
|
|
|
|
|
SetEvent (ctx->close_ev);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
2007-07-16 17:26:09 +00:00
|
|
|
|
/* Find a reader context or create a new one. Note that the reader
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* context will last until a _gpgme_io_close. NULL is returned for a
|
|
|
|
|
* bad FD or for other errors. */
|
2001-01-30 11:01:41 +00:00
|
|
|
|
static struct reader_context_s *
|
2018-10-31 13:58:23 +00:00
|
|
|
|
find_reader (int fd)
|
2001-01-30 11:01:41 +00:00
|
|
|
|
{
|
2007-07-16 17:26:09 +00:00
|
|
|
|
struct reader_context_s *rd = NULL;
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
TRACE_BEG0 (DEBUG_SYSIO, "gpgme:find_reader", fd, "");
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
if (fd < 0 || fd >= fd_table_size || !fd_table[fd].used)
|
2007-07-16 17:26:09 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
gpg_err_set_errno (EBADF);
|
|
|
|
|
TRACE_SUC0 ("EBADF");
|
|
|
|
|
return NULL;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
rd = fd_table[fd].reader;
|
|
|
|
|
if (rd)
|
2007-07-16 17:26:09 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
TRACE_SUC1 ("rd=%p", rd);
|
|
|
|
|
return rd; /* Return already initialized reader thread object. */
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-16 17:26:09 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Create a new reader thread. */
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOG3 ("fd=%d -> hdd=%p dupfrom=%d creating reader",
|
|
|
|
|
fd, fd_table[fd].hdd, fd_table[fd].dup_from);
|
|
|
|
|
rd = create_reader (fd_table[fd].hdd);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (!rd)
|
|
|
|
|
gpg_err_set_errno (EIO);
|
|
|
|
|
else
|
|
|
|
|
fd_table[fd].reader = rd;
|
|
|
|
|
|
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
TRACE_SUC1 ("rd=%p (new)", rd);
|
2007-07-16 17:26:09 +00:00
|
|
|
|
return rd;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_io_read (int fd, void *buffer, size_t count)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
int nread;
|
|
|
|
|
struct reader_context_s *ctx;
|
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_read", fd,
|
|
|
|
|
"buffer=%p, count=%u", buffer, count);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
ctx = find_reader (fd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ctx)
|
2018-11-01 08:53:48 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->eof_shortcut)
|
|
|
|
|
return TRACE_SYSRES (0);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
if (ctx->readpos == ctx->writepos && !ctx->error)
|
|
|
|
|
{
|
|
|
|
|
/* No data available. */
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
TRACE_LOG1 ("waiting for data from thread %p", ctx->thread_hd);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->have_data_ev, INFINITE);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG1 ("data from thread %p available", ctx->thread_hd);
|
|
|
|
|
LOCK (ctx->mutex);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->readpos == ctx->writepos || ctx->error)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
ctx->eof_shortcut = 1;
|
|
|
|
|
if (ctx->eof)
|
|
|
|
|
return TRACE_SYSRES (0);
|
|
|
|
|
if (!ctx->error)
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG ("EOF but ctx->eof flag not set");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (ctx->error_code);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2001-01-31 12:39:53 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
nread = ctx->readpos < ctx->writepos
|
|
|
|
|
? ctx->writepos - ctx->readpos
|
|
|
|
|
: READBUF_SIZE - ctx->readpos;
|
|
|
|
|
if (nread > count)
|
|
|
|
|
nread = count;
|
|
|
|
|
memcpy (buffer, ctx->buffer + ctx->readpos, nread);
|
|
|
|
|
ctx->readpos = (ctx->readpos + nread) % READBUF_SIZE;
|
|
|
|
|
if (ctx->readpos == ctx->writepos && !ctx->eof)
|
|
|
|
|
{
|
|
|
|
|
if (!ResetEvent (ctx->have_data_ev))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!SetEvent (ctx->have_space_ev))
|
|
|
|
|
{
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
TRACE_LOG2 ("SetEvent (0x%x) failed: ec=%d",
|
|
|
|
|
ctx->have_space_ev, (int) GetLastError ());
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOGBUFX (buffer, nread);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (nread);
|
|
|
|
|
}
|
2001-01-30 11:01:41 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* The writer does use a simple buffering strategy so that we are
|
|
|
|
|
informed about write errors as soon as possible (i. e. with the the
|
|
|
|
|
next call to the write function. */
|
2012-09-25 13:29:49 +00:00
|
|
|
|
static DWORD CALLBACK
|
2001-02-28 10:18:38 +00:00
|
|
|
|
writer (void *arg)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
struct writer_context_s *ctx = arg;
|
|
|
|
|
DWORD nwritten;
|
2010-04-16 14:08:41 +00:00
|
|
|
|
int sock;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_BEG4 (DEBUG_SYSIO, "gpgme:writer", ctx->hdd,
|
|
|
|
|
"hd=%p, sock=%d, thread=%p, refcount=%d",
|
|
|
|
|
ctx->hdd->hd, ctx->hdd->sock, ctx->thread_hd, ctx->refcount);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (ctx->hdd->hd != INVALID_HANDLE_VALUE)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
sock = 0;
|
|
|
|
|
else
|
|
|
|
|
sock = 1;
|
2010-04-16 14:08:41 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
LOCK (ctx->mutex);
|
2017-01-23 14:08:23 +00:00
|
|
|
|
if (ctx->stop_me && !ctx->nbytes)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
break;
|
2006-02-15 13:30:08 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ctx->nbytes)
|
2012-09-25 13:29:49 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!SetEvent (ctx->is_empty))
|
|
|
|
|
TRACE_LOG1 ("SetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
if (!ResetEvent (ctx->have_data))
|
|
|
|
|
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
TRACE_LOG ("idle");
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->have_data, INFINITE);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG ("got data to send");
|
|
|
|
|
LOCK (ctx->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2017-01-23 14:08:23 +00:00
|
|
|
|
if (ctx->stop_me && !ctx->nbytes)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
break;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2010-04-16 14:08:41 +00:00
|
|
|
|
TRACE_LOG2 ("%s %d bytes", sock?"sending":"writing", ctx->nbytes);
|
|
|
|
|
|
2007-08-22 17:29:41 +00:00
|
|
|
|
/* Note that CTX->nbytes is not zero at this point, because
|
|
|
|
|
_gpgme_io_write always writes at least 1 byte before waking
|
|
|
|
|
us up, unless CTX->stop_me is true, which we catch above. */
|
2010-06-10 13:49:19 +00:00
|
|
|
|
if (sock)
|
2010-01-25 16:04:27 +00:00
|
|
|
|
{
|
|
|
|
|
/* We need to try send first because a socket handle can't
|
|
|
|
|
be used with WriteFile. */
|
|
|
|
|
int n;
|
2010-06-09 13:33:31 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
n = send (ctx->hdd->sock, ctx->buffer, ctx->nbytes, 0);
|
2010-04-16 14:08:41 +00:00
|
|
|
|
if (n < 0)
|
2010-01-25 16:04:27 +00:00
|
|
|
|
{
|
|
|
|
|
ctx->error_code = (int) WSAGetLastError ();
|
|
|
|
|
ctx->error = 1;
|
|
|
|
|
TRACE_LOG1 ("send error: ec=%d", ctx->error_code);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-04-16 14:08:41 +00:00
|
|
|
|
nwritten = n;
|
2010-01-25 16:04:27 +00:00
|
|
|
|
}
|
2010-04-16 14:08:41 +00:00
|
|
|
|
else
|
2010-01-25 16:04:27 +00:00
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (!WriteFile (ctx->hdd->hd, ctx->buffer,
|
2010-01-25 16:04:27 +00:00
|
|
|
|
ctx->nbytes, &nwritten, NULL))
|
|
|
|
|
{
|
2010-06-09 13:33:31 +00:00
|
|
|
|
if (GetLastError () == ERROR_BUSY)
|
|
|
|
|
{
|
|
|
|
|
/* Probably stop_me is set now. */
|
|
|
|
|
TRACE_LOG ("pipe busy (unblocked?)");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 16:04:27 +00:00
|
|
|
|
ctx->error_code = (int) GetLastError ();
|
|
|
|
|
ctx->error = 1;
|
|
|
|
|
TRACE_LOG1 ("write error: ec=%d", ctx->error_code);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-08-22 17:29:41 +00:00
|
|
|
|
TRACE_LOG1 ("wrote %d bytes", (int) nwritten);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-08-22 17:29:41 +00:00
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
ctx->nbytes -= nwritten;
|
|
|
|
|
UNLOCK (ctx->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Indicate that we have an error. */
|
|
|
|
|
if (!SetEvent (ctx->is_empty))
|
|
|
|
|
TRACE_LOG1 ("SetEvent failed: ec=%d", (int) GetLastError ());
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
|
|
|
|
TRACE_LOG ("waiting for close");
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->close_ev, INFINITE);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
2017-01-23 14:08:23 +00:00
|
|
|
|
if (ctx->nbytes)
|
|
|
|
|
TRACE_LOG1 ("still %d bytes in buffer at close time", ctx->nbytes);
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (ctx->hdd);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->close_ev);
|
|
|
|
|
close_handle (ctx->have_data);
|
|
|
|
|
close_handle (ctx->is_empty);
|
|
|
|
|
close_handle (ctx->thread_hd);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
DESTROY_LOCK (ctx->mutex);
|
|
|
|
|
free (ctx);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SUC ();
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct writer_context_s *
|
2018-11-02 08:14:07 +00:00
|
|
|
|
create_writer (hddesc_t hdd)
|
2001-02-28 10:18:38 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
struct writer_context_s *ctx;
|
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
DWORD tid;
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
|
|
|
|
|
TRACE_BEG3 (DEBUG_SYSIO, "gpgme:create_writer", hdd,
|
|
|
|
|
"handle=%p sock=%d refhdd=%d",
|
|
|
|
|
hdd->hd, hdd->sock, hdd->refcount);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr);
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
|
|
|
|
|
|
|
|
|
ctx = calloc (1, sizeof *ctx);
|
|
|
|
|
if (!ctx)
|
|
|
|
|
{
|
2018-11-02 11:54:22 +00:00
|
|
|
|
TRACE_SYSERR_NR (errno);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return NULL;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
ctx->hdd = ref_hddesc (hdd);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
ctx->refcount = 1;
|
|
|
|
|
ctx->have_data = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
if (ctx->have_data)
|
|
|
|
|
ctx->is_empty = CreateEvent (&sec_attr, TRUE, TRUE, NULL);
|
|
|
|
|
if (ctx->is_empty)
|
2013-04-25 11:00:16 +00:00
|
|
|
|
ctx->close_ev = CreateEvent (&sec_attr, TRUE, FALSE, NULL);
|
|
|
|
|
if (!ctx->have_data || !ctx->is_empty || !ctx->close_ev)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("CreateEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
if (ctx->have_data)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->have_data);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->is_empty)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->is_empty);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
if (ctx->close_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->close_ev);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (ctx->hdd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
free (ctx);
|
2018-11-02 11:54:22 +00:00
|
|
|
|
TRACE_SYSERR_NR (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INIT_LOCK (ctx->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
ctx->thread_hd = CreateThread (&sec_attr, 0, writer, ctx, 0, &tid );
|
|
|
|
|
if (!ctx->thread_hd)
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("CreateThread failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
DESTROY_LOCK (ctx->mutex);
|
|
|
|
|
if (ctx->have_data)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->have_data);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->is_empty)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->is_empty);
|
2013-04-25 11:00:16 +00:00
|
|
|
|
if (ctx->close_ev)
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (ctx->close_ev);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (ctx->hdd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
free (ctx);
|
2018-11-02 11:54:22 +00:00
|
|
|
|
TRACE_SYSERR_NR (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return NULL;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* We set the priority of the thread higher because we know
|
|
|
|
|
that it only runs for a short time. This greatly helps to
|
|
|
|
|
increase the performance of the I/O. */
|
|
|
|
|
SetThreadPriority (ctx->thread_hd, get_desired_thread_priority ());
|
2005-09-23 13:29:04 +00:00
|
|
|
|
}
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_SUC ();
|
|
|
|
|
return ctx;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 11:00:16 +00:00
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
static void
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
destroy_writer (struct writer_context_s *ctx)
|
2001-02-28 10:18:38 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
ctx->refcount--;
|
|
|
|
|
if (ctx->refcount != 0)
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE2 (DEBUG_SYSIO, "gpgme:destroy_writer", ctx,
|
|
|
|
|
"hdd=%p refcount now %d", ctx->hdd, ctx->refcount);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
ctx->stop_me = 1;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
if (ctx->have_data)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
SetEvent (ctx->have_data);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE1 (DEBUG_SYSIO, "gpgme:destroy_writer", ctx,
|
|
|
|
|
"hdd=%p close triggered", ctx->hdd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
UNLOCK (ctx->mutex);
|
2010-06-09 13:33:31 +00:00
|
|
|
|
|
2017-01-23 14:08:23 +00:00
|
|
|
|
/* Give the writer a chance to flush the buffer. */
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->is_empty, INFINITE);
|
2017-01-23 14:08:23 +00:00
|
|
|
|
|
2013-04-25 11:00:16 +00:00
|
|
|
|
/* After setting this event CTX is void. */
|
|
|
|
|
SetEvent (ctx->close_ev);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Find a writer context or create a new one. Note that the writer
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* context will last until a _gpgme_io_close. NULL is returned for a
|
|
|
|
|
* bad FD or for other errors. */
|
2001-02-28 10:18:38 +00:00
|
|
|
|
static struct writer_context_s *
|
2018-10-31 13:58:23 +00:00
|
|
|
|
find_writer (int fd)
|
2001-02-28 10:18:38 +00:00
|
|
|
|
{
|
2007-07-16 17:26:09 +00:00
|
|
|
|
struct writer_context_s *wt = NULL;
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
TRACE_BEG0 (DEBUG_SYSIO, "gpgme:find_writer", fd, "");
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
if (fd < 0 || fd >= fd_table_size || !fd_table[fd].used)
|
2007-07-16 17:26:09 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
gpg_err_set_errno (EBADF);
|
|
|
|
|
TRACE_SUC0 ("EBADF");
|
|
|
|
|
return NULL;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
wt = fd_table[fd].writer;
|
|
|
|
|
if (wt)
|
2007-07-16 17:26:09 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
TRACE_SUC1 ("wt=%p", wt);
|
|
|
|
|
return wt; /* Return already initialized writer thread object. */
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2007-07-16 17:26:09 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Create a new writer thread. */
|
|
|
|
|
TRACE_LOG4 ("fd=%d -> handle=%p socket=%d dupfrom=%d creating writer",
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd, fd_table[fd].hdd->hd, fd_table[fd].hdd->sock,
|
2018-11-01 08:53:48 +00:00
|
|
|
|
fd_table[fd].dup_from);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
wt = create_writer (fd_table[fd].hdd);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (!wt)
|
|
|
|
|
gpg_err_set_errno (EIO);
|
|
|
|
|
else
|
|
|
|
|
fd_table[fd].writer = wt;
|
|
|
|
|
|
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
TRACE_SUC1 ("wt=%p (new)", wt);
|
2007-07-16 17:26:09 +00:00
|
|
|
|
return wt;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_io_write (int fd, const void *buffer, size_t count)
|
2001-02-28 10:18:38 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
struct writer_context_s *ctx;
|
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_write", fd,
|
|
|
|
|
"buffer=%p, count=%u", buffer, count);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOGBUFX (buffer, count);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2007-08-22 17:29:41 +00:00
|
|
|
|
if (count == 0)
|
2007-09-07 19:38:50 +00:00
|
|
|
|
return TRACE_SYSRES (0);
|
2007-08-22 17:29:41 +00:00
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
ctx = find_writer (fd);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ctx)
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
|
|
|
|
|
LOCK (ctx->mutex);
|
|
|
|
|
if (!ctx->error && ctx->nbytes)
|
|
|
|
|
{
|
|
|
|
|
/* Bytes are pending for send. */
|
|
|
|
|
|
|
|
|
|
/* Reset the is_empty event. Better safe than sorry. */
|
|
|
|
|
if (!ResetEvent (ctx->is_empty))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
TRACE_LOG1 ("waiting for empty buffer in thread %p", ctx->thread_hd);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
wait_for_single_object (ctx->is_empty, INFINITE);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG1 ("thread %p buffer is empty", ctx->thread_hd);
|
|
|
|
|
LOCK (ctx->mutex);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (ctx->error)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (ctx->mutex);
|
2007-08-02 14:59:01 +00:00
|
|
|
|
if (ctx->error_code == ERROR_NO_DATA)
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EPIPE);
|
2007-08-02 14:59:01 +00:00
|
|
|
|
else
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2015-12-02 10:28:07 +00:00
|
|
|
|
/* If no error occurred, the number of bytes in the buffer must be
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
zero. */
|
|
|
|
|
assert (!ctx->nbytes);
|
|
|
|
|
|
|
|
|
|
if (count > WRITEBUF_SIZE)
|
|
|
|
|
count = WRITEBUF_SIZE;
|
|
|
|
|
memcpy (ctx->buffer, buffer, count);
|
|
|
|
|
ctx->nbytes = count;
|
|
|
|
|
|
|
|
|
|
/* We have to reset the is_empty event early, because it is also
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* used by the select() implementation to probe the channel. */
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ResetEvent (ctx->is_empty))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("ResetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!SetEvent (ctx->have_data))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("SetEvent failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
UNLOCK (ctx->mutex);
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
UNLOCK (ctx->mutex);
|
2006-02-15 13:30:08 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES ((int) count);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-02-28 10:18:38 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_io_pipe (int filedes[2], int inherit_idx)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2010-06-10 13:49:19 +00:00
|
|
|
|
int rfd;
|
|
|
|
|
int wfd;
|
|
|
|
|
HANDLE rh;
|
|
|
|
|
HANDLE wh;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
hddesc_t rhdesc;
|
|
|
|
|
hddesc_t whdesc;
|
2010-06-10 13:49:19 +00:00
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
2010-06-09 13:33:31 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_pipe", filedes,
|
|
|
|
|
"inherit_idx=%i (GPGME uses it for %s)",
|
2007-09-27 11:44:45 +00:00
|
|
|
|
inherit_idx, inherit_idx ? "reading" : "writing");
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
/* Get a new empty file descriptor. */
|
2010-06-10 13:49:19 +00:00
|
|
|
|
rfd = new_fd ();
|
|
|
|
|
if (rfd == -1)
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
wfd = new_fd ();
|
|
|
|
|
if (wfd == -1)
|
|
|
|
|
{
|
|
|
|
|
release_fd (rfd);
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2018-11-02 08:14:07 +00:00
|
|
|
|
rhdesc = new_hddesc ();
|
|
|
|
|
if (!rhdesc)
|
|
|
|
|
{
|
|
|
|
|
release_fd (rfd);
|
|
|
|
|
release_fd (wfd);
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
whdesc = new_hddesc ();
|
|
|
|
|
if (!whdesc)
|
|
|
|
|
{
|
|
|
|
|
release_fd (rfd);
|
|
|
|
|
release_fd (wfd);
|
|
|
|
|
release_hddesc (rhdesc);
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
2018-10-31 13:58:23 +00:00
|
|
|
|
/* Create a pipe. */
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
memset (&sec_attr, 0, sizeof (sec_attr));
|
|
|
|
|
sec_attr.nLength = sizeof (sec_attr);
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!CreatePipe (&rh, &wh, &sec_attr, PIPEBUF_SIZE))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("CreatePipe failed: ec=%d", (int) GetLastError ());
|
2010-06-10 13:49:19 +00:00
|
|
|
|
release_fd (rfd);
|
|
|
|
|
release_fd (wfd);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (rhdesc);
|
|
|
|
|
release_hddesc (whdesc);
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2000-12-06 12:17:10 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Make one end inheritable. */
|
|
|
|
|
if (inherit_idx == 0)
|
|
|
|
|
{
|
|
|
|
|
HANDLE hd;
|
|
|
|
|
if (!DuplicateHandle (GetCurrentProcess(), rh,
|
|
|
|
|
GetCurrentProcess(), &hd, 0,
|
|
|
|
|
TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("DuplicateHandle failed: ec=%d",
|
|
|
|
|
(int) GetLastError ());
|
2010-06-10 13:49:19 +00:00
|
|
|
|
release_fd (rfd);
|
|
|
|
|
release_fd (wfd);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (rh);
|
|
|
|
|
close_handle (wh);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (rhdesc);
|
|
|
|
|
release_hddesc (whdesc);
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (rh);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
rh = hd;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
else if (inherit_idx == 1)
|
|
|
|
|
{
|
|
|
|
|
HANDLE hd;
|
|
|
|
|
if (!DuplicateHandle( GetCurrentProcess(), wh,
|
|
|
|
|
GetCurrentProcess(), &hd, 0,
|
|
|
|
|
TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("DuplicateHandle failed: ec=%d",
|
|
|
|
|
(int) GetLastError ());
|
2010-06-10 13:49:19 +00:00
|
|
|
|
release_fd (rfd);
|
|
|
|
|
release_fd (wfd);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (rh);
|
|
|
|
|
close_handle (wh);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
release_hddesc (rhdesc);
|
|
|
|
|
release_hddesc (whdesc);
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (wh);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
wh = hd;
|
2010-06-09 13:33:31 +00:00
|
|
|
|
}
|
2018-10-31 13:58:23 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Put the HANDLEs of the new pipe into the file descriptor table.
|
|
|
|
|
* Note that we don't need to lock the table because we have just
|
|
|
|
|
* acquired these two fresh fds and they are not known by any other
|
|
|
|
|
* thread. */
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd_table[rfd].want_reader = 1;
|
|
|
|
|
ref_hddesc (rhdesc)->hd = rh;
|
|
|
|
|
fd_table[rfd].hdd = rhdesc;
|
|
|
|
|
|
|
|
|
|
fd_table[wfd].want_writer = 1;
|
|
|
|
|
ref_hddesc (whdesc)->hd = wh;
|
|
|
|
|
fd_table[wfd].hdd = whdesc;
|
2009-06-18 13:41:48 +00:00
|
|
|
|
|
2010-06-10 13:49:19 +00:00
|
|
|
|
filedes[0] = rfd;
|
|
|
|
|
filedes[1] = wfd;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
return TRACE_SUC6 ("read=0x%x (hdd=%p,hd=%p), write=0x%x (hdd=%p,hd=%p)",
|
|
|
|
|
rfd, fd_table[rfd].hdd, fd_table[rfd].hdd->hd,
|
|
|
|
|
wfd, fd_table[wfd].hdd, fd_table[wfd].hdd->hd);
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Close out File descriptor FD. */
|
2000-11-23 15:28:15 +00:00
|
|
|
|
int
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_io_close (int fd)
|
2000-11-23 15:28:15 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_close_notify_handler_t handler = NULL;
|
|
|
|
|
void *value = NULL;
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_close", fd);
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (fd < 0)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EBADF);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2018-11-01 08:53:48 +00:00
|
|
|
|
|
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
/* Check the size in the locked state because we may eventually add
|
|
|
|
|
* code to change that size. */
|
|
|
|
|
if (fd >= fd_table_size || !fd_table[fd].used)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
gpg_err_set_errno (EBADF);
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2010-06-09 13:33:31 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOG2 ("hdd=%p dupfrom=%d", fd_table[fd].hdd, fd_table[fd].dup_from);
|
2013-05-06 18:23:47 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (fd_table[fd].reader)
|
2013-04-25 11:00:16 +00:00
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOG1 ("destroying reader %p", fd_table[fd].reader);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
destroy_reader (fd_table[fd].reader);
|
|
|
|
|
fd_table[fd].reader = NULL;
|
2013-04-25 11:00:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
if (fd_table[fd].writer)
|
2013-04-25 11:00:16 +00:00
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_LOG1 ("destroying writer %p", fd_table[fd].writer);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
destroy_writer (fd_table[fd].writer);
|
|
|
|
|
fd_table[fd].writer = NULL;
|
2013-04-25 11:00:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 05:34:27 +00:00
|
|
|
|
/* The handler may not use any fd function because the table is
|
2018-11-02 11:54:22 +00:00
|
|
|
|
* locked. Can we avoid this? */
|
2018-11-01 08:53:48 +00:00
|
|
|
|
handler = fd_table[fd].notify.handler;
|
|
|
|
|
value = fd_table[fd].notify.value;
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2018-11-08 05:34:27 +00:00
|
|
|
|
/* Release our reference to the handle descriptor. Note that if no
|
2018-11-02 08:14:07 +00:00
|
|
|
|
* reader or writer threads were used this release will also take
|
|
|
|
|
* care that the handle descriptor is closed
|
|
|
|
|
* (i.e. CloseHandle(hdd->hd) is called). */
|
|
|
|
|
release_hddesc (fd_table[fd].hdd);
|
|
|
|
|
fd_table[fd].hdd = NULL;
|
2000-12-06 12:17:10 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
|
|
|
|
|
/* Run the notification callback. */
|
|
|
|
|
if (handler)
|
|
|
|
|
handler (fd, value);
|
|
|
|
|
|
|
|
|
|
release_fd (fd); /* FIXME: We should have a release_fd_locked () */
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (0);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Set a close notification callback which is called right after FD
|
2018-11-08 05:34:27 +00:00
|
|
|
|
* has been closed but before its slot (ie. the FD number) is being
|
|
|
|
|
* released. The HANDLER may thus use the provided value of the FD
|
2018-11-01 08:53:48 +00:00
|
|
|
|
* but it may not pass it to any I/O functions. Note: Only the last
|
|
|
|
|
* handler set for an FD is used. */
|
2001-02-20 13:31:56 +00:00
|
|
|
|
int
|
2007-07-13 00:43:17 +00:00
|
|
|
|
_gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler,
|
|
|
|
|
void *value)
|
2001-02-20 13:31:56 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_set_close_notify", fd,
|
|
|
|
|
"close_handler=%p/%p", handler, value);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
if (fd < 0 || fd >= fd_table_size || !fd_table[fd].used)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
gpg_err_set_errno (EBADF);
|
|
|
|
|
return TRACE_SYSRES (-1);;
|
2001-02-20 13:31:56 +00:00
|
|
|
|
}
|
2018-11-01 08:53:48 +00:00
|
|
|
|
|
|
|
|
|
fd_table[fd].notify.handler = handler;
|
|
|
|
|
fd_table[fd].notify.value = value;
|
|
|
|
|
UNLOCK (fd_table_lock);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (0);
|
2001-02-20 13:31:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_io_set_nonblocking (int fd)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE (DEBUG_SYSIO, "_gpgme_io_set_nonblocking", fd);
|
|
|
|
|
return 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
static char *
|
2007-01-17 19:35:06 +00:00
|
|
|
|
build_commandline (char **argv)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-01-17 19:35:06 +00:00
|
|
|
|
int i;
|
|
|
|
|
int n = 0;
|
|
|
|
|
char *buf;
|
|
|
|
|
char *p;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-01-17 19:35:06 +00:00
|
|
|
|
/* We have to quote some things because under Windows the program
|
|
|
|
|
parses the commandline and does some unquoting. We enclose the
|
|
|
|
|
whole argument in double-quotes, and escape literal double-quotes
|
|
|
|
|
as well as backslashes with a backslash. We end up with a
|
|
|
|
|
trailing space at the end of the line, but that is harmless. */
|
|
|
|
|
for (i = 0; argv[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
p = argv[i];
|
|
|
|
|
/* The leading double-quote. */
|
|
|
|
|
n++;
|
|
|
|
|
while (*p)
|
|
|
|
|
{
|
|
|
|
|
/* An extra one for each literal that must be escaped. */
|
|
|
|
|
if (*p == '\\' || *p == '"')
|
|
|
|
|
n++;
|
|
|
|
|
n++;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
/* The trailing double-quote and the delimiter. */
|
|
|
|
|
n += 2;
|
|
|
|
|
}
|
|
|
|
|
/* And a trailing zero. */
|
|
|
|
|
n++;
|
|
|
|
|
|
2005-09-13 14:17:04 +00:00
|
|
|
|
buf = p = malloc (n);
|
2007-01-17 19:35:06 +00:00
|
|
|
|
if (!buf)
|
2005-09-13 14:17:04 +00:00
|
|
|
|
return NULL;
|
2007-01-17 19:35:06 +00:00
|
|
|
|
for (i = 0; argv[i]; i++)
|
2005-09-13 14:17:04 +00:00
|
|
|
|
{
|
2007-01-17 19:35:06 +00:00
|
|
|
|
char *argvp = argv[i];
|
|
|
|
|
|
|
|
|
|
*(p++) = '"';
|
|
|
|
|
while (*argvp)
|
|
|
|
|
{
|
2007-01-26 12:08:12 +00:00
|
|
|
|
if (*argvp == '\\' || *argvp == '"')
|
2007-01-17 19:35:06 +00:00
|
|
|
|
*(p++) = '\\';
|
|
|
|
|
*(p++) = *(argvp++);
|
|
|
|
|
}
|
|
|
|
|
*(p++) = '"';
|
|
|
|
|
*(p++) = ' ';
|
2001-07-31 15:21:58 +00:00
|
|
|
|
}
|
2007-01-17 19:35:06 +00:00
|
|
|
|
*(p++) = 0;
|
|
|
|
|
|
2005-09-13 14:17:04 +00:00
|
|
|
|
return buf;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
int
|
2009-06-12 16:58:45 +00:00
|
|
|
|
_gpgme_io_spawn (const char *path, char *const argv[], unsigned int flags,
|
2009-11-10 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Activate UIServer if FD passing is enabled and
Assuan is available.
m4/
2009-11-10 Marcus Brinkmann <marcus@g10code.de>
* libassuan.m4: Fix LIBASSUAN_VERSION.
src/
2009-11-10 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (uiserver_components): New variable.
(main_sources): Add it.
* ops.h, key.c (_gpgme_key_append_name): Take CONVERT argument,
implement it. Adjust callers.
(gpgme_key_from_uid): New function.
* gpgme.h.in (gpgme_protocol_t): Add GPGME_PROTOCOL_DEFAULT.
(gpgme_encrypt_flags_t): Add GPGME_ENCRYPT_PREPARE,
GPGME_ENCRYPT_EXPECT_SIGN.
(gpgme_set_sub_protocol, gpgme_key_from_uid): New functions.
* libgpgme.vers, gpgme.def: Add new functions.
* gpgme.c (gpgme_set_protocol): Add UIServer protocol.
(gpgme_set_sub_protocol): New function.
(gpgme_get_protocol_name): Add UIServer and default protocol.
* assuan-support.c: Return correct error values, implement
socketpair for POSIX.
* priv-io.h, posix-io.c, w32-io.c, w32-glib-io.c,
w32-qt-io.cpp (_gpgme_io_spawn): Add ATFORK and ATFORKVALUE
arguments. Implement it for POSIX. Adjust all callers.
* engine.h, engine-backend.h (_gpgme_engine_set_protocol)
(_gpgme_engine_op_decrypt_verify): New prototypes. Adjust all
users.
* engine.c (engine_ops, gpgme_get_engine_info): Add UIServer
engine.
(_gpgme_engine_set_protocol, _gpgme_engine_op_decrypt_verify): New
function.
* decrypt-verify.c (decrypt_verify_start): Call
_gpgme_engine_op_decrypt_verify.
* util.h, posix-util.c,
w32-util.c (_gpgme_get_uiserver_socket_path): New function.
* engine-gpgsm.c (gpgsm_set_fd): Fix _gpgme_io_pipe invocation.
* gpgme-tool.c: Some support for UIServer protocol.
* engine-uiserver.c: New file.
2009-11-10 09:07:19 +00:00
|
|
|
|
struct spawn_fd_item_s *fd_list,
|
|
|
|
|
void (*atfork) (void *opaque, int reserved),
|
|
|
|
|
void *atforkvalue, pid_t *r_pid)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
PROCESS_INFORMATION pi =
|
|
|
|
|
{
|
|
|
|
|
NULL, /* returns process handle */
|
|
|
|
|
0, /* returns primary thread handle */
|
|
|
|
|
0, /* returns pid */
|
2008-02-14 19:51:21 +00:00
|
|
|
|
0 /* returns tid */
|
2000-11-22 17:10:48 +00:00
|
|
|
|
};
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
int i;
|
2010-06-09 13:33:31 +00:00
|
|
|
|
|
|
|
|
|
SECURITY_ATTRIBUTES sec_attr;
|
|
|
|
|
STARTUPINFOA si;
|
|
|
|
|
int cr_flags = CREATE_DEFAULT_ERROR_MODE;
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
char **args;
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
char *arg_string;
|
|
|
|
|
/* FIXME. */
|
|
|
|
|
int debug_me = 0;
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
int tmp_fd;
|
|
|
|
|
char *tmp_name;
|
2015-10-28 15:27:49 +00:00
|
|
|
|
const char *spawnhelper;
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_BEG1 (DEBUG_SYSIO, "_gpgme_io_spawn", path,
|
|
|
|
|
"path=%s", path);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
|
|
|
|
|
(void)atfork;
|
|
|
|
|
(void)atforkvalue;
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
while (argv[i])
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG2 ("argv[%2i] = %s", i, argv[i]);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
/* We do not inherit any handles by default, and just insert those
|
|
|
|
|
handles we want the child to have afterwards. But some handle
|
|
|
|
|
values occur on the command line, and we need to move
|
|
|
|
|
stdin/out/err to the right location. So we use a wrapper program
|
|
|
|
|
which gets the information from a temporary file. */
|
|
|
|
|
if (_gpgme_mkstemp (&tmp_fd, &tmp_name) < 0)
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("_gpgme_mkstemp failed: %s", strerror (errno));
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
TRACE_LOG1 ("tmp_name = %s", tmp_name);
|
|
|
|
|
|
|
|
|
|
args = calloc (2 + i + 1, sizeof (*args));
|
|
|
|
|
args[0] = (char *) _gpgme_get_w32spawn_path ();
|
|
|
|
|
args[1] = tmp_name;
|
2013-05-06 18:23:47 +00:00
|
|
|
|
args[2] = (char *)path;
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
memcpy (&args[3], &argv[1], i * sizeof (*args));
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
memset (&sec_attr, 0, sizeof sec_attr);
|
|
|
|
|
sec_attr.nLength = sizeof sec_attr;
|
|
|
|
|
sec_attr.bInheritHandle = FALSE;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
arg_string = build_commandline (args);
|
|
|
|
|
free (args);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!arg_string)
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
{
|
|
|
|
|
close (tmp_fd);
|
2010-06-09 13:33:31 +00:00
|
|
|
|
DeleteFileA (tmp_name);
|
2018-10-29 18:44:02 +00:00
|
|
|
|
free (tmp_name);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
memset (&si, 0, sizeof si);
|
|
|
|
|
si.cb = sizeof (si);
|
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
|
|
|
|
|
si.wShowWindow = debug_me ? SW_SHOW : SW_HIDE;
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
si.hStdInput = INVALID_HANDLE_VALUE;
|
|
|
|
|
si.hStdOutput = INVALID_HANDLE_VALUE;
|
|
|
|
|
si.hStdError = INVALID_HANDLE_VALUE;
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2011-02-02 13:07:05 +00:00
|
|
|
|
cr_flags |= CREATE_SUSPENDED;
|
2014-04-10 09:39:14 +00:00
|
|
|
|
if ((flags & IOSPAWN_FLAG_DETACHED))
|
|
|
|
|
cr_flags |= DETACHED_PROCESS;
|
2010-06-09 13:33:31 +00:00
|
|
|
|
cr_flags |= GetPriorityClass (GetCurrentProcess ());
|
2015-10-28 15:27:49 +00:00
|
|
|
|
spawnhelper = _gpgme_get_w32spawn_path ();
|
2016-08-18 14:56:58 +00:00
|
|
|
|
if (!spawnhelper)
|
|
|
|
|
{
|
|
|
|
|
/* This is a common mistake for new users of gpgme not to include
|
|
|
|
|
gpgme-w32spawn.exe with their binary. So we want to make
|
|
|
|
|
this transparent to developers. If users have somehow messed
|
|
|
|
|
up their installation this should also be properly communicated
|
|
|
|
|
as otherwise calls to gnupg will result in unsupported protocol
|
|
|
|
|
errors that do not explain a lot. */
|
|
|
|
|
char *msg;
|
|
|
|
|
gpgrt_asprintf (&msg, "gpgme-w32spawn.exe was not found in the "
|
|
|
|
|
"detected installation directory of GpgME"
|
|
|
|
|
"\n\t\"%s\"\n\n"
|
|
|
|
|
"Crypto operations will not work.\n\n"
|
|
|
|
|
"If you see this it indicates a problem "
|
|
|
|
|
"with your installation.\n"
|
|
|
|
|
"Please report the problem to your "
|
|
|
|
|
"distributor of GpgME.\n\n"
|
2017-02-02 11:35:59 +00:00
|
|
|
|
"Developer's Note: The install dir can be "
|
2016-08-18 14:56:58 +00:00
|
|
|
|
"manually set with: gpgme_set_global_flag",
|
|
|
|
|
_gpgme_get_inst_dir ());
|
|
|
|
|
MessageBoxA (NULL, msg, "GpgME not installed correctly", MB_OK);
|
2017-02-02 11:35:59 +00:00
|
|
|
|
gpgrt_free (msg);
|
2016-08-18 14:56:58 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2018-10-29 18:44:02 +00:00
|
|
|
|
close (tmp_fd);
|
|
|
|
|
DeleteFileA (tmp_name);
|
|
|
|
|
free (tmp_name);
|
2016-08-18 14:56:58 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2015-10-28 15:27:49 +00:00
|
|
|
|
if (!CreateProcessA (spawnhelper,
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
arg_string,
|
|
|
|
|
&sec_attr, /* process security attributes */
|
|
|
|
|
&sec_attr, /* thread security attributes */
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
FALSE, /* inherit handles */
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
cr_flags, /* creation flags */
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
NULL, /* environment */
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
NULL, /* use current drive/directory */
|
|
|
|
|
&si, /* startup information */
|
|
|
|
|
&pi)) /* returns process information */
|
|
|
|
|
{
|
2015-10-28 15:27:49 +00:00
|
|
|
|
int lasterr = (int)GetLastError ();
|
|
|
|
|
TRACE_LOG1 ("CreateProcess failed: ec=%d", lasterr);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
free (arg_string);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
close (tmp_fd);
|
2010-06-09 13:33:31 +00:00
|
|
|
|
DeleteFileA (tmp_name);
|
2018-10-29 18:44:02 +00:00
|
|
|
|
free (tmp_name);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-12 16:58:45 +00:00
|
|
|
|
if (flags & IOSPAWN_FLAG_ALLOW_SET_FG)
|
|
|
|
|
_gpgme_allow_set_foreground_window ((pid_t)pi.dwProcessId);
|
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
/* Insert the inherited handles. */
|
2018-11-01 08:53:48 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
2011-02-02 13:07:05 +00:00
|
|
|
|
int fd = fd_list[i].fd;
|
|
|
|
|
HANDLE ohd = INVALID_HANDLE_VALUE;
|
|
|
|
|
HANDLE hd = INVALID_HANDLE_VALUE;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
/* Make it inheritable for the wrapper process. */
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (fd >= 0 && fd < fd_table_size && fd_table[fd].used
|
|
|
|
|
&& fd_table[fd].hdd)
|
|
|
|
|
ohd = fd_table[fd].hdd->hd;
|
2011-02-02 13:07:05 +00:00
|
|
|
|
|
|
|
|
|
if (!DuplicateHandle (GetCurrentProcess(), ohd,
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
pi.hProcess, &hd, 0, TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("DuplicateHandle failed: ec=%d", (int) GetLastError ());
|
|
|
|
|
TerminateProcess (pi.hProcess, 0);
|
|
|
|
|
/* Just in case TerminateProcess didn't work, let the
|
|
|
|
|
process fail on its own. */
|
|
|
|
|
ResumeThread (pi.hThread);
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (pi.hThread);
|
|
|
|
|
close_handle (pi.hProcess);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
|
|
|
|
close (tmp_fd);
|
2010-06-09 13:33:31 +00:00
|
|
|
|
DeleteFileA (tmp_name);
|
2018-10-29 18:44:02 +00:00
|
|
|
|
free (tmp_name);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
/* Return the child name of this handle. */
|
|
|
|
|
fd_list[i].peer_name = handle_to_fd (hd);
|
2000-12-06 12:17:10 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
/* Write the handle translation information to the temporary
|
|
|
|
|
file. */
|
|
|
|
|
{
|
|
|
|
|
/* Hold roughly MAX_TRANS quadruplets of 64 bit numbers in hex
|
|
|
|
|
notation: "0xFEDCBA9876543210" with an extra white space after
|
|
|
|
|
every quadruplet. 10*(19*4 + 1) - 1 = 769. This plans ahead
|
|
|
|
|
for a time when a HANDLE is 64 bit. */
|
2009-06-12 16:58:45 +00:00
|
|
|
|
#define BUFFER_MAX 810
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
char line[BUFFER_MAX + 1];
|
|
|
|
|
int res;
|
|
|
|
|
int written;
|
|
|
|
|
size_t len;
|
|
|
|
|
|
2018-02-09 15:04:54 +00:00
|
|
|
|
if (flags)
|
|
|
|
|
snprintf (line, BUFFER_MAX, "~%i \n", flags);
|
2009-06-12 16:58:45 +00:00
|
|
|
|
else
|
|
|
|
|
strcpy (line, "\n");
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
|
|
|
|
{
|
|
|
|
|
/* Strip the newline. */
|
|
|
|
|
len = strlen (line) - 1;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
/* Format is: Local name, stdin/stdout/stderr, peer name, argv idx. */
|
|
|
|
|
snprintf (&line[len], BUFFER_MAX - len, "0x%x %d 0x%x %d \n",
|
|
|
|
|
fd_list[i].fd, fd_list[i].dup_to,
|
|
|
|
|
fd_list[i].peer_name, fd_list[i].arg_loc);
|
|
|
|
|
/* Rather safe than sorry. */
|
|
|
|
|
line[BUFFER_MAX - 1] = '\n';
|
|
|
|
|
line[BUFFER_MAX] = '\0';
|
|
|
|
|
}
|
|
|
|
|
len = strlen (line);
|
|
|
|
|
written = 0;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
res = write (tmp_fd, &line[written], len - written);
|
|
|
|
|
if (res > 0)
|
|
|
|
|
written += res;
|
|
|
|
|
}
|
|
|
|
|
while (res > 0 || (res < 0 && errno == EAGAIN));
|
|
|
|
|
}
|
|
|
|
|
close (tmp_fd);
|
|
|
|
|
/* The temporary file is deleted by the gpgme-w32spawn process
|
|
|
|
|
(hopefully). */
|
2010-06-09 13:33:31 +00:00
|
|
|
|
|
2018-10-30 10:19:33 +00:00
|
|
|
|
free (tmp_name);
|
|
|
|
|
free (arg_string);
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG4 ("CreateProcess ready: hProcess=%p, hThread=%p, "
|
|
|
|
|
"dwProcessID=%d, dwThreadId=%d",
|
2012-09-25 13:29:49 +00:00
|
|
|
|
pi.hProcess, pi.hThread,
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
(int) pi.dwProcessId, (int) pi.dwThreadId);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2008-02-14 19:51:21 +00:00
|
|
|
|
if (r_pid)
|
|
|
|
|
*r_pid = (pid_t)pi.dwProcessId;
|
2009-06-12 16:58:45 +00:00
|
|
|
|
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-02 11:54:22 +00:00
|
|
|
|
if (ResumeThread (pi.hThread) == (DWORD)(-1))
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG1 ("ResumeThread failed: ec=%d", (int) GetLastError ());
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (pi.hThread);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
TRACE_LOG1 ("process=%p", pi.hProcess);
|
|
|
|
|
|
|
|
|
|
/* We don't need to wait for the process. */
|
2018-11-02 11:28:17 +00:00
|
|
|
|
close_handle (pi.hProcess);
|
2007-09-27 13:01:54 +00:00
|
|
|
|
|
2009-11-05 02:39:31 +00:00
|
|
|
|
if (! (flags & IOSPAWN_FLAG_NOCLOSE))
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
|
|
|
|
_gpgme_io_close (fd_list[i].fd);
|
|
|
|
|
}
|
assuan/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members.
(HANDLE_TRANSLATION): New macro.
(pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn.
[HANDLE_TRANSLATION]: Return translated handles.
gpgme/
2008-06-25 Marcus Brinkmann <marcus@g10code.de>
* gpgme-w32spawn.c: New file.
* Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable
with gpgme-w32spawn.
* engine-gpgsm.c (gpgsm_new): Use server translated handles.
(gpgsm_set_locale): Return early if locale value is NULL.
* util.h (_gpgme_mkstemp)
(_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function
prototypes.
* w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>.
(letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New
functions.
* rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign)
(gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over
special filename FD rather than stdin.
(struct arg_and_data_s): Add member ARG_LOCP.
(struct fd_data_map_s): Add member ARG_LOC.
(struct engine_gpg): Add member ARG_LOC to status and colon.
(_add_arg, add_arg_with_locp): New function.
(add_arg_ext): Reimplement in terms of _add_arg.
(gpg_new): Remember argument location for status FD.
(build_argv): Set argument location if requested. Also set
argument location of fd_data_map for data items.
(start): Adjust caller of _gpgme_io_spawn.
* priv-io.h (struct spawn_fd_item_s): Add members peer_name and
arg_loc.
(_gpgme_io_spawn): Remove parent fd list argument.
* posix-io.c (get_max_fds): New function.
(_gpgme_io_dup): Add tracing.
(_gpgme_io_spawn): Remove parent fd list. Change meaning of child
fd list to contain all child fds that should be inherited. Close
all other file descriptors after fork.
* w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove
parent fd list. Change meaning of child fd list to contain all
child fds that should be inherited. Do not inherit any file
descriptors, but DuplicateHandle them. Spawn process through
wrapper process. Provide wrapper process with a temporary file
containing handle translation data. Return translated handle
names.
* w32-io.c (reader): Add more tracing output.
(_gpgme_io_read): Likewise.
* engine-gpgconf.c (gpgconf_read): Adjust caller of
_gpgme_io_spawn.
* version.c (_gpgme_get_program_version): Likewise.
2008-06-25 16:52:31 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
|
|
|
|
if (fd_list[i].dup_to == -1)
|
|
|
|
|
TRACE_LOG3 ("fd[%i] = 0x%x -> 0x%x", i, fd_list[i].fd,
|
|
|
|
|
fd_list[i].peer_name);
|
|
|
|
|
else
|
|
|
|
|
TRACE_LOG4 ("fd[%i] = 0x%x -> 0x%x (std%s)", i, fd_list[i].fd,
|
|
|
|
|
fd_list[i].peer_name, (fd_list[i].dup_to == 0) ? "in" :
|
|
|
|
|
((fd_list[i].dup_to == 1) ? "out" : "err"));
|
2007-09-27 13:01:54 +00:00
|
|
|
|
|
|
|
|
|
return TRACE_SYSRES (0);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Select on the list of fds. Returns: -1 = error, 0 = timeout or
|
|
|
|
|
nothing to select, > 0 = number of signaled fds. */
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
_gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
HANDLE waitbuf[MAXIMUM_WAIT_OBJECTS];
|
|
|
|
|
int waitidx[MAXIMUM_WAIT_OBJECTS];
|
|
|
|
|
int code;
|
|
|
|
|
int nwait;
|
|
|
|
|
int i;
|
|
|
|
|
int any;
|
|
|
|
|
int count;
|
|
|
|
|
void *dbg_help;
|
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_select", fds,
|
|
|
|
|
"nfds=%u, nonblock=%u", nfds, nonblock);
|
2000-11-23 15:28:15 +00:00
|
|
|
|
|
2013-05-06 18:23:47 +00:00
|
|
|
|
#if 0
|
2000-12-06 12:17:10 +00:00
|
|
|
|
restart:
|
2013-05-06 18:23:47 +00:00
|
|
|
|
#endif
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_SEQ (dbg_help, "select on [ ");
|
|
|
|
|
any = 0;
|
|
|
|
|
nwait = 0;
|
|
|
|
|
count = 0;
|
|
|
|
|
for (i=0; i < nfds; i++)
|
|
|
|
|
{
|
|
|
|
|
if (fds[i].fd == -1)
|
|
|
|
|
continue;
|
|
|
|
|
fds[i].signaled = 0;
|
|
|
|
|
if (fds[i].for_read || fds[i].for_write)
|
|
|
|
|
{
|
2007-09-28 16:23:53 +00:00
|
|
|
|
if (fds[i].for_read)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* FIXME: A find_reader_locked() along with separate
|
|
|
|
|
* lock calls might be a better appaoched here. */
|
2018-10-31 13:58:23 +00:00
|
|
|
|
struct reader_context_s *ctx = find_reader (fds[i].fd);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ctx)
|
|
|
|
|
TRACE_LOG1 ("error: no reader for FD 0x%x (ignored)",
|
|
|
|
|
fds[i].fd);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (nwait >= DIM (waitbuf))
|
|
|
|
|
{
|
|
|
|
|
TRACE_END (dbg_help, "oops ]");
|
|
|
|
|
TRACE_LOG ("Too many objects for WFMO!");
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
waitidx[nwait] = i;
|
|
|
|
|
waitbuf[nwait++] = ctx->have_data_ev;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_ADD1 (dbg_help, "r0x%x ", fds[i].fd);
|
|
|
|
|
any = 1;
|
2001-02-20 13:31:56 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
else if (fds[i].for_write)
|
|
|
|
|
{
|
2018-10-31 13:58:23 +00:00
|
|
|
|
struct writer_context_s *ctx = find_writer (fds[i].fd);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (!ctx)
|
|
|
|
|
TRACE_LOG1 ("error: no writer for FD 0x%x (ignored)",
|
|
|
|
|
fds[i].fd);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (nwait >= DIM (waitbuf))
|
|
|
|
|
{
|
|
|
|
|
TRACE_END (dbg_help, "oops ]");
|
|
|
|
|
TRACE_LOG ("Too many objects for WFMO!");
|
|
|
|
|
/* FIXME: Should translate the error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
waitidx[nwait] = i;
|
|
|
|
|
waitbuf[nwait++] = ctx->is_empty;
|
2001-02-28 10:18:38 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_ADD1 (dbg_help, "w0x%x ", fds[i].fd);
|
|
|
|
|
any = 1;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_END (dbg_help, "]");
|
2012-09-25 13:29:49 +00:00
|
|
|
|
if (!any)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (0);
|
|
|
|
|
|
|
|
|
|
code = WaitForMultipleObjects (nwait, waitbuf, 0, nonblock ? 0 : 1000);
|
2018-11-02 11:54:22 +00:00
|
|
|
|
if (code < WAIT_OBJECT_0 + nwait)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* The WFMO is a really silly function: It does return either
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
the index of the signaled object or if 2 objects have been
|
|
|
|
|
signalled at the same time, the index of the object with the
|
|
|
|
|
lowest object is returned - so and how do we find out how
|
2018-11-01 08:53:48 +00:00
|
|
|
|
many objects have been signaled?. The only solution I can
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
imagine is to test each object starting with the returned
|
|
|
|
|
index individually - how dull. */
|
|
|
|
|
any = 0;
|
|
|
|
|
for (i = code - WAIT_OBJECT_0; i < nwait; i++)
|
|
|
|
|
{
|
2018-11-02 11:28:17 +00:00
|
|
|
|
if (wait_for_single_object (waitbuf[i], 0) == WAIT_OBJECT_0)
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
{
|
|
|
|
|
assert (waitidx[i] >=0 && waitidx[i] < nfds);
|
|
|
|
|
fds[waitidx[i]].signaled = 1;
|
|
|
|
|
any = 1;
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!any)
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG ("no signaled objects found after WFMO");
|
|
|
|
|
count = -1;
|
|
|
|
|
}
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
else if (code == WAIT_TIMEOUT)
|
|
|
|
|
TRACE_LOG ("WFMO timed out");
|
|
|
|
|
else if (code == WAIT_FAILED)
|
|
|
|
|
{
|
|
|
|
|
int le = (int) GetLastError ();
|
2010-06-10 13:49:19 +00:00
|
|
|
|
#if 0
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (le == ERROR_INVALID_HANDLE)
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
|
int j = handle_to_fd (waitbuf[i]);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG1 ("WFMO invalid handle %d removed", j);
|
|
|
|
|
for (k = 0 ; k < nfds; k++)
|
|
|
|
|
{
|
|
|
|
|
if (fds[k].fd == j)
|
|
|
|
|
{
|
|
|
|
|
fds[k].for_read = fds[k].for_write = 0;
|
|
|
|
|
goto restart;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG (" oops, or not???");
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2010-06-10 13:49:19 +00:00
|
|
|
|
#endif
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_LOG1 ("WFMO failed: %d", le);
|
|
|
|
|
count = -1;
|
2001-01-30 11:01:41 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TRACE_LOG1 ("WFMO returned %d", code);
|
|
|
|
|
count = -1;
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
if (count > 0)
|
|
|
|
|
{
|
|
|
|
|
TRACE_SEQ (dbg_help, "select OK [ ");
|
|
|
|
|
for (i = 0; i < nfds; i++)
|
|
|
|
|
{
|
|
|
|
|
if (fds[i].fd == -1)
|
|
|
|
|
continue;
|
|
|
|
|
if ((fds[i].for_read || fds[i].for_write) && fds[i].signaled)
|
|
|
|
|
TRACE_ADD2 (dbg_help, "%c0x%x ",
|
|
|
|
|
fds[i].for_read ? 'r' : 'w', fds[i].fd);
|
2001-01-31 12:39:53 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_END (dbg_help, "]");
|
2001-01-31 12:39:53 +00:00
|
|
|
|
}
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
|
|
|
|
if (count < 0)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: Should determine a proper error code. */
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (EIO);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (count);
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
2005-03-09 11:47:21 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2005-03-09 11:47:21 +00:00
|
|
|
|
void
|
|
|
|
|
_gpgme_io_subsystem_init (void)
|
|
|
|
|
{
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
/* Nothing to do. */
|
2005-03-09 11:47:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-18 14:00:50 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
/* Write the printable version of FD to BUFFER which has an allocated
|
|
|
|
|
* length of BUFLEN. The printable version is the representation on
|
|
|
|
|
* the command line that the child process expects. Note that this
|
|
|
|
|
* works closely together with the gpgme-32spawn wrapper process which
|
|
|
|
|
* translates these command line args to the real handles. */
|
2005-11-18 14:00:50 +00:00
|
|
|
|
int
|
2018-11-01 08:53:48 +00:00
|
|
|
|
_gpgme_io_fd2str (char *buffer, int buflen, int fd)
|
2005-11-18 14:00:50 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
return snprintf (buffer, buflen, "%d", fd);
|
2005-11-18 14:00:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-07-16 17:26:09 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_dup (int fd)
|
|
|
|
|
{
|
2010-06-10 13:49:19 +00:00
|
|
|
|
int newfd;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
struct reader_context_s *rd_ctx;
|
|
|
|
|
struct writer_context_s *wt_ctx;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
int want_reader, want_writer;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_dup", fd);
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
|
|
|
|
if (fd < 0 || fd >= fd_table_size || !fd_table[fd].used)
|
2007-07-16 17:26:09 +00:00
|
|
|
|
{
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
gpg_err_set_errno (EBADF);
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
2007-07-16 17:26:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 13:49:19 +00:00
|
|
|
|
newfd = new_fd();
|
|
|
|
|
if (newfd == -1)
|
2018-11-01 08:53:48 +00:00
|
|
|
|
{
|
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
gpg_err_set_errno (EMFILE);
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
fd_table[newfd].hdd = ref_hddesc (fd_table[fd].hdd);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
fd_table[newfd].dup_from = fd;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
want_reader = fd_table[fd].want_reader;
|
|
|
|
|
want_writer = fd_table[fd].want_writer;
|
2010-06-10 13:49:19 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
rd_ctx = want_reader? find_reader (fd) : NULL;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
if (rd_ctx)
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
/* NEWFD initializes a freshly allocated slot and does not need
|
|
|
|
|
* to be locked. */
|
|
|
|
|
LOCK (rd_ctx->mutex);
|
2007-07-16 17:26:09 +00:00
|
|
|
|
rd_ctx->refcount++;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
UNLOCK (rd_ctx->mutex);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
fd_table[newfd].reader = rd_ctx;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
wt_ctx = want_writer? find_writer (fd) : NULL;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
if (wt_ctx)
|
|
|
|
|
{
|
2018-11-02 08:14:07 +00:00
|
|
|
|
LOCK (wt_ctx->mutex);
|
2007-07-16 17:26:09 +00:00
|
|
|
|
wt_ctx->refcount++;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
UNLOCK (wt_ctx->mutex);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
fd_table[newfd].writer = wt_ctx;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 13:49:19 +00:00
|
|
|
|
return TRACE_SYSRES (newfd);
|
2007-07-16 17:26:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-11-17 18:45:14 +00:00
|
|
|
|
|
2007-09-06 22:41:11 +00:00
|
|
|
|
/* The following interface is only useful for GPGME Glib and Qt. */
|
2005-11-17 18:45:14 +00:00
|
|
|
|
|
2007-09-06 22:41:11 +00:00
|
|
|
|
/* Compatibility interface, obsolete. */
|
2005-11-17 18:45:14 +00:00
|
|
|
|
void *
|
|
|
|
|
gpgme_get_giochannel (int fd)
|
|
|
|
|
{
|
2018-10-31 13:58:23 +00:00
|
|
|
|
(void)fd;
|
2005-11-17 18:45:14 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2005-03-09 11:47:21 +00:00
|
|
|
|
|
2007-07-17 Marcus Brinkmann <marcus@g10code.de>
* debug.c:;5B Include <errno.h> and "debug.h".
(_gpgme_debug): Save and restore ERRNO.
(TOHEX): New macro.
(_gpgme_debug_buffer): New function.
* conversion.c, data-compat.c, data-mem.c, data.c, engine-gpgsm.c,
gpgme.c, keylist.c, posix-io.c, rungpg.c, sign.c, version.c,
w32-io.c, wait.c: Replace DEBUG macros by TRACE_* variants. In
most of these files, add many more tracepoints.
2007-07-17 12:36:04 +00:00
|
|
|
|
|
2007-09-06 22:41:11 +00:00
|
|
|
|
/* Look up the giochannel or qiodevice for file descriptor FD. */
|
|
|
|
|
void *
|
|
|
|
|
gpgme_get_fdptr (int fd)
|
|
|
|
|
{
|
2018-10-31 13:58:23 +00:00
|
|
|
|
(void)fd;
|
2007-09-06 22:41:11 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
wsa2errno (int err)
|
|
|
|
|
{
|
|
|
|
|
switch (err)
|
|
|
|
|
{
|
|
|
|
|
case WSAENOTSOCK:
|
|
|
|
|
return EINVAL;
|
|
|
|
|
case WSAEWOULDBLOCK:
|
|
|
|
|
return EAGAIN;
|
|
|
|
|
case ERROR_BROKEN_PIPE:
|
|
|
|
|
return EPIPE;
|
|
|
|
|
case WSANOTINITIALISED:
|
|
|
|
|
return ENOSYS;
|
|
|
|
|
default:
|
|
|
|
|
return EIO;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_socket (int domain, int type, int proto)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
2010-06-10 13:49:19 +00:00
|
|
|
|
int fd;
|
2018-11-02 08:14:07 +00:00
|
|
|
|
hddesc_t hdd;
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
|
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_socket", domain,
|
|
|
|
|
"type=%i, protp=%i", type, proto);
|
|
|
|
|
|
2010-06-10 13:49:19 +00:00
|
|
|
|
fd = new_fd();
|
|
|
|
|
if (fd == -1)
|
|
|
|
|
return TRACE_SYSRES (-1);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
hdd = new_hddesc ();
|
|
|
|
|
if (!hdd)
|
|
|
|
|
{
|
|
|
|
|
UNLOCK (fd_table_lock);
|
|
|
|
|
release_fd (fd);
|
|
|
|
|
gpg_err_set_errno (ENOMEM);
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
res = socket (domain, type, proto);
|
|
|
|
|
if (res == INVALID_SOCKET)
|
|
|
|
|
{
|
2010-06-10 13:49:19 +00:00
|
|
|
|
release_fd (fd);
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (wsa2errno (WSAGetLastError ()));
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2018-11-02 08:14:07 +00:00
|
|
|
|
ref_hddesc (hdd)->sock = res;
|
|
|
|
|
fd_table[fd].hdd = hdd;
|
|
|
|
|
fd_table[fd].want_reader = 1;
|
|
|
|
|
fd_table[fd].want_writer = 1;
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
|
2018-11-02 08:14:07 +00:00
|
|
|
|
TRACE_SUC3 ("hdd=%p, socket=0x%x (0x%x)", hdd, fd, hdd->sock);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2011-02-03 11:38:28 +00:00
|
|
|
|
return fd;
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_connect (int fd, struct sockaddr *addr, int addrlen)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
int sock;
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
|
|
|
|
|
TRACE_BEG2 (DEBUG_SYSIO, "_gpgme_io_connect", fd,
|
|
|
|
|
"addr=%p, addrlen=%i", addr, addrlen);
|
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
LOCK (fd_table_lock);
|
2018-11-02 08:14:07 +00:00
|
|
|
|
if (fd < 0 || fd >= fd_table_size || !fd_table[fd].used || !fd_table[fd].hdd)
|
2010-06-10 13:49:19 +00:00
|
|
|
|
{
|
|
|
|
|
gpg_err_set_errno (EBADF);
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
2010-06-10 13:49:19 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2018-11-02 08:14:07 +00:00
|
|
|
|
sock = fd_table[fd].hdd->sock;
|
2018-11-01 08:53:48 +00:00
|
|
|
|
UNLOCK (fd_table_lock);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-01 08:53:48 +00:00
|
|
|
|
res = connect (sock, addr, addrlen);
|
2010-01-25 16:04:27 +00:00
|
|
|
|
if (res)
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
{
|
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Require libgpg-error 1.8.
src/
2010-05-06 Marcus Brinkmann <marcus@g10code.de>
* sign.c, data-user.c, conversion.c, debug.c, verify.c, data.c,
decrypt.c, delete.c, assuan-support.c, import.c, engine-gpgsm.c,
data-mem.c, op-support.c, w32-io.c, w32-util.c, data-compat.c: Use
gpg_error_from_syserror instead gpg_error_from_errno, and use
gpg_err_set_errno to set error number.
* setenv.c: Include <gpg-error.h> and define __set_errno to use
gpg_err_set_errno.
* gpgme-tool.c (ARGP_ERR_UNKNOWN): Define to EDEADLOCK (which is
mapped in Windows CE) instead of E2BIG (which is not).
(gt_import_keys): Initialize err.
2010-05-06 13:39:55 +00:00
|
|
|
|
gpg_err_set_errno (wsa2errno (WSAGetLastError ()));
|
assuan/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* assuan.h (_gpgme_io_socket): New prototype.
(_ASSUAN_CUSTOM_IO, _assuan_custom_close, _assuan_custom_read)
(_assuan_custom_write, _assuan_custom_pipe, _assuan_custom_socket)
(_assuan_custom_connect): New macros.
* assuan-socket.c (_assuan_close, _assuan_sock_new)
(_assuan_sock_connect) [_ASSUAN_CUSTOM_IO]: Use custom I/O function.
* assuan-buffer.c (assuan_read_line): Do not handle EAGAIN anymore.
* assuan-client.c (_assuan_read_from_server): Likewise.
* assuan-handler.c (process_next): Likewise
* assuan-inquire.c (assuan_inquire): Likewise.
src/
2009-04-08 Marcus Brinkmann <marcus@g10code.de>
* w32-glib-io.c (giochannel_table): New members used, fd, socket.
(find_channel): Drop CREATE argument.
(new_dummy_channel_from_fd, new_channel_from_fd)
(new_channel_from_socket): New functions.
(_gpgm_io_fd2str): Implement for sockets.
(_gpgme_io_write, _gpgme_io_read): Translate EAGAIN errors
correctly.
(_gpgme_io_pipe): Fix for new channel bookkeeping.
(_gpgme_io_close, _gpgme_io_dup): Likewise.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-io.c (MAX_READERS, MAX_WRITERS): Bump up to 40.
(wsa2errno, _gpgme_io_socket, _gpgme_io_connect): New.
* w32-qt-io.cpp (_gpgme_io_socket, _gpgme_io_connect): New stubs.
* version.c [HAVE_W32_SYSTEM]: Include "windows.h.
(do_subsystem_inits) [HAVE_W32_SYSTEM]: Call WSAStartup.
* engine-assuan.c (llass_status_handler): Ignore EAGAIN errors.
2009-04-08 18:53:57 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRACE_SUC ();
|
|
|
|
|
}
|