2000-11-22 17:10:48 +00:00
|
|
|
|
/* posix-io.c - Posix I/O functions
|
2018-11-16 12:27:33 +00:00
|
|
|
|
* Copyright (C) 2000 Werner Koch (dd9jn)
|
|
|
|
|
* Copyright (C) 2001, 2002, 2004, 2005, 2007, 2010 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-or-later
|
2010-02-17 21:40:02 +00:00
|
|
|
|
*/
|
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>
|
2016-01-15 15:16:38 +00:00
|
|
|
|
#ifdef HAVE_STDINT_H
|
|
|
|
|
# include <stdint.h>
|
|
|
|
|
#endif
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <fcntl.h>
|
2010-11-02 16:27:46 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
#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
|
2000-11-22 17:10:48 +00:00
|
|
|
|
#include <sys/wait.h>
|
2008-10-20 15:59:19 +00:00
|
|
|
|
#ifdef HAVE_SYS_UIO_H
|
|
|
|
|
# include <sys/uio.h>
|
|
|
|
|
#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
|
|
|
|
#include <ctype.h>
|
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
|
|
|
|
#include <sys/resource.h>
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2017-10-04 16:03:54 +00:00
|
|
|
|
#ifdef USE_LINUX_GETDENTS
|
2017-09-16 03:16:45 +00:00
|
|
|
|
# include <sys/syscall.h>
|
2016-05-27 20:19:35 +00:00
|
|
|
|
# include <sys/types.h>
|
|
|
|
|
# include <dirent.h>
|
2017-10-04 16:03:54 +00:00
|
|
|
|
#endif /*USE_LINUX_GETDENTS*/
|
2016-05-27 20:19:35 +00:00
|
|
|
|
|
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
|
#include "util.h"
|
2005-03-24 13:05:12 +00:00
|
|
|
|
#include "priv-io.h"
|
2002-05-09 03:38:12 +00:00
|
|
|
|
#include "sema.h"
|
2002-06-02 20:43:04 +00:00
|
|
|
|
#include "ath.h"
|
2003-01-30 Marcus Brinkmann <marcus@g10code.de>
* engine-gpgsm.c (status_handler): Do not close status fd at end
of function.
* ops.h (_gpgme_op_data_lookup): Add prototype.
* op-support.c: Include <stdlib.h>.
(_gpgme_op_data_lookup): New function.
* decrypt.c (_gpgme_release_decrypt_result): Function removed.
(struct decrypt_result_s): Rename to ...
(struct decrypt_resul): ... this.
(DecryptResult): New type.
(_gpgme_decrypt_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
* sign.c (_gpgme_release_sign_result): Function removed.
(release_sign_result): New function.
(struct sign_result_s): Rename to ...
(struct sign_result): ... this.
(SignResult): New type.
(_gpgme_sign_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
* encrypt.c (struct encrypt_result_s): Rename to ...
(struct encrypt_result): ... this.
(_gpgme_release_encrypt_result): Function removed.
(release_encrypt_result): New function.
(_gpgme_encrypt_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
* verify.c (struct verify_result_s): Rename to ...
(struct verify_result): ... this. Remove member next.
(VerifyResult): New type.
(_gpgme_release_verify_result): Function removed.
(release_verify_result): New function.
(finish_sig): Change first argument to type VerifyResult. Diddle
the type of the op_data structure.
(add_notation): Change first argument to type VerifyResult.
(_gpgme_verify_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
* passphrase.c (struct passphrase_result_s): Rename to ...
(struct passphrase_result): ... this. Remove member next.
(PassphraseResult): New type.
(_gpgme_release_passphrase_result): Function removed.
(release_passphrase_result): New function.
(_gpgme_passphrase_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
(_gpgme_passphrase_command_handler): Likewise.
* keylist.c (struct keylist_result_s): Rename to ...
(struct keylist_result): ... this. Remove member next.
(KeylistResult): New type.
(_gpgme_release_keylist_result): Function removed.
(release_keylist_result): New function.
(keylist_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
* edit.c (struct edit_result_s): Rename to ...
(struct edit_result): ... this. Remove member next.
(EditResult): New type.
(_gpgme_release_edit_result): Function removed.
(release_edit_result): New function.
(edit_status_handler): Don't use
test_and_allocate_result, but use _gpgme_op_data_lookup to
retrieve result data object.
(command_handler): Likewise.
* types.h (DecryptResult, SignResult, EncryptResult,
PassphraseResult, ImportResult, DeleteResult, GenKeyResult,
KeylistResult, EditResult): Types removed.
* ops.h: Don't include "types.h", but "gpgme.h" and "context.h".
(test_and_allocate_result): Remove macro.
(_gpgme_release_decrypt_result): Remove prototype.
(_gpgme_decrypt_result): Remove prototype.
(_gpgme_release_sign_result): Remove prototype.
(_gpgme_release_encrypt_result): Remove prototype.
(_gpgme_release_passphrase_result): Remove prototype.
(_gpgme_release_import_result): Remove prototype.
(_gpgme_release_delete_result): Remove prototype.
(_gpgme_release_genkey_result): Remove prototype.
(_gpgme_release_keylist_result): Remove prototype.
(_gpgme_release_edit_result): Remove prototype.
(_gpgme_release_verify_result): Remove prototype.
* gpgme.c (_gpgme_release_result): Rewritten.
* context.h (enum ctx_op_data_type): New enum.
(struct ctx_op_data): New structure.
(struct gpgme_context_s): Replace the member result with a member
op_data.
(fail_on_pending_request): Remove macro.
* op-support.c (_gpgme_op_reset): Expand macro
fail_on_pending_request.
* util.h: Don't include "types.h" or "debug.h", but include "gpgme.h".
2003-01-30 22:40:05 +00:00
|
|
|
|
#include "debug.h"
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2017-10-04 16:03:54 +00:00
|
|
|
|
|
2019-06-06 16:55:57 +00:00
|
|
|
|
#ifdef USE_LINUX_GETDENTS
|
|
|
|
|
/* This is not declared in public headers; getdents64(2) says that we must
|
|
|
|
|
* define it ourselves. */
|
|
|
|
|
struct linux_dirent64
|
|
|
|
|
{
|
|
|
|
|
ino64_t d_ino;
|
|
|
|
|
off64_t d_off;
|
|
|
|
|
unsigned short d_reclen;
|
|
|
|
|
unsigned char d_type;
|
|
|
|
|
char d_name[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
# define DIR_BUF_SIZE 1024
|
|
|
|
|
#endif /*USE_LINUX_GETDENTS*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return true if FD is valid file descriptor. */
|
|
|
|
|
#if 0
|
|
|
|
|
int
|
|
|
|
|
_gpgme_is_fd_valid (int fd)
|
|
|
|
|
{
|
|
|
|
|
int dir_fd;
|
|
|
|
|
char dir_buf[DIR_BUF_SIZE];
|
|
|
|
|
struct linux_dirent64 *dir_entry;
|
|
|
|
|
int r, pos, x;
|
|
|
|
|
const char *s;
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
dir_fd = open ("/proc/self/fd", O_RDONLY | O_DIRECTORY);
|
|
|
|
|
if (dir_fd != -1)
|
|
|
|
|
{
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
|
|
|
|
r = syscall(SYS_getdents64, dir_fd, dir_buf, DIR_BUF_SIZE);
|
|
|
|
|
if (r == -1)
|
|
|
|
|
break; /* Ooops */
|
|
|
|
|
if (r == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
for (pos = 0; pos < r; pos += dir_entry->d_reclen)
|
|
|
|
|
{
|
|
|
|
|
dir_entry = (struct linux_dirent64 *) (dir_buf + pos);
|
|
|
|
|
s = dir_entry->d_name;
|
|
|
|
|
if (*s < '0' || *s > '9')
|
|
|
|
|
continue;
|
|
|
|
|
/* atoi is not guaranteed to be async-signal-safe. */
|
|
|
|
|
for (x = 0; *s >= '0' && *s <= '9'; s++)
|
|
|
|
|
x = x * 10 + (*s - '0');
|
|
|
|
|
if (*s)
|
|
|
|
|
continue; /* Does not look like a file descriptor. */
|
|
|
|
|
if (x == fd)
|
|
|
|
|
{
|
|
|
|
|
result = 1;
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
leave:
|
|
|
|
|
close (dir_fd);
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
#endif /*0*/
|
|
|
|
|
|
2003-10-06 16:17:13 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
_gpgme_io_subsystem_init (void)
|
|
|
|
|
{
|
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
|
|
sigaction (SIGPIPE, NULL, &act);
|
|
|
|
|
if (act.sa_handler == SIG_DFL)
|
|
|
|
|
{
|
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
|
sigemptyset (&act.sa_mask);
|
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
sigaction (SIGPIPE, &act, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-18 14:00:50 +00:00
|
|
|
|
|
|
|
|
|
/* Write the printable version of FD to the buffer BUF of length
|
|
|
|
|
BUFLEN. The printable version is the representation on the command
|
|
|
|
|
line that the child process expects. */
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_fd2str (char *buf, int buflen, int fd)
|
|
|
|
|
{
|
|
|
|
|
return snprintf (buf, buflen, "%d", fd);
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-06 16:17:13 +00:00
|
|
|
|
|
2010-02-17 21:40:02 +00:00
|
|
|
|
/* The table to hold notification handlers. We use a linear search
|
|
|
|
|
and extend the table as needed. */
|
|
|
|
|
struct notify_table_item_s
|
2002-03-18 00:04:06 +00:00
|
|
|
|
{
|
2010-02-17 21:40:02 +00:00
|
|
|
|
int fd; /* -1 indicates an unused entry. */
|
2007-07-13 00:43:17 +00:00
|
|
|
|
_gpgme_close_notify_handler_t handler;
|
2002-03-18 00:04:06 +00:00
|
|
|
|
void *value;
|
2010-02-17 21:40:02 +00:00
|
|
|
|
};
|
|
|
|
|
typedef struct notify_table_item_s *notify_table_item_t;
|
2001-02-19 17:22:38 +00:00
|
|
|
|
|
2010-02-17 21:40:02 +00:00
|
|
|
|
static notify_table_item_t notify_table;
|
|
|
|
|
static size_t notify_table_size;
|
|
|
|
|
DEFINE_STATIC_LOCK (notify_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
|
|
|
|
|
2010-02-17 21:40:02 +00:00
|
|
|
|
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2002-03-18 00:04:06 +00:00
|
|
|
|
_gpgme_io_read (int fd, void *buffer, size_t count)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
|
int nread;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_read", NULL,
|
|
|
|
|
"fd=%d buffer=%p count=%zu", fd, buffer, count);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2002-06-02 20:43:04 +00:00
|
|
|
|
nread = _gpgme_ath_read (fd, buffer, count);
|
2001-04-02 08:40:32 +00:00
|
|
|
|
}
|
2003-06-06 00:22:27 +00:00
|
|
|
|
while (nread == -1 && errno == EINTR);
|
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:03:43 +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);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2002-03-18 00:04:06 +00:00
|
|
|
|
_gpgme_io_write (int fd, const void *buffer, size_t count)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
|
int nwritten;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_write", NULL,
|
|
|
|
|
"fd=%d buffer=%p count=%zu", fd, buffer, count);
|
2018-11-02 08:03:43 +00:00
|
|
|
|
TRACE_LOGBUFX (buffer, count);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2002-06-02 20:43:04 +00:00
|
|
|
|
nwritten = _gpgme_ath_write (fd, buffer, count);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
}
|
|
|
|
|
while (nwritten == -1 && errno == EINTR);
|
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 (nwritten);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-06-06 00:22:27 +00:00
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2001-12-13 22:02:08 +00:00
|
|
|
|
_gpgme_io_pipe (int filedes[2], int inherit_idx)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2003-06-06 00:22:27 +00:00
|
|
|
|
int saved_errno;
|
2001-12-13 22:02:08 +00:00
|
|
|
|
int err;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_pipe", NULL,
|
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
|
|
|
|
"inherit_idx=%i (GPGME uses it for %s)",
|
2007-09-27 11:44:45 +00:00
|
|
|
|
inherit_idx, inherit_idx ? "reading" : "writing");
|
2001-12-13 22:02:08 +00:00
|
|
|
|
|
|
|
|
|
err = pipe (filedes);
|
|
|
|
|
if (err < 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
|
|
|
|
return TRACE_SYSRES (err);
|
|
|
|
|
|
2001-12-13 22:02:08 +00:00
|
|
|
|
/* FIXME: Should get the old flags first. */
|
|
|
|
|
err = fcntl (filedes[1 - inherit_idx], F_SETFD, FD_CLOEXEC);
|
2003-06-06 00:22:27 +00:00
|
|
|
|
saved_errno = errno;
|
2001-12-13 22:02:08 +00:00
|
|
|
|
if (err < 0)
|
|
|
|
|
{
|
|
|
|
|
close (filedes[0]);
|
|
|
|
|
close (filedes[1]);
|
|
|
|
|
}
|
2003-06-06 00:22:27 +00:00
|
|
|
|
errno = saved_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
|
|
|
|
if (err)
|
|
|
|
|
return TRACE_SYSRES (err);
|
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_SUC ("read fd=%d write fd=%d", filedes[0], filedes[1]);
|
2018-11-16 17:17:22 +00:00
|
|
|
|
return 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
2000-11-23 15:28:15 +00:00
|
|
|
|
int
|
2002-03-18 00:04:06 +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
|
|
|
|
int res;
|
2010-02-17 21:40:02 +00:00
|
|
|
|
_gpgme_close_notify_handler_t handler = NULL;
|
|
|
|
|
void *handler_value;
|
|
|
|
|
int idx;
|
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
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_close", NULL, "fd=%d", 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
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
if (fd == -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
|
|
|
|
{
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
/* First call the notify handler. */
|
2010-02-17 21:40:02 +00:00
|
|
|
|
LOCK (notify_table_lock);
|
|
|
|
|
for (idx=0; idx < notify_table_size; idx++)
|
2002-03-18 00:04:06 +00:00
|
|
|
|
{
|
2010-02-17 21:40:02 +00:00
|
|
|
|
if (notify_table[idx].fd == fd)
|
|
|
|
|
{
|
|
|
|
|
handler = notify_table[idx].handler;
|
|
|
|
|
handler_value = notify_table[idx].value;
|
|
|
|
|
notify_table[idx].handler = NULL;
|
|
|
|
|
notify_table[idx].value = NULL;
|
|
|
|
|
notify_table[idx].fd = -1; /* Mark slot as free. */
|
|
|
|
|
break;
|
2001-02-19 17:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-17 21:40:02 +00:00
|
|
|
|
UNLOCK (notify_table_lock);
|
|
|
|
|
if (handler)
|
|
|
|
|
{
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_LOG ("invoking close handler %p/%p", handler, handler_value);
|
2010-02-17 21:40:02 +00:00
|
|
|
|
handler (fd, handler_value);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-25 13:29:49 +00:00
|
|
|
|
/* Then do the close. */
|
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
|
|
|
|
res = close (fd);
|
|
|
|
|
return TRACE_SYSRES (res);
|
2000-11-23 15:28:15 +00:00
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
2001-02-19 17:22:38 +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-19 17:22:38 +00:00
|
|
|
|
{
|
2010-02-17 21:40:02 +00:00
|
|
|
|
int res = 0;
|
|
|
|
|
int idx;
|
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_set_close_notify", NULL,
|
|
|
|
|
"fd=%d close_handler=%p/%p", fd, handler, 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
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
assert (fd != -1);
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2010-02-17 21:40:02 +00:00
|
|
|
|
LOCK (notify_table_lock);
|
|
|
|
|
for (idx=0; idx < notify_table_size; idx++)
|
|
|
|
|
if (notify_table[idx].fd == -1)
|
|
|
|
|
break;
|
|
|
|
|
if (idx == notify_table_size)
|
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-02-17 21:40:02 +00:00
|
|
|
|
/* We need to increase the size of the table. The approach we
|
|
|
|
|
take is straightforward to minimize the risk of bugs. */
|
|
|
|
|
notify_table_item_t newtbl;
|
|
|
|
|
size_t newsize = notify_table_size + 64;
|
|
|
|
|
|
|
|
|
|
newtbl = calloc (newsize, sizeof *newtbl);
|
|
|
|
|
if (!newtbl)
|
|
|
|
|
{
|
|
|
|
|
res = -1;
|
|
|
|
|
goto leave;
|
|
|
|
|
}
|
|
|
|
|
for (idx=0; idx < notify_table_size; idx++)
|
|
|
|
|
newtbl[idx] = notify_table[idx];
|
|
|
|
|
for (; idx < newsize; idx++)
|
|
|
|
|
{
|
|
|
|
|
newtbl[idx].fd = -1;
|
|
|
|
|
newtbl[idx].handler = NULL;
|
|
|
|
|
newtbl[idx].value = NULL;
|
|
|
|
|
}
|
|
|
|
|
free (notify_table);
|
|
|
|
|
notify_table = newtbl;
|
|
|
|
|
idx = notify_table_size;
|
|
|
|
|
notify_table_size = newsize;
|
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-02-17 21:40:02 +00:00
|
|
|
|
notify_table[idx].fd = fd;
|
|
|
|
|
notify_table[idx].handler = handler;
|
|
|
|
|
notify_table[idx].value = value;
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2010-02-17 21:40:02 +00:00
|
|
|
|
leave:
|
|
|
|
|
UNLOCK (notify_table_lock);
|
|
|
|
|
|
|
|
|
|
return TRACE_SYSRES (res);
|
2001-02-19 17:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
int
|
2002-03-18 00:04:06 +00:00
|
|
|
|
_gpgme_io_set_nonblocking (int fd)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
|
int flags;
|
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 res;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_set_nonblocking", NULL, "fd=%d", fd);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
flags = fcntl (fd, F_GETFL, 0);
|
|
|
|
|
if (flags == -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
|
|
|
|
return TRACE_SYSRES (-1);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
flags |= O_NONBLOCK;
|
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
|
|
|
|
res = fcntl (fd, F_SETFL, flags);
|
|
|
|
|
return TRACE_SYSRES (res);
|
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
|
|
|
|
static long int
|
|
|
|
|
get_max_fds (void)
|
|
|
|
|
{
|
2016-09-13 18:59:07 +00:00
|
|
|
|
const char *source = NULL;
|
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
|
|
|
|
long int fds = -1;
|
|
|
|
|
int rc;
|
|
|
|
|
|
2016-05-27 20:19:35 +00:00
|
|
|
|
/* Under Linux we can figure out the highest used file descriptor by
|
2017-02-03 12:13:22 +00:00
|
|
|
|
* reading /proc/self/fd. This is in the common cases much faster
|
|
|
|
|
* than for example doing 4096 close calls where almost all of them
|
|
|
|
|
* will fail.
|
|
|
|
|
*
|
2017-09-16 03:16:45 +00:00
|
|
|
|
* We can't use the normal opendir/readdir/closedir interface between
|
|
|
|
|
* fork and exec in a multi-threaded process because opendir uses
|
|
|
|
|
* malloc and thus a mutex which may deadlock with a malloc in another
|
|
|
|
|
* thread. However, the underlying getdents system call is safe. */
|
2017-10-04 16:03:54 +00:00
|
|
|
|
#ifdef USE_LINUX_GETDENTS
|
2017-09-16 03:16:45 +00:00
|
|
|
|
{
|
|
|
|
|
int dir_fd;
|
|
|
|
|
char dir_buf[DIR_BUF_SIZE];
|
2017-10-11 15:38:39 +00:00
|
|
|
|
struct linux_dirent64 *dir_entry;
|
2017-09-16 03:16:45 +00:00
|
|
|
|
int r, pos;
|
|
|
|
|
const char *s;
|
|
|
|
|
int x;
|
|
|
|
|
|
|
|
|
|
dir_fd = open ("/proc/self/fd", O_RDONLY | O_DIRECTORY);
|
|
|
|
|
if (dir_fd != -1)
|
|
|
|
|
{
|
|
|
|
|
for (;;)
|
|
|
|
|
{
|
2017-10-11 15:38:39 +00:00
|
|
|
|
r = syscall(SYS_getdents64, dir_fd, dir_buf, DIR_BUF_SIZE);
|
2017-09-16 03:16:45 +00:00
|
|
|
|
if (r == -1)
|
|
|
|
|
{
|
|
|
|
|
/* Fall back to other methods. */
|
|
|
|
|
fds = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (r == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
for (pos = 0; pos < r; pos += dir_entry->d_reclen)
|
|
|
|
|
{
|
2017-10-11 15:38:39 +00:00
|
|
|
|
dir_entry = (struct linux_dirent64 *) (dir_buf + pos);
|
2017-09-16 03:16:45 +00:00
|
|
|
|
s = dir_entry->d_name;
|
|
|
|
|
if (*s < '0' || *s > '9')
|
|
|
|
|
continue;
|
|
|
|
|
/* atoi is not guaranteed to be async-signal-safe. */
|
|
|
|
|
for (x = 0; *s >= '0' && *s <= '9'; s++)
|
|
|
|
|
x = x * 10 + (*s - '0');
|
|
|
|
|
if (!*s && x > fds && x != dir_fd)
|
|
|
|
|
fds = x;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
close (dir_fd);
|
|
|
|
|
}
|
|
|
|
|
if (fds != -1)
|
|
|
|
|
{
|
|
|
|
|
fds++;
|
|
|
|
|
source = "/proc";
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-04 16:03:54 +00:00
|
|
|
|
#endif /*USE_LINUX_GETDENTS*/
|
2016-05-27 20:19:35 +00:00
|
|
|
|
|
|
|
|
|
#ifdef RLIMIT_NOFILE
|
|
|
|
|
if (fds == -1)
|
|
|
|
|
{
|
|
|
|
|
struct rlimit rl;
|
|
|
|
|
rc = getrlimit (RLIMIT_NOFILE, &rl);
|
|
|
|
|
if (rc == 0)
|
|
|
|
|
{
|
|
|
|
|
source = "RLIMIT_NOFILE";
|
|
|
|
|
fds = rl.rlim_max;
|
|
|
|
|
}
|
|
|
|
|
}
|
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
|
|
|
|
#endif
|
|
|
|
|
#ifdef RLIMIT_OFILE
|
|
|
|
|
if (fds == -1)
|
|
|
|
|
{
|
|
|
|
|
struct rlimit rl;
|
|
|
|
|
rc = getrlimit (RLIMIT_OFILE, &rl);
|
|
|
|
|
if (rc == 0)
|
|
|
|
|
{
|
|
|
|
|
source = "RLIMIT_OFILE";
|
|
|
|
|
fds = rl.rlim_max;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef _SC_OPEN_MAX
|
|
|
|
|
if (fds == -1)
|
|
|
|
|
{
|
|
|
|
|
long int scres;
|
|
|
|
|
scres = sysconf (_SC_OPEN_MAX);
|
|
|
|
|
if (scres >= 0)
|
|
|
|
|
{
|
|
|
|
|
source = "_SC_OPEN_MAX";
|
|
|
|
|
return scres;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#ifdef OPEN_MAX
|
|
|
|
|
if (fds == -1)
|
|
|
|
|
{
|
|
|
|
|
source = "OPEN_MAX";
|
|
|
|
|
fds = OPEN_MAX;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if !defined(RLIMIT_NOFILE) && !defined(RLIMIT_OFILE) \
|
|
|
|
|
&& !defined(_SC_OPEN_MAX) && !defined(OPEN_MAX)
|
|
|
|
|
#warning "No known way to get the maximum number of file descriptors."
|
|
|
|
|
#endif
|
|
|
|
|
if (fds == -1)
|
|
|
|
|
{
|
|
|
|
|
source = "arbitrary";
|
|
|
|
|
/* Arbitrary limit. */
|
|
|
|
|
fds = 1024;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-15 15:16:38 +00:00
|
|
|
|
/* AIX returns INT32_MAX instead of a proper value. We assume that
|
|
|
|
|
* this is always an error and use a more reasonable limit. */
|
|
|
|
|
#ifdef INT32_MAX
|
|
|
|
|
if (fds == INT32_MAX)
|
|
|
|
|
{
|
|
|
|
|
source = "aix-fix";
|
|
|
|
|
fds = 1024;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE (DEBUG_SYSIO, "gpgme:max_fds", NULL, "max fds=%ld (%s)", fds, source);
|
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 fds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-10-20 15:39:15 +00:00
|
|
|
|
int
|
2005-11-17 16:12:27 +00:00
|
|
|
|
_gpgme_io_waitpid (int pid, int hang, int *r_status, int *r_signal)
|
|
|
|
|
{
|
|
|
|
|
int status;
|
2014-04-15 10:25:45 +00:00
|
|
|
|
pid_t ret;
|
2005-11-17 16:12:27 +00:00
|
|
|
|
|
|
|
|
|
*r_status = 0;
|
|
|
|
|
*r_signal = 0;
|
2014-04-15 10:25:45 +00:00
|
|
|
|
do
|
|
|
|
|
ret = _gpgme_ath_waitpid (pid, &status, hang? 0 : WNOHANG);
|
|
|
|
|
while (ret == (pid_t)(-1) && errno == EINTR);
|
|
|
|
|
|
|
|
|
|
if (ret == pid)
|
2005-11-17 16:12:27 +00:00
|
|
|
|
{
|
|
|
|
|
if (WIFSIGNALED (status))
|
|
|
|
|
{
|
|
|
|
|
*r_status = 4; /* Need some value here. */
|
|
|
|
|
*r_signal = WTERMSIG (status);
|
|
|
|
|
}
|
|
|
|
|
else if (WIFEXITED (status))
|
|
|
|
|
*r_status = WEXITSTATUS (status);
|
|
|
|
|
else
|
|
|
|
|
*r_status = 4; /* Oops. */
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-28 20:31:31 +00:00
|
|
|
|
/* Returns 0 on success, -1 on error. */
|
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
|
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
|
pid_t pid;
|
|
|
|
|
int 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
|
|
|
|
int status;
|
|
|
|
|
int signo;
|
2009-06-12 16:58:45 +00:00
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_spawn", NULL,
|
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
|
|
|
|
"path=%s", path);
|
|
|
|
|
i = 0;
|
|
|
|
|
while (argv[i])
|
|
|
|
|
{
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_LOG ("argv[%2i] = %s", i, argv[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
|
|
|
|
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
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
2019-06-06 16:55:57 +00:00
|
|
|
|
{
|
|
|
|
|
if (fd_list[i].dup_to == -1)
|
|
|
|
|
TRACE_LOG ("fd[%i] = 0x%x", i, fd_list[i].fd);
|
|
|
|
|
else
|
|
|
|
|
TRACE_LOG ("fd[%i] = 0x%x -> 0x%x", i,fd_list[i].fd,fd_list[i].dup_to);
|
|
|
|
|
}
|
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
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
pid = fork ();
|
2012-09-25 13:29:49 +00:00
|
|
|
|
if (pid == -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
|
|
|
|
return TRACE_SYSRES (-1);
|
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
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
if (!pid)
|
|
|
|
|
{
|
2002-08-28 20:31:31 +00:00
|
|
|
|
/* Intermediate child to prevent zombie processes. */
|
|
|
|
|
if ((pid = fork ()) == 0)
|
2002-03-18 00:04:06 +00:00
|
|
|
|
{
|
2002-08-28 20:31:31 +00:00
|
|
|
|
/* Child. */
|
2017-02-03 12:56:23 +00:00
|
|
|
|
int max_fds = -1;
|
|
|
|
|
int 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
|
|
|
|
int seen_stdin = 0;
|
2014-04-10 09:15:40 +00:00
|
|
|
|
int seen_stdout = 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 seen_stderr = 0;
|
2002-08-28 20:31:31 +00:00
|
|
|
|
|
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
|
|
|
|
if (atfork)
|
|
|
|
|
atfork (atforkvalue, 0);
|
|
|
|
|
|
2017-02-03 12:56:23 +00:00
|
|
|
|
/* First close all fds which will not be inherited. If we
|
|
|
|
|
* have closefrom(2) we first figure out the highest fd we
|
|
|
|
|
* do not want to close, then call closefrom, and on success
|
|
|
|
|
* use the regular code to close all fds up to the start
|
2017-04-03 08:31:40 +00:00
|
|
|
|
* point of closefrom. Note that Solaris' and FreeBSD's closefrom do
|
2017-02-03 12:56:23 +00:00
|
|
|
|
* not return errors. */
|
|
|
|
|
#ifdef HAVE_CLOSEFROM
|
|
|
|
|
{
|
|
|
|
|
fd = -1;
|
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
|
|
|
|
if (fd_list[i].fd > fd)
|
|
|
|
|
fd = fd_list[i].fd;
|
|
|
|
|
fd++;
|
2017-04-03 08:31:40 +00:00
|
|
|
|
#if defined(__sun) || defined(__FreeBSD__)
|
2017-02-03 12:56:23 +00:00
|
|
|
|
closefrom (fd);
|
|
|
|
|
max_fds = fd;
|
|
|
|
|
#else /*!__sun */
|
|
|
|
|
while ((i = closefrom (fd)) && errno == EINTR)
|
|
|
|
|
;
|
|
|
|
|
if (!i || errno == EBADF)
|
|
|
|
|
max_fds = fd;
|
|
|
|
|
#endif /*!__sun*/
|
|
|
|
|
}
|
|
|
|
|
#endif /*HAVE_CLOSEFROM*/
|
|
|
|
|
if (max_fds == -1)
|
|
|
|
|
max_fds = get_max_fds ();
|
|
|
|
|
for (fd = 0; fd < max_fds; fd++)
|
|
|
|
|
{
|
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
|
|
|
|
if (fd_list[i].fd == fd)
|
|
|
|
|
break;
|
|
|
|
|
if (fd_list[i].fd == -1)
|
|
|
|
|
close (fd);
|
|
|
|
|
}
|
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
|
|
|
|
/* And now dup and close those to be duplicated. */
|
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
2002-03-18 00:04:06 +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
|
|
|
|
int child_fd;
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
if (fd_list[i].dup_to != -1)
|
|
|
|
|
child_fd = fd_list[i].dup_to;
|
|
|
|
|
else
|
|
|
|
|
child_fd = fd_list[i].fd;
|
|
|
|
|
|
|
|
|
|
if (child_fd == 0)
|
|
|
|
|
seen_stdin = 1;
|
2014-04-10 09:15:40 +00:00
|
|
|
|
else if (child_fd == 1)
|
|
|
|
|
seen_stdout = 1;
|
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
|
|
|
|
else if (child_fd == 2)
|
|
|
|
|
seen_stderr = 1;
|
|
|
|
|
|
|
|
|
|
if (fd_list[i].dup_to == -1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
res = dup2 (fd_list[i].fd, fd_list[i].dup_to);
|
|
|
|
|
if (res < 0)
|
2002-08-28 20:31: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
|
|
|
|
#if 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
|
|
|
|
/* FIXME: The debug file descriptor is not
|
|
|
|
|
dup'ed anyway, so we can't see this. */
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_LOG ("dup2 failed in child: %s\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
|
|
|
|
strerror (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
|
|
|
|
#endif
|
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
|
|
|
|
_exit (8);
|
2002-08-28 20:31:31 +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
|
|
|
|
|
|
|
|
|
close (fd_list[i].fd);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2014-04-10 09:15:40 +00:00
|
|
|
|
if (! seen_stdin || ! seen_stdout || !seen_stderr)
|
2002-03-18 00:04:06 +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
|
|
|
|
fd = open ("/dev/null", O_RDWR);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
if (fd == -1)
|
2002-03-18 00:04:06 +00:00
|
|
|
|
{
|
2014-04-10 09:15:40 +00:00
|
|
|
|
/* The debug file descriptor is not dup'ed, so we
|
|
|
|
|
can't do a trace output. */
|
2002-03-18 00:04:06 +00:00
|
|
|
|
_exit (8);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
}
|
2014-04-10 09:15:40 +00:00
|
|
|
|
/* Make sure that the process has connected stdin. */
|
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
|
|
|
|
if (! seen_stdin && fd != 0)
|
2002-08-28 20:31:31 +00:00
|
|
|
|
{
|
|
|
|
|
if (dup2 (fd, 0) == -1)
|
2014-04-10 09:15:40 +00:00
|
|
|
|
_exit (8);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
}
|
2014-04-10 09:15:40 +00:00
|
|
|
|
if (! seen_stdout && fd != 1)
|
|
|
|
|
{
|
|
|
|
|
if (dup2 (fd, 1) == -1)
|
|
|
|
|
_exit (8);
|
|
|
|
|
}
|
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
|
|
|
|
if (! seen_stderr && fd != 2)
|
2014-04-10 09:15:40 +00:00
|
|
|
|
{
|
|
|
|
|
if (dup2 (fd, 2) == -1)
|
|
|
|
|
_exit (8);
|
|
|
|
|
}
|
|
|
|
|
if (fd != 0 && fd != 1 && fd != 2)
|
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 (fd);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2008-10-30 15:08:44 +00:00
|
|
|
|
execv (path, (char *const *) argv);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
/* Hmm: in that case we could write a special status code to the
|
|
|
|
|
status-pipe. */
|
|
|
|
|
_exit (8);
|
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
|
|
|
|
/* End child. */
|
|
|
|
|
}
|
2002-08-28 20:31:31 +00:00
|
|
|
|
if (pid == -1)
|
|
|
|
|
_exit (1);
|
|
|
|
|
else
|
|
|
|
|
_exit (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
|
|
|
|
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_LOG ("waiting for child process pid=%i", pid);
|
2002-08-28 20:31:31 +00:00
|
|
|
|
_gpgme_io_waitpid (pid, 1, &status, &signo);
|
|
|
|
|
if (status)
|
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);
|
2002-08-28 20:31:31 +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
|
|
|
|
for (i = 0; fd_list[i].fd != -1; i++)
|
|
|
|
|
{
|
2009-11-05 02:39:31 +00:00
|
|
|
|
if (! (flags & IOSPAWN_FLAG_NOCLOSE))
|
|
|
|
|
_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
|
|
|
|
/* No handle translation. */
|
|
|
|
|
fd_list[i].peer_name = fd_list[i].fd;
|
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
2008-02-14 19:51:21 +00:00
|
|
|
|
if (r_pid)
|
|
|
|
|
*r_pid = pid;
|
|
|
|
|
|
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
|
|
|
|
/* 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
|
2002-07-28 Marcus Brinkmann <marcus@g10code.de>
* data.c (gpgme_data_read): For GPGME_DATA_TYPE_NONE, return EOF
instead an error.
The following changes make it possible to flush an inbound data
pipe before invoking a command handler:
* posix-io.c (_gpgme_io_select): Accept new argument NONBLOCK to
_gpgme_io_select. Set timeout of 0 if this is set.
* w32-io.c (_gpgme_io_select): Likewise.
* io.h: Add new argument NONBLOCK to _gpgme_io_select prototype.
* wait.c (do_select): Add new argument to _gpgme_io_select
invocation.
* rungpg.h (_gpgme_gpg_set_command_handler): Add new argument
linked_data to prototype.
* engine.h (_gpgme_engine_set_command_handler): Likewise.
* engine.c (_gpgme_engine_set_command_handler): Likewise.
* passphrase.c (_gpgme_passphrase_start): Pass NULL as linked_data
argument to _gpgme_engine_set_command_handler.
* rungpg.c (struct gpg_object_s): New members linked_data and
linked_idx in CMD.
(_gpgme_gpg_new): Initialize those new members.
(_gpgme_gpg_set_command_handler): Accept new argument linked_data.
(build_argv): Handle linked_data in the same hack as cb_data.
(read_status): If linked_data is in use, flush the pipe before
activating the command handler.
* gpgme.h: Add prototypes for gpgme_op_edit_start and
gpgme_op_edit.
The next changes export the status codes to the user:
* decrypt.c (_gpgme_decrypt_status_handler): Likewise, also prefix
all STATUS_ with GPGME_.
* delete.c (delete_status_handler): Likewise.
* decrypt-verify.c (decrypt_verify_status_handler): Likewise.
* encrypt.c (_gpgme_encrypt_status_handler): Likewise.
(_gpgme_encrypt_sym_status_handler): Likewise.
* encrypt-sign.c (encrypt_sign_status_handler): Likewise.
* engine-gpgsm.c (parse_status): Likewise.
(gpgsm_status_handler): Likewise.
(gpgsm_set_recipients): Likewise.
* export.c (export_status_handler): Likewise.
* genkey.c (genkey_status_handler): Likewise.
* import.c (append_xml_impinfo): Likewise.
(import_status_handler): Likewise.
* keylist.c (keylist_status_handler): Likewise.
* passphrase.c (_gpgme_passphrase_status_handler): Likewise.
(command_handler): Likewise.
* progress.c (_gpgme_progress_status_handler): Likewise.
* sign.c (_gpgme_sign_status_handler): Likewise.
* trustlist.c (trustlist_status_handler): Likewise.
* verify.c (_gpgme_verify_status_handler): Likewise.
* gpgme.h (GpgmeEditCb): New type.
* rungpg.h (GpgStatusCode): Rename and move to ...
* gpgme.h (GpgmeStatusCode): ... this and here.
* Makefile.am (status-table.h): Run mkstatus on gpgme.h, not rungpg.h.
* mkstatus: Prefix STATUS with GPGME_.
* rungpg.h (GpgStatusHandler, GpgCommandHandler): Change type
accordingly.
* ops.h (_gpgme_verify_status_handler,
_gpgme_decrypt_status_handler, _gpgme_sign_status_handler,
_gpgme_encrypt_status_handler, _gpgme_passphrase_status_handler,
_gpgme_progress_status_handler): Likewise.
* rungpg.c (struct gpg_object_s): Likewise for CMD.code.
These changes add an edit operation to GPGME:
* context.h (struct gpgme_context_s): New member RESULT.edit. *
ops.h: Add prototype for _gpgme_release_edit_result and
_gpgme_passphrase_command_handler.
* passphrase.c (command_handler): Make non-static and rename to ...
(_gpgme_passphrase_command_handler): ... this.
(_gpgme_passphrase_start): Use new name for command handler.
* types.h: Add EditResult type.
* gpgme.c (_gpgme_release_result): Release EDIT result.
* edit.c: New file.
* Makefile.am (libgpgme_la_SOURCES): Add edit.c.
(libgpgme_la_LDADD): Rename to libgpgme_la_LIBADD, and include
assuan_libobjs.
(assuan_libobjs): New variable, set this instead
libgpgme_la_LIBADD.
* engine.h (_gpgme_engine_op_edit): New prototype.
* engine.c (_gpgme_engine_op_edit): New function.
* rungpg.h (_gpgme_gpg_op_edit): New prototype.
* rungpg.c (_gpgme_gpg_op_edit): New function.
2002-07-28 18:41:02 +00:00
|
|
|
|
_gpgme_io_select (struct io_select_fd_s *fds, size_t nfds, int nonblock)
|
2000-11-22 17:10:48 +00:00
|
|
|
|
{
|
2002-05-09 03:38:12 +00:00
|
|
|
|
fd_set readfds;
|
|
|
|
|
fd_set writefds;
|
2003-07-31 15:44:02 +00:00
|
|
|
|
unsigned int 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
|
|
|
|
int any;
|
|
|
|
|
int max_fd;
|
|
|
|
|
int n;
|
|
|
|
|
int count;
|
|
|
|
|
/* Use a 1s timeout. */
|
|
|
|
|
struct timeval timeout = { 1, 0 };
|
2002-03-18 00:04:06 +00:00
|
|
|
|
void *dbg_help = NULL;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_select", NULL,
|
2018-11-16 15:57:09 +00:00
|
|
|
|
"nfds=%zu, nonblock=%u", nfds, nonblock);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
|
|
|
|
FD_ZERO (&readfds);
|
|
|
|
|
FD_ZERO (&writefds);
|
|
|
|
|
max_fd = 0;
|
2002-09-02 12:17:51 +00:00
|
|
|
|
if (nonblock)
|
|
|
|
|
timeout.tv_sec = 0;
|
2002-03-18 00:04:06 +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_SEQ (dbg_help, "select on [ ");
|
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
any = 0;
|
|
|
|
|
for (i = 0; i < nfds; i++)
|
|
|
|
|
{
|
2012-09-25 13:29:49 +00:00
|
|
|
|
if (fds[i].fd == -1)
|
2002-03-18 00:04:06 +00:00
|
|
|
|
continue;
|
2007-09-28 16:23:53 +00:00
|
|
|
|
if (fds[i].for_read)
|
2002-03-18 00:04:06 +00:00
|
|
|
|
{
|
2016-06-14 06:35:12 +00:00
|
|
|
|
if (fds[i].fd >= FD_SETSIZE)
|
|
|
|
|
{
|
|
|
|
|
TRACE_END (dbg_help, " -BAD- ]");
|
2016-11-10 18:49:13 +00:00
|
|
|
|
gpg_err_set_errno (EMFILE);
|
2016-06-14 06:35:12 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
|
assert (!FD_ISSET (fds[i].fd, &readfds));
|
|
|
|
|
FD_SET (fds[i].fd, &readfds);
|
|
|
|
|
if (fds[i].fd > max_fd)
|
|
|
|
|
max_fd = fds[i].fd;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_ADD1 (dbg_help, "r=%d ", fds[i].fd);
|
2019-06-06 16:55:57 +00:00
|
|
|
|
any = 1;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
|
else if (fds[i].for_write)
|
|
|
|
|
{
|
2016-06-14 06:35:12 +00:00
|
|
|
|
if (fds[i].fd >= FD_SETSIZE)
|
|
|
|
|
{
|
|
|
|
|
TRACE_END (dbg_help, " -BAD- ]");
|
2016-11-10 18:49:13 +00:00
|
|
|
|
gpg_err_set_errno (EMFILE);
|
2016-06-14 06:35:12 +00:00
|
|
|
|
return TRACE_SYSRES (-1);
|
|
|
|
|
}
|
2002-05-09 03:38:12 +00:00
|
|
|
|
assert (!FD_ISSET (fds[i].fd, &writefds));
|
2002-03-18 00:04:06 +00:00
|
|
|
|
FD_SET (fds[i].fd, &writefds);
|
|
|
|
|
if (fds[i].fd > max_fd)
|
|
|
|
|
max_fd = fds[i].fd;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_ADD1 (dbg_help, "w=%d ", fds[i].fd);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
any = 1;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
|
fds[i].signaled = 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
TRACE_END (dbg_help, "]");
|
2002-03-18 00:04:06 +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);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2003-05-18 21:08:43 +00:00
|
|
|
|
count = _gpgme_ath_select (max_fd + 1, &readfds, &writefds, NULL,
|
|
|
|
|
&timeout);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
}
|
|
|
|
|
while (count < 0 && errno == EINTR);
|
|
|
|
|
if (count < 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
|
|
|
|
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
|
|
|
|
TRACE_SEQ (dbg_help, "select OK [ ");
|
|
|
|
|
if (TRACE_ENABLED (dbg_help))
|
2002-03-18 00:04:06 +00:00
|
|
|
|
{
|
|
|
|
|
for (i = 0; i <= max_fd; i++)
|
|
|
|
|
{
|
|
|
|
|
if (FD_ISSET (i, &readfds))
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_ADD1 (dbg_help, "r=%d ", i);
|
2002-03-18 00:04:06 +00:00
|
|
|
|
if (FD_ISSET (i, &writefds))
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_ADD1 (dbg_help, "w=%d ", i);
|
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_END (dbg_help, "]");
|
2000-11-22 17:10:48 +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
|
|
|
|
/* The variable N is used to optimize it a little bit. */
|
2002-03-18 00:04:06 +00:00
|
|
|
|
for (n = count, i = 0; i < nfds && n; i++)
|
|
|
|
|
{
|
|
|
|
|
if (fds[i].fd == -1)
|
|
|
|
|
;
|
|
|
|
|
else if (fds[i].for_read)
|
|
|
|
|
{
|
|
|
|
|
if (FD_ISSET (fds[i].fd, &readfds))
|
|
|
|
|
{
|
|
|
|
|
fds[i].signaled = 1;
|
|
|
|
|
n--;
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
|
else if (fds[i].for_write)
|
|
|
|
|
{
|
|
|
|
|
if (FD_ISSET (fds[i].fd, &writefds))
|
|
|
|
|
{
|
|
|
|
|
fds[i].signaled = 1;
|
|
|
|
|
n--;
|
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
|
|
|
|
return TRACE_SYSRES (count);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
}
|
2006-12-17 21:12:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_recvmsg (int fd, struct msghdr *msg, int flags)
|
|
|
|
|
{
|
|
|
|
|
int nread;
|
|
|
|
|
int saved_errno;
|
|
|
|
|
struct iovec *iov;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_recvmsg", NULL,
|
|
|
|
|
"fd=%d msg=%p flags=%i", fd, msg, flags);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
|
|
|
|
|
nread = 0;
|
|
|
|
|
iov = msg->msg_iov;
|
|
|
|
|
while (iov < msg->msg_iov + msg->msg_iovlen)
|
|
|
|
|
{
|
|
|
|
|
nread += iov->iov_len;
|
|
|
|
|
iov++;
|
|
|
|
|
}
|
2012-09-25 13:29:49 +00:00
|
|
|
|
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_LOG ("about to receive %d bytes", 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
|
|
|
|
|
2006-12-17 21:12:40 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
nread = _gpgme_ath_recvmsg (fd, msg, flags);
|
|
|
|
|
}
|
|
|
|
|
while (nread == -1 && errno == EINTR);
|
|
|
|
|
saved_errno = errno;
|
|
|
|
|
if (nread > 0)
|
|
|
|
|
{
|
|
|
|
|
int nr = nread;
|
|
|
|
|
|
|
|
|
|
iov = msg->msg_iov;
|
|
|
|
|
while (nr > 0)
|
|
|
|
|
{
|
|
|
|
|
int len = nr > iov->iov_len ? iov->iov_len : nr;
|
2018-11-02 08:03:43 +00:00
|
|
|
|
TRACE_LOGBUFX (msg->msg_iov->iov_base, len);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
iov++;
|
|
|
|
|
nr -= len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
errno = saved_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 TRACE_SYSRES (nread);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_sendmsg (int fd, const struct msghdr *msg, int flags)
|
|
|
|
|
{
|
|
|
|
|
int nwritten;
|
|
|
|
|
struct iovec *iov;
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_sendmsg", NULL,
|
|
|
|
|
"fd=%d msg=%p flags=%i", fd, msg, flags);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
|
|
|
|
|
nwritten = 0;
|
|
|
|
|
iov = msg->msg_iov;
|
|
|
|
|
while (iov < msg->msg_iov + msg->msg_iovlen)
|
|
|
|
|
{
|
|
|
|
|
nwritten += iov->iov_len;
|
|
|
|
|
iov++;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 15:25:49 +00:00
|
|
|
|
TRACE_LOG ("about to receive %d bytes", nwritten);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
iov = msg->msg_iov;
|
|
|
|
|
while (nwritten > 0)
|
|
|
|
|
{
|
|
|
|
|
int len = nwritten > iov->iov_len ? iov->iov_len : nwritten;
|
2018-11-02 08:03:43 +00:00
|
|
|
|
TRACE_LOGBUFX (msg->msg_iov->iov_base, len);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
iov++;
|
|
|
|
|
nwritten -= len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
nwritten = _gpgme_ath_sendmsg (fd, msg, flags);
|
|
|
|
|
}
|
|
|
|
|
while (nwritten == -1 && errno == EINTR);
|
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 (nwritten);
|
2006-12-17 21:12:40 +00:00
|
|
|
|
}
|
2007-07-16 17:26:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_dup (int fd)
|
|
|
|
|
{
|
2014-04-15 10:25:45 +00:00
|
|
|
|
int new_fd;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
new_fd = dup (fd);
|
|
|
|
|
while (new_fd == -1 && errno == EINTR);
|
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
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE (DEBUG_SYSIO, "_gpgme_io_dup", NULL, "fd=%d -> fd=%d", fd, new_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
|
|
|
|
|
|
|
|
|
return new_fd;
|
2007-07-16 17:26:09 +00:00
|
|
|
|
}
|
2009-04-15 12:04:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_socket (int domain, int type, int proto)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_socket", NULL,
|
|
|
|
|
"domain=%d type=%i proto=%i", domain, type, proto);
|
2009-04-15 12:04:21 +00:00
|
|
|
|
|
|
|
|
|
res = socket (domain, type, proto);
|
|
|
|
|
|
|
|
|
|
return TRACE_SYSRES (res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
_gpgme_io_connect (int fd, struct sockaddr *addr, int addrlen)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
|
2019-06-05 13:48:33 +00:00
|
|
|
|
TRACE_BEG (DEBUG_SYSIO, "_gpgme_io_connect", NULL,
|
|
|
|
|
"fd=%d addr=%p addrlen=%i", fd, addr, addrlen);
|
2009-04-15 12:04:21 +00:00
|
|
|
|
|
2014-04-15 10:25:45 +00:00
|
|
|
|
do
|
|
|
|
|
res = ath_connect (fd, addr, addrlen);
|
|
|
|
|
while (res == -1 && errno == EINTR);
|
2009-04-15 12:04:21 +00:00
|
|
|
|
|
|
|
|
|
return TRACE_SYSRES (res);
|
|
|
|
|
}
|