2002-03-17 Marcus Brinkmann <marcus@g10code.de>

* configure.ac: Add automake conditional HAVE_DOSISH_SYSTEM.

gpgme/
2002-03-18  Marcus Brinkmann  <marcus@g10code.de>

	* Makefile.am (system_components): New variable, set depending on
	HAVE_DOSISH_SYSTEM.
	(libgpgme_la_SOURCES): Use system_components.  Remove `syshdr.h'.
	* syshdr.h: File removed.

	* posix-io.c: Remove !HAVE_DOSISH_SYSTEM safeguard.  Clean up source.
	* posix-sema.c: Likewise.
	* posix-util.c: Likewise.

	* w32-io.c: Remove HAVE_DOSISH_SYSTEM safeguard.
	* w32-sema.c: Likewise.
	* w32-util.c: Likewise.

	* posix-io.c: Include `unistd.h', do not include `syshdr.h'.
	* posix-sema.c: Likewise.
	* w32-io.c: Include `io.h', do not include `syshdr.h'
	* w32-sema.c: Likewise.
	* w32-util.c: Likewise.
	* data.c: Do not include `syshdr.h'.
	* wait.c: Likewise.
	* wait.h: Code cleanup.

	* mutex.h: New file.
	* posix-sema.c: Implement.
This commit is contained in:
Marcus Brinkmann 2002-03-18 00:04:06 +00:00
parent 5a24e01ee8
commit 6cee0a4f3f
17 changed files with 553 additions and 393 deletions

View File

@ -1,3 +1,7 @@
2002-03-17 Marcus Brinkmann <marcus@g10code.de>
* configure.ac: Add automake conditional HAVE_DOSISH_SYSTEM.
2002-03-04 Werner Koch <wk@gnupg.org> 2002-03-04 Werner Koch <wk@gnupg.org>
* configure.ac: Bumbed version to 0.3.4-cvs to continue development. * configure.ac: Bumbed version to 0.3.4-cvs to continue development.

2
TODO
View File

@ -51,7 +51,7 @@ Hey Emacs, this is -*- outline -*- mode!
** Make sure everything is cleaned correctly (esp. test area). ** Make sure everything is cleaned correctly (esp. test area).
* Architecture support * Architecture support
** Implement posix-sema.c ** (nothing currently)
Bugs reported by Stephane Corthesy: Bugs reported by Stephane Corthesy:
> BTW, here's another bug: it it not possible to retrieve fingerprints > BTW, here's another bug: it it not possible to retrieve fingerprints

View File

@ -72,6 +72,7 @@ case "${target}" in
# DOS with the DJGPP environment # DOS with the DJGPP environment
AC_DEFINE(HAVE_DRIVE_LETTERS) AC_DEFINE(HAVE_DRIVE_LETTERS)
AC_DEFINE(HAVE_DOSISH_SYSTEM) AC_DEFINE(HAVE_DOSISH_SYSTEM)
have_dosish_system=yes
GPG_DEFAULT='c:\\gnupg\\gpg.exe' GPG_DEFAULT='c:\\gnupg\\gpg.exe'
GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe' GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe'
#component_system='COM+' #component_system='COM+'
@ -82,6 +83,7 @@ dnl GPG_DEFAULT='/usr/bin/gpg'
dnl GPGSM_DEFAULT='/usr/bin/gpgsm' dnl GPGSM_DEFAULT='/usr/bin/gpgsm'
;; ;;
esac esac
AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = "yes")
dnl dnl
dnl Checks for libraries. dnl Checks for libraries.

View File

@ -1,3 +1,30 @@
2002-03-18 Marcus Brinkmann <marcus@g10code.de>
* Makefile.am (system_components): New variable, set depending on
HAVE_DOSISH_SYSTEM.
(libgpgme_la_SOURCES): Use system_components. Remove `syshdr.h'.
* syshdr.h: File removed.
* posix-io.c: Remove !HAVE_DOSISH_SYSTEM safeguard. Clean up source.
* posix-sema.c: Likewise.
* posix-util.c: Likewise.
* w32-io.c: Remove HAVE_DOSISH_SYSTEM safeguard.
* w32-sema.c: Likewise.
* w32-util.c: Likewise.
* posix-io.c: Include `unistd.h', do not include `syshdr.h'.
* posix-sema.c: Likewise.
* w32-io.c: Include `io.h', do not include `syshdr.h'
* w32-sema.c: Likewise.
* w32-util.c: Likewise.
* data.c: Do not include `syshdr.h'.
* wait.c: Likewise.
* wait.h: Code cleanup.
* mutex.h: New file.
* posix-sema.c: Implement.
2002-03-08 Werner Koch <wk@gnupg.org> 2002-03-08 Werner Koch <wk@gnupg.org>
* util.h [!HAVE_FOPENCOOKIE]: Fixed type. Thanks to Frank Heckenbach. * util.h [!HAVE_FOPENCOOKIE]: Fixed type. Thanks to Frank Heckenbach.

View File

@ -35,9 +35,15 @@ AM_CPPFLAGS = -I$(top_srcdir)/assuan
libgpgme_la_LIBADD = ../assuan/libassuan.a ../jnlib/libjnlib.a libgpgme_la_LIBADD = ../assuan/libassuan.a ../jnlib/libjnlib.a
endif endif
if HAVE_DOSISH_SYSTEM
system_components = w32-util.c w32-sema.c w32-io.c
else
system_components = posix-util.c posix-sema.c posix-io.c
endif
libgpgme_la_SOURCES = \ libgpgme_la_SOURCES = \
gpgme.h types.h \ gpgme.h types.h \
util.h util.c posix-util.c w32-util.c \ util.h util.c \
context.h ops.h \ context.h ops.h \
data.c recipient.c signers.c \ data.c recipient.c signers.c \
wait.c wait.h \ wait.c wait.h \
@ -59,8 +65,8 @@ libgpgme_la_SOURCES = \
rungpg.c rungpg.h status-table.h \ rungpg.c rungpg.h status-table.h \
engine-gpgsm.c engine-gpgsm.h \ engine-gpgsm.c engine-gpgsm.h \
engine.c engine.h \ engine.c engine.h \
sema.h posix-sema.c w32-sema.c \ sema.h io.h \
syshdr.h io.h posix-io.c w32-io.c \ ${system_components} \
gpgme.c debug.c version.c errors.c gpgme.c debug.c version.c errors.c
errors.c : gpgme.h errors.c : gpgme.h

View File

@ -27,7 +27,6 @@
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "syshdr.h"
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"

View File

@ -43,7 +43,7 @@ extern "C" {
AM_PATH_GPGME macro) check that this header matches the installed AM_PATH_GPGME macro) check that this header matches the installed
library. Warning: Do not edit the next line. configure will do library. Warning: Do not edit the next line. configure will do
that for you! */ that for you! */
#define GPGME_VERSION "0.3.5-cvs" #define GPGME_VERSION "0.3.5-cvs-2002-03-10"
/* The opaque data types used by GPGME. */ /* The opaque data types used by GPGME. */

124
gpgme/mutex.h Normal file
View File

@ -0,0 +1,124 @@
/* mutex.h - Portable mutual exclusion, independent from any thread library.
* Copyright (C) 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef MUTEX_H
#define MUTEX_H
/* Define MUTEX_FAKE before including the file to get stubs that don't
provide any locking at all. Define MUTEX_PTHREAD if you can link
against the posix thread library. */
#if defined(MUTEX_FAKE)
typedef char mutex_t;
#define mutex_init(x) (0)
#define mutex_destroy(x)
#define mutex_lock(x) (0)
#define mutex_unlock(x) (0)
#elif defined(MUTEX_PTHREAD)
#include <pthread.h>
#define mutex_t pthread_mutex_t
#define mutex_init(x) pthread_mutex_init (&(x), 0)
#define mutex_destroy(x) pthread_mutex_destroy(&(x))
#define mutex_lock(x) pthread_mutex_lock (&(x))
#define mutex_unlock(x) pthread_mutex_unlock (&(x))
#else
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
/* The type of a mutex. */
typedef int mutex_t[2];
inline static int
set_close_on_exec (int fd)
{
int flags = fcntl (fd, F_GETFD, 0);
if (flags == -1)
return errno;
flags |= FD_CLOEXEC;
if (fcntl (fd, F_SETFD, flags) == -1)
return errno;
return 0;
}
/* Initialize the mutex variable MUTEX. */
inline int
mutex_init (mutex_t mutex)
{
ssize_t amount;
int err = 0;
if (pipe (mutex))
return errno;
err = set_close_on_exec (mutex[0]);
if (!err)
err = set_close_on_exec (mutex[1]);
if (!err)
while ((amount = write (mutex[1], " ", 1)) < 0 && errno == EINTR)
;
if (!err && amount != 1)
err = errno;
if (err)
{
close (mutex[0]);
close (mutex[1]);
}
return err;
}
/* Destroy the mutex variable MUTEX. */
inline void
mutex_destroy (mutex_t mutex)
{
close (mutex[0]);
close (mutex[1]);
}
/* Take the mutex variable MUTEX. */
inline int
mutex_lock (mutex_t mutex)
{
char data;
int amount;
while ((amount = read (mutex[0], &data, 1)) < 0 && errno == EINTR)
;
return (amount != 1) ? errno : 0;
}
/* Release the mutex variable MUTEX. */
inline int
mutex_unlock (mutex_t mutex)
{
int amount;
while ((amount = write (mutex[1], " ", 1)) < 0 && errno == EINTR)
;
return (amount != 1) ? errno : 0;
}
#endif /* MUTEX_FAKE */
#endif /* MUTEX_H */

View File

@ -1,6 +1,6 @@
/* posix-io.c - Posix I/O functions /* posix-io.c - Posix I/O functions
* Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -19,58 +19,61 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#ifndef HAVE_DOSISH_SYSTEM #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <signal.h>
#include <fcntl.h>
#include "syshdr.h"
#include "util.h" #include "util.h"
#include "io.h" #include "io.h"
static struct { static struct
void (*handler)(int,void*); {
void (*handler) (int,void*);
void *value; void *value;
} notify_table[256]; } notify_table[256];
int int
_gpgme_io_read ( int fd, void *buffer, size_t count ) _gpgme_io_read (int fd, void *buffer, size_t count)
{ {
int nread; int nread;
DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int)count ); DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int) count);
do { do
{
nread = read (fd, buffer, count); nread = read (fd, buffer, count);
} while (nread == -1 && errno == EINTR );
DEBUG2 ("fd %d: got %d bytes\n", fd, nread );
if ( nread > 0 ) {
_gpgme_debug (2, "fd %d: got `%.*s'\n", fd, nread, buffer );
} }
while (nread == -1 && errno == EINTR );
DEBUG2 ("fd %d: got %d bytes\n", fd, nread);
if (nread > 0)
_gpgme_debug (2, "fd %d: got `%.*s'\n", fd, nread, buffer);
return nread; return nread;
} }
int int
_gpgme_io_write ( int fd, const void *buffer, size_t count ) _gpgme_io_write (int fd, const void *buffer, size_t count)
{ {
int nwritten; int nwritten;
DEBUG2 ("fd %d: about to write %d bytes\n", fd, (int)count ); DEBUG2 ("fd %d: about to write %d bytes\n", fd, (int) count);
_gpgme_debug (2, "fd %d: write `%.*s'\n", fd, (int)count, buffer ); _gpgme_debug (2, "fd %d: write `%.*s'\n", fd, (int) count, buffer);
do { do
{
nwritten = write (fd, buffer, count); nwritten = write (fd, buffer, count);
} while (nwritten == -1 && errno == EINTR ); }
DEBUG2 ("fd %d: wrote %d bytes\n", fd, (int)nwritten ); while (nwritten == -1 && errno == EINTR);
DEBUG2 ("fd %d: wrote %d bytes\n", fd, (int) nwritten);
return nwritten; return nwritten;
} }
@ -92,32 +95,36 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx)
return err; return err;
} }
int int
_gpgme_io_close ( int fd ) _gpgme_io_close (int fd)
{ {
if ( fd == -1 ) if (fd == -1)
return -1; return -1;
/* first call the notify handler */ /* First call the notify handler. */
DEBUG1 ("closing fd %d", fd ); DEBUG1 ("closing fd %d", fd);
if ( fd >= 0 && fd < DIM (notify_table) ) { if (fd >= 0 && fd < DIM (notify_table))
if (notify_table[fd].handler) { {
if (notify_table[fd].handler)
{
notify_table[fd].handler (fd, notify_table[fd].value); notify_table[fd].handler (fd, notify_table[fd].value);
notify_table[fd].handler = NULL; notify_table[fd].handler = NULL;
notify_table[fd].value = NULL; notify_table[fd].value = NULL;
} }
} }
/* then do the close */ /* Then do the close. */
return close (fd); return close (fd);
} }
int int
_gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value) _gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
{ {
assert (fd != -1); assert (fd != -1);
if ( fd < 0 || fd >= DIM (notify_table) ) if (fd < 0 || fd >= DIM (notify_table))
return -1; return -1;
DEBUG1 ("set notification for fd %d", fd ); DEBUG1 ("set notification for fd %d", fd);
notify_table[fd].handler = handler; notify_table[fd].handler = handler;
notify_table[fd].value = value; notify_table[fd].value = value;
return 0; return 0;
@ -125,7 +132,7 @@ _gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value)
int int
_gpgme_io_set_nonblocking ( int fd ) _gpgme_io_set_nonblocking (int fd)
{ {
int flags; int flags;
@ -138,124 +145,134 @@ _gpgme_io_set_nonblocking ( int fd )
int int
_gpgme_io_spawn ( const char *path, char **argv, _gpgme_io_spawn (const char *path, char **argv,
struct spawn_fd_item_s *fd_child_list, struct spawn_fd_item_s *fd_child_list,
struct spawn_fd_item_s *fd_parent_list ) struct spawn_fd_item_s *fd_parent_list)
{ {
static volatile int fixed_signals; static volatile int fixed_signals;
pid_t pid; pid_t pid;
int i; int i;
if ( !fixed_signals ) { if (!fixed_signals)
{
struct sigaction act; struct sigaction act;
sigaction( SIGPIPE, NULL, &act ); sigaction (SIGPIPE, NULL, &act);
if( act.sa_handler == SIG_DFL ) { if (act.sa_handler == SIG_DFL)
{
act.sa_handler = SIG_IGN; act.sa_handler = SIG_IGN;
sigemptyset( &act.sa_mask ); sigemptyset (&act.sa_mask);
act.sa_flags = 0; act.sa_flags = 0;
sigaction( SIGPIPE, &act, NULL); sigaction (SIGPIPE, &act, NULL);
} }
fixed_signals = 1; fixed_signals = 1;
/* fixme: This is not really MT safe */ /* XXX: This is not really MT safe. */
} }
pid = fork (); pid = fork ();
if (pid == -1) if (pid == -1)
return -1; return -1;
if ( !pid ) { /* child */ if (!pid)
{
/* Child. */
int duped_stdin = 0; int duped_stdin = 0;
int duped_stderr = 0; int duped_stderr = 0;
/* first close all fds which will not be duped */ /* First close all fds which will not be duped. */
for (i=0; fd_child_list[i].fd != -1; i++ ) { for (i=0; fd_child_list[i].fd != -1; i++)
if (fd_child_list[i].dup_to == -1 ) if (fd_child_list[i].dup_to == -1)
close (fd_child_list[i].fd); close (fd_child_list[i].fd);
}
/* and now dup and close the rest */ /* And now dup and close the rest. */
for (i=0; fd_child_list[i].fd != -1; i++ ) { for (i=0; fd_child_list[i].fd != -1; i++)
if (fd_child_list[i].dup_to != -1 ) { {
if ( dup2 (fd_child_list[i].fd, if (fd_child_list[i].dup_to != -1)
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)); DEBUG1 ("dup2 failed in child: %s\n", strerror (errno));
_exit (8); _exit (8);
} }
if ( fd_child_list[i].dup_to == 0 ) if (fd_child_list[i].dup_to == 0)
duped_stdin=1; duped_stdin=1;
if ( fd_child_list[i].dup_to == 2 ) if (fd_child_list[i].dup_to == 2)
duped_stderr=1; duped_stderr=1;
close (fd_child_list[i].fd); close (fd_child_list[i].fd);
} }
} }
if( !duped_stdin || !duped_stderr ) { if (!duped_stdin || !duped_stderr)
int fd = open ( "/dev/null", O_RDWR ); {
if ( fd == -1 ) { int fd = open ("/dev/null", O_RDWR);
DEBUG1 ("can't open `/dev/null': %s\n", strerror (errno) ); if (fd == -1)
{
DEBUG1 ("can't open `/dev/null': %s\n", strerror (errno));
_exit (8); _exit (8);
} }
/* Make sure that the process has a connected stdin */ /* Make sure that the process has a connected stdin. */
if ( !duped_stdin ) { if (!duped_stdin)
if ( dup2 ( fd, 0 ) == -1 ) { {
if (dup2 (fd, 0) == -1)
{
DEBUG1("dup2(/dev/null, 0) failed: %s\n", DEBUG1("dup2(/dev/null, 0) failed: %s\n",
strerror (errno) ); strerror (errno));
_exit (8); _exit (8);
} }
} }
if ( !duped_stderr ) { if (!duped_stderr)
if ( dup2 ( fd, 2 ) == -1 ) { if (dup2 (fd, 2) == -1)
{
DEBUG1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno)); DEBUG1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno));
_exit (8); _exit (8);
} }
}
close (fd); close (fd);
} }
execv ( path, argv ); execv ( path, argv );
/* Hmm: in that case we could write a special status code to the /* Hmm: in that case we could write a special status code to the
* status-pipe */ status-pipe. */
DEBUG1 ("exec of `%s' failed\n", path ); DEBUG1 ("exec of `%s' failed\n", path);
_exit (8); _exit (8);
} /* end child */ } /* End child. */
/* .dup_to is not used in the parent list */ /* .dup_to is not used in the parent list. */
for (i=0; fd_parent_list[i].fd != -1; i++ ) { for (i=0; fd_parent_list[i].fd != -1; i++)
close (fd_parent_list[i].fd); close (fd_parent_list[i].fd);
}
return (int)pid; return (int) pid;
} }
int int
_gpgme_io_waitpid ( int pid, int hang, int *r_status, int *r_signal ) _gpgme_io_waitpid (int pid, int hang, int *r_status, int *r_signal)
{ {
int status; int status;
*r_status = 0; *r_status = 0;
*r_signal = 0; *r_signal = 0;
if ( waitpid ( pid, &status, hang? 0 : WNOHANG ) == pid ) { if (waitpid (pid, &status, hang? 0 : WNOHANG) == pid)
if ( WIFSIGNALED (status) ) { {
*r_status = 4; /* Need some value here */ if (WIFSIGNALED (status))
{
*r_status = 4; /* Need some value here. */
*r_signal = WTERMSIG (status); *r_signal = WTERMSIG (status);
} }
else if ( WIFEXITED (status) ) { else if (WIFEXITED (status))
*r_status = WEXITSTATUS (status); *r_status = WEXITSTATUS (status);
} else
else { *r_status = 4; /* Oops. */
*r_status = 4; /* oops */
}
return 1; return 1;
} }
return 0; return 0;
} }
int int
_gpgme_io_kill ( int pid, int hard ) _gpgme_io_kill (int pid, int hard)
{ {
return kill ( pid, hard? SIGKILL : SIGTERM ); return kill (pid, hard ? SIGKILL : SIGTERM);
} }
@ -266,81 +283,93 @@ _gpgme_io_kill ( int pid, int hard )
* >0 = number of signaled fds * >0 = number of signaled fds
*/ */
int int
_gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds ) _gpgme_io_select (struct io_select_fd_s *fds, size_t nfds)
{ {
static fd_set readfds; static fd_set readfds;
static fd_set writefds; static fd_set writefds;
int any, i, max_fd, n, count; int any, i, max_fd, n, count;
struct timeval timeout = { 1, 0 }; /* Use a 1s timeout */ struct timeval timeout = { 1, 0 }; /* Use a 1s timeout. */
void *dbg_help = NULL; void *dbg_help = NULL;
FD_ZERO ( &readfds ); FD_ZERO (&readfds);
FD_ZERO ( &writefds ); FD_ZERO (&writefds);
max_fd = 0; max_fd = 0;
if ( _gpgme_debug_level () > 2 ) if (_gpgme_debug_level () > 2)
DEBUG_BEGIN (dbg_help, "gpgme:select on [ "); DEBUG_BEGIN (dbg_help, "gpgme:select on [ ");
any = 0; any = 0;
for ( i=0; i < nfds; i++ ) { for (i = 0; i < nfds; i++)
if ( fds[i].fd == -1 ) {
if (fds[i].fd == -1)
continue; continue;
if ( fds[i].frozen ) { if (fds[i].frozen)
DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd ); DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd );
} else if (fds[i].for_read)
else if ( fds[i].for_read ) { {
assert ( !FD_ISSET ( fds[i].fd, &readfds ) ); assert (!FD_ISSET (fds[i].fd, &readfds));
FD_SET ( fds[i].fd, &readfds ); FD_SET (fds[i].fd, &readfds);
if ( fds[i].fd > max_fd ) if (fds[i].fd > max_fd)
max_fd = fds[i].fd; max_fd = fds[i].fd;
DEBUG_ADD1 (dbg_help, "r%d ", fds[i].fd ); DEBUG_ADD1 (dbg_help, "r%d ", fds[i].fd);
any = 1; any = 1;
} }
else if ( fds[i].for_write ) { else if (fds[i].for_write)
assert ( !FD_ISSET ( fds[i].fd, &writefds ) ); {
FD_SET ( fds[i].fd, &writefds ); assert (!FD_ISSET ( fds[i].fd, &writefds));
if ( fds[i].fd > max_fd ) FD_SET (fds[i].fd, &writefds);
if (fds[i].fd > max_fd)
max_fd = fds[i].fd; max_fd = fds[i].fd;
DEBUG_ADD1 (dbg_help, "w%d ", fds[i].fd ); DEBUG_ADD1 (dbg_help, "w%d ", fds[i].fd);
any = 1; any = 1;
} }
fds[i].signaled = 0; fds[i].signaled = 0;
} }
DEBUG_END (dbg_help, "]" ); DEBUG_END (dbg_help, "]");
if ( !any ) if (!any)
return 0; return 0;
do { do
count = select ( max_fd+1, &readfds, &writefds, NULL, &timeout ); {
} while ( count < 0 && errno == EINTR); count = select (max_fd + 1, &readfds, &writefds, NULL, &timeout);
if ( count < 0 ) { }
DEBUG1 ("_gpgme_io_select failed: %s\n", strerror (errno) ); while (count < 0 && errno == EINTR);
if (count < 0)
{
DEBUG1 ("_gpgme_io_select failed: %s\n", strerror (errno));
return -1; /* error */ return -1; /* error */
} }
if ( _gpgme_debug_level () > 2 ) if (_gpgme_debug_level () > 2)
DEBUG_BEGIN (dbg_help, "select OK [ " ); DEBUG_BEGIN (dbg_help, "select OK [ ");
if (DEBUG_ENABLED(dbg_help)) { if (DEBUG_ENABLED(dbg_help))
for (i=0; i <= max_fd; i++ ) { {
if (FD_ISSET (i, &readfds) ) for (i = 0; i <= max_fd; i++)
DEBUG_ADD1 (dbg_help, "r%d ", i ); {
if (FD_ISSET (i, &writefds) ) if (FD_ISSET (i, &readfds))
DEBUG_ADD1 (dbg_help, "w%d ", i ); DEBUG_ADD1 (dbg_help, "r%d ", i);
if (FD_ISSET (i, &writefds))
DEBUG_ADD1 (dbg_help, "w%d ", i);
} }
DEBUG_END (dbg_help, "]" ); DEBUG_END (dbg_help, "]");
} }
/* n is used to optimize it a little bit */ /* n is used to optimize it a little bit. */
for ( n=count, i=0; i < nfds && n ; i++ ) { for (n = count, i = 0; i < nfds && n; i++)
if ( fds[i].fd == -1 ) {
if (fds[i].fd == -1)
; ;
else if ( fds[i].for_read ) { else if (fds[i].for_read)
if ( FD_ISSET ( fds[i].fd, &readfds ) ) { {
if (FD_ISSET (fds[i].fd, &readfds))
{
fds[i].signaled = 1; fds[i].signaled = 1;
n--; n--;
} }
} }
else if ( fds[i].for_write ) { else if (fds[i].for_write)
if ( FD_ISSET ( fds[i].fd, &writefds ) ) { {
if (FD_ISSET (fds[i].fd, &writefds))
{
fds[i].signaled = 1; fds[i].signaled = 1;
n--; n--;
} }
@ -348,9 +377,3 @@ _gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds )
} }
return count; return count;
} }
#endif /*!HAVE_DOSISH_SYSTEM*/

