2000-11-22 17:10:48 +00:00
|
|
|
/* posix-io.c - Posix I/O functions
|
2003-01-29 20:03:24 +00:00
|
|
|
Copyright (C) 2000 Werner Koch (dd9jn)
|
|
|
|
Copyright (C) 2001, 2002 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 General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 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
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GPGME; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
2000-11-22 17:10:48 +00:00
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2000-11-22 17:10:48 +00:00
|
|
|
#include <config.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
#endif
|
2000-11-22 17:10:48 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2002-03-18 00:04:06 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2000-11-22 17:10:48 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2001-01-30 11:01:41 +00:00
|
|
|
#include "util.h"
|
2000-11-22 17:10:48 +00:00
|
|
|
#include "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
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
static struct
|
|
|
|
{
|
|
|
|
void (*handler) (int,void*);
|
|
|
|
void *value;
|
2001-02-19 17:22:38 +00:00
|
|
|
} notify_table[256];
|
|
|
|
|
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;
|
2003-06-06 00:22:27 +00:00
|
|
|
int saved_errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
|
|
|
|
DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int) count);
|
|
|
|
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);
|
|
|
|
saved_errno = errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
DEBUG2 ("fd %d: got %d bytes\n", fd, nread);
|
|
|
|
if (nread > 0)
|
|
|
|
_gpgme_debug (2, "fd %d: got `%.*s'\n", fd, nread, buffer);
|
2003-06-06 00:22:27 +00:00
|
|
|
errno = saved_errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
return 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
|
|
|
{
|
2003-06-06 00:22:27 +00:00
|
|
|
int saved_errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
int nwritten;
|
|
|
|
|
|
|
|
DEBUG2 ("fd %d: about to write %d bytes\n", fd, (int) count);
|
|
|
|
_gpgme_debug (2, "fd %d: write `%.*s'\n", fd, (int) count, buffer);
|
|
|
|
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);
|
2003-06-06 00:22:27 +00:00
|
|
|
saved_errno = errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
DEBUG2 ("fd %d: wrote %d bytes\n", fd, (int) nwritten);
|
2003-06-06 00:22:27 +00:00
|
|
|
errno = saved_errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
return 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;
|
|
|
|
|
|
|
|
err = pipe (filedes);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
/* 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;
|
2001-12-13 22:02:08 +00:00
|
|
|
return err;
|
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
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
/* First call the notify handler. */
|
|
|
|
DEBUG1 ("closing fd %d", fd);
|
2003-07-31 15:44:02 +00:00
|
|
|
if (fd >= 0 && fd < (int) DIM (notify_table))
|
2002-03-18 00:04:06 +00:00
|
|
|
{
|
|
|
|
if (notify_table[fd].handler)
|
|
|
|
{
|
|
|
|
notify_table[fd].handler (fd, notify_table[fd].value);
|
|
|
|
notify_table[fd].handler = NULL;
|
|
|
|
notify_table[fd].value = NULL;
|
2001-02-19 17:22:38 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
/* Then do the close. */
|
|
|
|
return close (fd);
|
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
|
|
|
|
_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
|
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
assert (fd != -1);
|
|
|
|
|
2003-07-31 15:44:02 +00:00
|
|
|
if (fd < 0 || fd >= (int) DIM (notify_table))
|
2002-03-18 00:04:06 +00:00
|
|
|
return -1;
|
|
|
|
DEBUG1 ("set notification for fd %d", fd);
|
|
|
|
notify_table[fd].handler = handler;
|
|
|
|
notify_table[fd].value = value;
|
|
|
|
return 0;
|
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;
|
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)
|
|
|
|
return -1;
|
|
|
|
flags |= O_NONBLOCK;
|
|
|
|
return fcntl (fd, F_SETFL, flags);
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-28 20:31:31 +00:00
|
|
|
/* Returns 0 on success, -1 on error. */
|
2000-11-23 15:28:15 +00:00
|
|
|
int
|
2002-03-18 00:04:06 +00:00
|
|
|
_gpgme_io_spawn (const char *path, char **argv,
|
|
|
|
struct spawn_fd_item_s *fd_child_list,
|
|
|
|
struct spawn_fd_item_s *fd_parent_list)
|
2000-11-22 17:10:48 +00:00
|
|
|
{
|
2002-05-09 03:38:12 +00:00
|
|
|
static int fixed_signals;
|
|
|
|
DEFINE_STATIC_LOCK (fixed_signals_lock);
|
2002-03-18 00:04:06 +00:00
|
|
|
pid_t pid;
|
|
|
|
int i;
|
2002-08-28 20:31:31 +00:00
|
|
|
int status, signo;
|
2002-05-09 03:38:12 +00:00
|
|
|
LOCK (fixed_signals_lock);
|
2002-03-18 00:04:06 +00:00
|
|
|
if (!fixed_signals)
|
|
|
|
{
|
|
|
|
struct sigaction act;
|
2000-12-12 13:31:25 +00:00
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
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);
|
2000-12-12 13:31:25 +00:00
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
fixed_signals = 1;
|
2000-12-12 13:31:25 +00:00
|
|
|
}
|
2002-05-09 03:38:12 +00:00
|
|
|
UNLOCK (fixed_signals_lock);
|
2000-12-12 13:31:25 +00:00
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
pid = fork ();
|
|
|
|
if (pid == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
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. */
|
|
|
|
int duped_stdin = 0;
|
|
|
|
int duped_stderr = 0;
|
|
|
|
|
|
|
|
/* First close all fds which will not be duped. */
|
|
|
|
for (i=0; fd_child_list[i].fd != -1; i++)
|
|
|
|
if (fd_child_list[i].dup_to == -1)
|
2002-03-18 00:04:06 +00:00
|
|
|
close (fd_child_list[i].fd);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
2002-08-28 20:31:31 +00:00
|
|
|
/* And now dup and close the rest. */
|
|
|
|
for (i=0; fd_child_list[i].fd != -1; i++)
|
2002-03-18 00:04:06 +00:00
|
|
|
{
|
2002-08-28 20:31:31 +00:00
|
|
|
if (fd_child_list[i].dup_to != -1)
|
|
|
|
{
|
|
|
|
if (dup2 (fd_child_list[i].fd,
|
|
|
|
fd_child_list[i].dup_to) == -1)
|
|
|
|
{
|
|
|
|
DEBUG1 ("dup2 failed in child: %s\n", strerror (errno));
|
|
|
|
_exit (8);
|
|
|
|
}
|
|
|
|
if (fd_child_list[i].dup_to == 0)
|
|
|
|
duped_stdin=1;
|
|
|
|
if (fd_child_list[i].dup_to == 2)
|
|
|
|
duped_stderr=1;
|
|
|
|
close (fd_child_list[i].fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!duped_stdin || !duped_stderr)
|
2002-03-18 00:04:06 +00:00
|
|
|
{
|
2002-08-28 20:31:31 +00:00
|
|
|
int fd = open ("/dev/null", O_RDWR);
|
|
|
|
if (fd == -1)
|
2002-03-18 00:04:06 +00:00
|
|
|
{
|
2002-08-28 20:31:31 +00:00
|
|
|
DEBUG1 ("can't open `/dev/null': %s\n", strerror (errno));
|
2002-03-18 00:04:06 +00:00
|
|
|
_exit (8);
|
2002-08-28 20:31:31 +00:00
|
|
|
}
|
|
|
|
/* Make sure that the process has a connected stdin. */
|
|
|
|
if (!duped_stdin)
|
|
|
|
{
|
|
|
|
if (dup2 (fd, 0) == -1)
|
|
|
|
{
|
|
|
|
DEBUG1("dup2(/dev/null, 0) failed: %s\n",
|
|
|
|
strerror (errno));
|
|
|
|
_exit (8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!duped_stderr)
|
|
|
|
if (dup2 (fd, 2) == -1)
|
|
|
|
{
|
2003-05-18 21:08:43 +00:00
|
|
|
DEBUG1 ("dup2(dev/null, 2) failed: %s\n",
|
|
|
|
strerror (errno));
|
2002-08-28 20:31:31 +00:00
|
|
|
_exit (8);
|
|
|
|
}
|
|
|
|
close (fd);
|
|
|
|
}
|
2000-11-22 17:10:48 +00:00
|
|
|
|
2002-08-28 20:31:31 +00:00
|
|
|
execv ( path, argv );
|
|
|
|
/* Hmm: in that case we could write a special status code to the
|
|
|
|
status-pipe. */
|
|
|
|
DEBUG1 ("exec of `%s' failed\n", path);
|
|
|
|
_exit (8);
|
|
|
|
} /* End child. */
|
|
|
|
if (pid == -1)
|
|
|
|
_exit (1);
|
|
|
|
else
|
|
|
|
_exit (0);
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
|
2002-08-28 20:31:31 +00:00
|
|
|
_gpgme_io_waitpid (pid, 1, &status, &signo);
|
|
|
|
if (status)
|
|
|
|
return -1;
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
/* .dup_to is not used in the parent list. */
|
2002-08-28 20:31:31 +00:00
|
|
|
for (i = 0; fd_parent_list[i].fd != -1; i++)
|
2002-11-25 21:12:46 +00:00
|
|
|
_gpgme_io_close (fd_parent_list[i].fd);
|
2000-11-22 17:10:48 +00:00
|
|
|
|
2002-08-28 20:31:31 +00:00
|
|
|
return 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2002-03-18 00:04:06 +00:00
|
|
|
_gpgme_io_waitpid (int pid, int hang, int *r_status, int *r_signal)
|
2000-11-22 17:10:48 +00:00
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
int status;
|
|
|
|
|
|
|
|
*r_status = 0;
|
|
|
|
*r_signal = 0;
|
2002-06-02 20:43:04 +00:00
|
|
|
if (_gpgme_ath_waitpid (pid, &status, hang? 0 : WNOHANG) == pid)
|
2002-03-18 00:04:06 +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;
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
return 0;
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
|
2001-02-13 15:00:31 +00:00
|
|
|
int
|
2002-03-18 00:04:06 +00:00
|
|
|
_gpgme_io_kill (int pid, int hard)
|
2001-02-13 15:00:31 +00:00
|
|
|
{
|
2002-03-18 00:04:06 +00:00
|
|
|
return kill (pid, hard ? SIGKILL : SIGTERM);
|
2001-02-13 15:00:31 +00:00
|
|
|
}
|
|
|
|
|
2000-11-22 17:10:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Select on the list of fds.
|
|
|
|
* Returns: -1 = error
|
|
|
|
* 0 = timeout or nothing to select
|
|
|
|
* >0 = number of signaled fds
|
|
|
|
*/
|
|
|
|
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;
|
|
|
|
int any, max_fd, n, count;
|
2002-09-02 12:17:51 +00:00
|
|
|
struct timeval timeout = { 1, 0 }; /* Use a 1s timeout. */
|
2002-03-18 00:04:06 +00:00
|
|
|
void *dbg_help = NULL;
|
|
|
|
|
|
|
|
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
|
|
|
|
2002-05-08 03:57:42 +00:00
|
|
|
DEBUG_BEGIN (dbg_help, 3, "gpgme:select on [ ");
|
2002-03-18 00:04:06 +00:00
|
|
|
any = 0;
|
|
|
|
for (i = 0; i < nfds; i++)
|
|
|
|
{
|
|
|
|
if (fds[i].fd == -1)
|
|
|
|
continue;
|
|
|
|
if (fds[i].frozen)
|
2002-05-08 03:57:42 +00:00
|
|
|
DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd);
|
2002-03-18 00:04:06 +00:00
|
|
|
else if (fds[i].for_read)
|
|
|
|
{
|
|
|
|
assert (!FD_ISSET (fds[i].fd, &readfds));
|
|
|
|
FD_SET (fds[i].fd, &readfds);
|
|
|
|
if (fds[i].fd > max_fd)
|
|
|
|
max_fd = fds[i].fd;
|
|
|
|
DEBUG_ADD1 (dbg_help, "r%d ", fds[i].fd);
|
|
|
|
any = 1;
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
else if (fds[i].for_write)
|
|
|
|
{
|
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;
|
|
|
|
DEBUG_ADD1 (dbg_help, "w%d ", fds[i].fd);
|
|
|
|
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
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
DEBUG_END (dbg_help, "]");
|
|
|
|
if (!any)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2003-06-06 00:22:27 +00:00
|
|
|
int saved_errno = errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
DEBUG1 ("_gpgme_io_select failed: %s\n", strerror (errno));
|
2003-06-06 00:22:27 +00:00
|
|
|
errno = saved_errno;
|
2002-03-18 00:04:06 +00:00
|
|
|
return -1; /* error */
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
2002-05-08 03:57:42 +00:00
|
|
|
DEBUG_BEGIN (dbg_help, 3, "select OK [ ");
|
|
|
|
if (DEBUG_ENABLED (dbg_help))
|
2002-03-18 00:04:06 +00:00
|
|
|
{
|
|
|
|
for (i = 0; i <= max_fd; i++)
|
|
|
|
{
|
|
|
|
if (FD_ISSET (i, &readfds))
|
|
|
|
DEBUG_ADD1 (dbg_help, "r%d ", i);
|
|
|
|
if (FD_ISSET (i, &writefds))
|
|
|
|
DEBUG_ADD1 (dbg_help, "w%d ", i);
|
2001-01-30 11:01:41 +00:00
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
DEBUG_END (dbg_help, "]");
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|
|
|
|
|
2002-03-18 00:04:06 +00:00
|
|
|
/* n is used to optimize it a little bit. */
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-03-18 00:04:06 +00:00
|
|
|
return count;
|
2000-11-22 17:10:48 +00:00
|
|
|
}
|