View File

@ -1,6 +1,6 @@
/* posix-sema.c /* posix-sema.c
* Copyright (C) 2001 Werner Koch (dd9jn) * Copyright (C) 2001 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -19,53 +19,101 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#ifndef HAVE_DOSISH_SYSTEM #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h> #include <fcntl.h>
#include "syshdr.h" #include <unistd.h>
#include <sys/time.h>
#include <sys/types.h>
#include "util.h" #include "util.h"
#include "sema.h" #include "sema.h"
#include "mutex.h"
static void
sema_fatal (const char *text)
{
fprintf (stderr, "sema.c: %s\n", text);
abort ();
}
static void
critsect_init (struct critsect_s *s)
{
static mutex_t init_lock;
static int initialized;
mutex_t *mp;
if (!initialized)
{
/* The very first time we call this function, we assume that
only one thread is running, so that we can bootstrap the
semaphore code. */
mutex_init (init_lock);
initialized = 1;
}
if (!s)
return; /* We just want to initialize ourself. */
/* First test whether it is really not initialized. */
mutex_lock (init_lock);
if (s->private)
{
mutex_unlock (init_lock);
return;
}
/* Now initialize it. */
mp = xtrymalloc (sizeof *mp);
if (!mp)
{
mutex_unlock (init_lock);
sema_fatal ("out of core while creating critical section lock");
}
mutex_init (*mp);
s->private = mp;
mutex_unlock (init_lock);
}
void void
_gpgme_sema_subsystem_init () _gpgme_sema_subsystem_init ()
{ {
/* FIXME: Posix semaphore support has not yet been implemented */ /* FIXME: we should check that there is only one thread running */
critsect_init (NULL);
} }
void void
_gpgme_sema_cs_enter ( struct critsect_s *s ) _gpgme_sema_cs_enter (struct critsect_s *s)
{ {
if (!s->private)
critsect_init (s);
mutex_lock (*((mutex_t *) s->private));
} }
void void
_gpgme_sema_cs_leave (struct critsect_s *s) _gpgme_sema_cs_leave (struct critsect_s *s)
{ {
if (!s->private)
critsect_init (s);
mutex_unlock (*((mutex_t *) s->private));
} }
void void
_gpgme_sema_cs_destroy ( struct critsect_s *s ) _gpgme_sema_cs_destroy (struct critsect_s *s)
{ {
if (s && s->private)
{
mutex_destroy (*((mutex_t *) s->private));
xfree (s->private);
s->private = NULL;
}
} }
#endif /*!HAVE_DOSISH_SYSTEM*/

View File

@ -1,6 +1,6 @@
/* posix-util.c - Utility functions for Posix /* posix-util.c - Utility functions for Posix
* Copyright (C) 2001 Werner Koch (dd9jn) * Copyright (C) 2001 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -19,10 +19,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#ifndef HAVE_DOSISH_SYSTEM #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -49,5 +48,3 @@ _gpgme_get_gpgsm_path (void)
return NULL; return NULL;
#endif #endif
} }
#endif /*!HAVE_DOSISH_SYSTEM*/

View File

@ -1,40 +0,0 @@
/* syshdr.h - System specfic header files
* Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifndef SYSHDR_H
#define SYSHDR_H
#include <config.h>
#ifdef HAVE_DOSISH_SYSTEM
#include <io.h>
#else
#include <sys/time.h>
#include <unistd.h>
#endif
#endif /* SYSHDR_H */

View File

@ -1,6 +1,6 @@
/* w32-io.c - W32 API I/O functions /* w32-io.c - W32 API I/O functions
* Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -19,20 +19,20 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#ifdef HAVE_DOSISH_SYSTEM #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <windows.h> #include <windows.h>
#include "syshdr.h" #include <io.h>
#include "util.h" #include "util.h"
#include "sema.h" #include "sema.h"
@ -1120,14 +1120,3 @@ _gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds )
return count; return count;
} }
#endif /*HAVE_DOSISH_SYSTEM*/

View File

@ -1,6 +1,6 @@
/* w32-sema.c /* w32-sema.c
* Copyright (C) 2001 Werner Koch (dd9jn) * Copyright (C) 2001 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -19,21 +19,20 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#ifdef HAVE_DOSISH_SYSTEM #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <signal.h> #include <signal.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <windows.h> #include <windows.h>
#include "syshdr.h" #include <io.h>
#include "util.h" #include "util.h"
#include "sema.h" #include "sema.h"
@ -113,12 +112,3 @@ _gpgme_sema_cs_destroy ( struct critsect_s *s )
s->private = NULL; s->private = NULL;
} }
} }
#endif /*HAVE_DOSISH_SYSTEM*/

View File

@ -1,7 +1,7 @@
/* w32-util.c - Utility functions for the W32 API /* w32-util.c - Utility functions for the W32 API
* Copyright (C) 1999 Free Software Foundation, Inc * Copyright (C) 1999 Free Software Foundation, Inc
* Copyright (C) 2001 Werner Koch (dd9jn) * Copyright (C) 2001 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -20,10 +20,9 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/ */
#ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#ifdef HAVE_DOSISH_SYSTEM #endif
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -34,60 +33,61 @@
#include <signal.h> #include <signal.h>
#include <fcntl.h> #include <fcntl.h>
#include <windows.h> #include <windows.h>
#include "syshdr.h" #include <io.h>
#include "util.h" #include "util.h"
/**************** /* Return a string from the Win32 Registry or NULL in case of error.
* Return a string from the Win32 Registry or NULL in case of Caller must release the return value. A NULL for root is an alias
* error. Caller must release the return value. A NULL for root for HKEY_CURRENT_USER. */
* is an alias for HKEY_CURRENT_USER.
*/
static char * static char *
read_w32_registry_string ( const char *root, read_w32_registry_string (const char *root, const char *dir, const char *name)
const char *dir, const char *name )
{ {
HKEY root_key, key_handle; HKEY root_key, key_handle;
DWORD n1, nbytes; DWORD n1, nbytes;
char *result = NULL; char *result = NULL;
if( !root ) if (!root)
root_key = HKEY_CURRENT_USER; root_key = HKEY_CURRENT_USER;
else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) ) else if (!strcmp (root, "HKEY_CLASSES_ROOT"))
root_key = HKEY_CLASSES_ROOT; root_key = HKEY_CLASSES_ROOT;
else if( !strcmp( root, "HKEY_CURRENT_USER" ) ) else if (!strcmp (root, "HKEY_CURRENT_USER"))
root_key = HKEY_CURRENT_USER; root_key = HKEY_CURRENT_USER;
else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) ) else if (!strcmp (root, "HKEY_LOCAL_MACHINE"))
root_key = HKEY_LOCAL_MACHINE; root_key = HKEY_LOCAL_MACHINE;
else if( !strcmp( root, "HKEY_USERS" ) ) else if (!strcmp (root, "HKEY_USERS"))
root_key = HKEY_USERS; root_key = HKEY_USERS;
else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) ) else if (!strcmp (root, "HKEY_PERFORMANCE_DATA"))
root_key = HKEY_PERFORMANCE_DATA; root_key = HKEY_PERFORMANCE_DATA;
else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) ) else if (!strcmp (root, "HKEY_CURRENT_CONFIG"))
root_key = HKEY_CURRENT_CONFIG; root_key = HKEY_CURRENT_CONFIG;
else else
return NULL; return NULL;
if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) if (RegOpenKeyEx (root_key, dir, 0, KEY_READ, &key_handle))
return NULL; /* no need for a RegClose, so return direct */ return NULL; /* No need for a RegClose, so return directly. */
nbytes = 1; nbytes = 1;
if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) if (RegQueryValueEx (key_handle, name, 0, NULL, NULL, &nbytes))
goto leave; goto leave;
result = xtrymalloc( (n1=nbytes+1) ); n1 = nbytes + 1;
if( !result ) result = xtrymalloc (n1);
if (!result)
goto leave; goto leave;
if( RegQueryValueEx( key_handle, name, 0, NULL, result, &n1 ) ) { if (RegQueryValueEx (key_handle, name, 0, NULL, result, &n1))
xfree(result); result = NULL; {
xfree(result);
result = NULL;
goto leave; goto leave;
} }
result[nbytes] = 0; /* make sure it is really a string */ result[nbytes] = 0; /* Make sure it is really a string. */
leave: leave:
RegCloseKey( key_handle ); RegCloseKey (key_handle);
return result; return result;
} }
static const char * static const char *
find_program_in_registry (const char *name) find_program_in_registry (const char *name)
{ {
@ -98,7 +98,7 @@ find_program_in_registry (const char *name)
{ {
int i; int i;
DEBUG1 ("found %s in registry: `%s'", name, program ); DEBUG1 ("found %s in registry: `%s'", name, program);
for (i = 0; program[i]; i++) for (i = 0; program[i]; i++)
{ {
if (program[i] == '/') if (program[i] == '/')
@ -108,6 +108,7 @@ find_program_in_registry (const char *name)
return program; return program;
} }
const char * const char *
_gpgme_get_gpg_path (void) _gpgme_get_gpg_path (void)
{ {
@ -135,6 +136,3 @@ _gpgme_get_gpgsm_path (void)
#endif #endif
return gpgsm_program; return gpgsm_program;
} }
#endif /*HAVE_DOSISH_SYSTEM*/

View File

@ -26,7 +26,6 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include "syshdr.h"
#include "util.h" #include "util.h"
#include "context.h" #include "context.h"

View File

@ -1,6 +1,6 @@
/* wait.h - definitions for wait.c /* wait.h - Definitions for the wait queue interface.
* Copyright (C) 2000 Werner Koch (dd9jn) * Copyright (C) 2000 Werner Koch (dd9jn)
* Copyright (C) 2001 g10 Code GmbH * Copyright (C) 2001, 2002 g10 Code GmbH
* *
* This file is part of GPGME. * This file is part of GPGME.
* *
@ -24,17 +24,11 @@
#include "gpgme.h" #include "gpgme.h"
void _gpgme_remove_proc_from_wait_queue ( int pid ); void _gpgme_remove_proc_from_wait_queue (int pid);
GpgmeError _gpgme_register_pipe_handler ( GpgmeError _gpgme_register_pipe_handler (void *opaque,
void *opaque, int (*handler) (void*, int, int),
int (*handler)(void*,int,int),
void *handler_value, void *handler_value,
int pid, int fd, int inbound ); int pid, int fd, int inbound);
#endif /* WAIT_H */ #endif /* WAIT_H */