From: Marcus Brinkmann Date: Mon, 18 Mar 2002 00:04:06 +0000 (+0000) Subject: 2002-03-17 Marcus Brinkmann X-Git-Tag: V0-3-5~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6cee0a4f3f060029531d7feaf7fe76f5c9d4196c;p=gpgme.git 2002-03-17 Marcus Brinkmann * configure.ac: Add automake conditional HAVE_DOSISH_SYSTEM. gpgme/ 2002-03-18 Marcus Brinkmann * 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. --- diff --git a/ChangeLog b/ChangeLog index 0c8a0bf..2e035a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2002-03-17 Marcus Brinkmann + + * configure.ac: Add automake conditional HAVE_DOSISH_SYSTEM. + 2002-03-04 Werner Koch * configure.ac: Bumbed version to 0.3.4-cvs to continue development. diff --git a/TODO b/TODO index 0e1752c..e7d37fc 100644 --- a/TODO +++ b/TODO @@ -51,7 +51,7 @@ Hey Emacs, this is -*- outline -*- mode! ** Make sure everything is cleaned correctly (esp. test area). * Architecture support -** Implement posix-sema.c +** (nothing currently) Bugs reported by Stephane Corthesy: > BTW, here's another bug: it it not possible to retrieve fingerprints diff --git a/configure.ac b/configure.ac index d28a7a6..59bcc35 100644 --- a/configure.ac +++ b/configure.ac @@ -72,6 +72,7 @@ case "${target}" in # DOS with the DJGPP environment AC_DEFINE(HAVE_DRIVE_LETTERS) AC_DEFINE(HAVE_DOSISH_SYSTEM) + have_dosish_system=yes GPG_DEFAULT='c:\\gnupg\\gpg.exe' GPGSM_DEFAULT='c:\\gnupg\\gpgsm.exe' #component_system='COM+' @@ -82,6 +83,7 @@ dnl GPG_DEFAULT='/usr/bin/gpg' dnl GPGSM_DEFAULT='/usr/bin/gpgsm' ;; esac +AM_CONDITIONAL(HAVE_DOSISH_SYSTEM, test "$have_dosish_system" = "yes") dnl dnl Checks for libraries. diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 619e802..5649ab4 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,30 @@ +2002-03-18 Marcus Brinkmann + + * 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 * util.h [!HAVE_FOPENCOOKIE]: Fixed type. Thanks to Frank Heckenbach. diff --git a/gpgme/Makefile.am b/gpgme/Makefile.am index aa6ef83..9ce45ab 100644 --- a/gpgme/Makefile.am +++ b/gpgme/Makefile.am @@ -35,9 +35,15 @@ AM_CPPFLAGS = -I$(top_srcdir)/assuan libgpgme_la_LIBADD = ../assuan/libassuan.a ../jnlib/libjnlib.a 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 = \ gpgme.h types.h \ - util.h util.c posix-util.c w32-util.c \ + util.h util.c \ context.h ops.h \ data.c recipient.c signers.c \ wait.c wait.h \ @@ -59,8 +65,8 @@ libgpgme_la_SOURCES = \ rungpg.c rungpg.h status-table.h \ engine-gpgsm.c engine-gpgsm.h \ engine.c engine.h \ - sema.h posix-sema.c w32-sema.c \ - syshdr.h io.h posix-io.c w32-io.c \ + sema.h io.h \ + ${system_components} \ gpgme.c debug.c version.c errors.c errors.c : gpgme.h diff --git a/gpgme/data.c b/gpgme/data.c index 911be5c..1805d58 100644 --- a/gpgme/data.c +++ b/gpgme/data.c @@ -27,7 +27,6 @@ #include #include #include -#include "syshdr.h" #include "util.h" #include "context.h" diff --git a/gpgme/gpgme.h b/gpgme/gpgme.h index 12db1ae..f45c41f 100644 --- a/gpgme/gpgme.h +++ b/gpgme/gpgme.h @@ -43,7 +43,7 @@ extern "C" { AM_PATH_GPGME macro) check that this header matches the installed library. Warning: Do not edit the next line. configure will do 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. */ diff --git a/gpgme/mutex.h b/gpgme/mutex.h new file mode 100644 index 0000000..a1cf868 --- /dev/null +++ b/gpgme/mutex.h @@ -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 + +#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 +#include +#include + +/* 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 */ diff --git a/gpgme/posix-io.c b/gpgme/posix-io.c index eaa8950..511ab53 100644 --- a/gpgme/posix-io.c +++ b/gpgme/posix-io.c @@ -1,6 +1,6 @@ /* posix-io.c - Posix I/O functions * 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. * @@ -19,59 +19,62 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#ifdef HAVE_CONFIG_H #include -#ifndef HAVE_DOSISH_SYSTEM - +#endif #include #include #include #include #include +#include +#include +#include #include #include #include -#include -#include -#include "syshdr.h" #include "util.h" #include "io.h" -static struct { - void (*handler)(int,void*); - void *value; +static struct +{ + void (*handler) (int,void*); + void *value; } notify_table[256]; - int -_gpgme_io_read ( int fd, void *buffer, size_t count ) +_gpgme_io_read (int fd, void *buffer, size_t count) { - int nread; - - DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int)count ); - do { - 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 ); + int nread; + + DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int) count); + do + { + nread = read (fd, buffer, count); } - return nread; + 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; } 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; - - 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 { - nwritten = write (fd, buffer, count); - } while (nwritten == -1 && errno == EINTR ); - DEBUG2 ("fd %d: wrote %d bytes\n", fd, (int)nwritten ); - return nwritten; + 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 + { + nwritten = write (fd, buffer, count); + } + while (nwritten == -1 && errno == EINTR); + DEBUG2 ("fd %d: wrote %d bytes\n", fd, (int) nwritten); + return nwritten; } int @@ -92,170 +95,184 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx) return err; } + int -_gpgme_io_close ( int fd ) +_gpgme_io_close (int fd) { - if ( fd == -1 ) - return -1; - /* first call the notify handler */ - DEBUG1 ("closing fd %d", fd ); - if ( fd >= 0 && fd < DIM (notify_table) ) { - if (notify_table[fd].handler) { - notify_table[fd].handler (fd, notify_table[fd].value); - notify_table[fd].handler = NULL; - notify_table[fd].value = NULL; + if (fd == -1) + return -1; + /* First call the notify handler. */ + DEBUG1 ("closing fd %d", fd); + if (fd >= 0 && fd < DIM (notify_table)) + { + if (notify_table[fd].handler) + { + notify_table[fd].handler (fd, notify_table[fd].value); + notify_table[fd].handler = NULL; + notify_table[fd].value = NULL; } } - /* then do the close */ - return close (fd); + /* Then do the close. */ + return close (fd); } + int _gpgme_io_set_close_notify (int fd, void (*handler)(int, void*), void *value) { - assert (fd != -1); - - if ( fd < 0 || fd >= DIM (notify_table) ) - return -1; - DEBUG1 ("set notification for fd %d", fd ); - notify_table[fd].handler = handler; - notify_table[fd].value = value; - return 0; + assert (fd != -1); + + if (fd < 0 || fd >= DIM (notify_table)) + return -1; + DEBUG1 ("set notification for fd %d", fd); + notify_table[fd].handler = handler; + notify_table[fd].value = value; + return 0; } int -_gpgme_io_set_nonblocking ( int fd ) +_gpgme_io_set_nonblocking (int fd) { - int flags; + int flags; - flags = fcntl (fd, F_GETFL, 0); - if (flags == -1) - return -1; - flags |= O_NONBLOCK; - return fcntl (fd, F_SETFL, flags); + flags = fcntl (fd, F_GETFL, 0); + if (flags == -1) + return -1; + flags |= O_NONBLOCK; + return fcntl (fd, F_SETFL, flags); } int -_gpgme_io_spawn ( const char *path, char **argv, - struct spawn_fd_item_s *fd_child_list, - struct spawn_fd_item_s *fd_parent_list ) +_gpgme_io_spawn (const char *path, char **argv, + struct spawn_fd_item_s *fd_child_list, + struct spawn_fd_item_s *fd_parent_list) { - static volatile int fixed_signals; - pid_t pid; - int i; + static volatile int fixed_signals; + pid_t pid; + int i; - if ( !fixed_signals ) { - struct sigaction act; + if (!fixed_signals) + { + 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); + 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); } - fixed_signals = 1; - /* fixme: This is not really MT safe */ + fixed_signals = 1; + /* XXX: This is not really MT safe. */ } - - pid = fork (); - if (pid == -1) - return -1; - - if ( !pid ) { /* 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 ) - close (fd_child_list[i].fd); - } - /* and now dup and close the rest */ - 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, - fd_child_list[i].dup_to ) == -1 ) { - DEBUG1 ("dup2 failed in child: %s\n", strerror (errno)); - _exit (8); + pid = fork (); + if (pid == -1) + return -1; + + if (!pid) + { + /* 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) + close (fd_child_list[i].fd); + + /* And now dup and close the rest. */ + 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, + 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 (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 ) { - int fd = open ( "/dev/null", O_RDWR ); - if ( fd == -1 ) { - DEBUG1 ("can't open `/dev/null': %s\n", strerror (errno) ); - _exit (8); - } - /* 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_stdin || !duped_stderr) + { + int fd = open ("/dev/null", O_RDWR); + if (fd == -1) + { + DEBUG1 ("can't open `/dev/null': %s\n", strerror (errno)); + _exit (8); } - if ( !duped_stderr ) { - if ( dup2 ( fd, 2 ) == -1 ) { - DEBUG1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno)); - _exit (8); + /* 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); } } - close (fd); - } - - 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 (!duped_stderr) + if (dup2 (fd, 2) == -1) + { + DEBUG1 ("dup2(dev/null, 2) failed: %s\n", strerror (errno)); + _exit (8); + } + close (fd); + } - /* .dup_to is not used in the parent list */ - for (i=0; fd_parent_list[i].fd != -1; i++ ) { - close (fd_parent_list[i].fd); - } + 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. */ + + /* .dup_to is not used in the parent list. */ + for (i=0; fd_parent_list[i].fd != -1; i++) + close (fd_parent_list[i].fd); - return (int)pid; + return (int) pid; } 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; - - *r_status = 0; - *r_signal = 0; - if ( waitpid ( pid, &status, hang? 0 : WNOHANG ) == pid ) { - 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; + int status; + + *r_status = 0; + *r_signal = 0; + if (waitpid (pid, &status, hang? 0 : WNOHANG) == pid) + { + 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; + return 0; } + 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,91 +283,97 @@ _gpgme_io_kill ( int pid, int hard ) * >0 = number of signaled fds */ 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 writefds; - int any, i, max_fd, n, count; - struct timeval timeout = { 1, 0 }; /* Use a 1s timeout */ - void *dbg_help = NULL; - - FD_ZERO ( &readfds ); - FD_ZERO ( &writefds ); - max_fd = 0; - - if ( _gpgme_debug_level () > 2 ) - DEBUG_BEGIN (dbg_help, "gpgme:select on [ "); - any = 0; - for ( i=0; i < nfds; i++ ) { - if ( fds[i].fd == -1 ) - continue; - if ( fds[i].frozen ) { - DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd ); - } - 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; + static fd_set readfds; + static fd_set writefds; + int any, i, max_fd, n, count; + struct timeval timeout = { 1, 0 }; /* Use a 1s timeout. */ + void *dbg_help = NULL; + + FD_ZERO (&readfds); + FD_ZERO (&writefds); + max_fd = 0; + + if (_gpgme_debug_level () > 2) + DEBUG_BEGIN (dbg_help, "gpgme:select on [ "); + any = 0; + for (i = 0; i < nfds; i++) + { + if (fds[i].fd == -1) + continue; + if (fds[i].frozen) + DEBUG_ADD1 (dbg_help, "f%d ", fds[i].fd ); + 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; } - else if ( fds[i].for_write ) { - assert ( !FD_ISSET ( fds[i].fd, &writefds ) ); - 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; + else if (fds[i].for_write) + { + assert (!FD_ISSET ( fds[i].fd, &writefds)); + 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; } - fds[i].signaled = 0; + fds[i].signaled = 0; } - DEBUG_END (dbg_help, "]" ); - if ( !any ) - return 0; - - do { - count = select ( max_fd+1, &readfds, &writefds, NULL, &timeout ); - } while ( count < 0 && errno == EINTR); - if ( count < 0 ) { - DEBUG1 ("_gpgme_io_select failed: %s\n", strerror (errno) ); - return -1; /* error */ + DEBUG_END (dbg_help, "]"); + if (!any) + return 0; + + do + { + count = select (max_fd + 1, &readfds, &writefds, NULL, &timeout); + } + while (count < 0 && errno == EINTR); + if (count < 0) + { + DEBUG1 ("_gpgme_io_select failed: %s\n", strerror (errno)); + return -1; /* error */ } - if ( _gpgme_debug_level () > 2 ) - DEBUG_BEGIN (dbg_help, "select OK [ " ); - if (DEBUG_ENABLED(dbg_help)) { - 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 ); + if (_gpgme_debug_level () > 2) + DEBUG_BEGIN (dbg_help, "select OK [ "); + if (DEBUG_ENABLED(dbg_help)) + { + 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); } - DEBUG_END (dbg_help, "]" ); + DEBUG_END (dbg_help, "]"); } - /* 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--; + /* 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--; } } - else if ( fds[i].for_write ) { - if ( FD_ISSET ( fds[i].fd, &writefds ) ) { - fds[i].signaled = 1; - n--; + else if (fds[i].for_write) + { + if (FD_ISSET (fds[i].fd, &writefds)) + { + fds[i].signaled = 1; + n--; } } } - return count; + return count; } - - -#endif /*!HAVE_DOSISH_SYSTEM*/ - - - diff --git a/gpgme/posix-sema.c b/gpgme/posix-sema.c index 3d89520..aff8bbc 100644 --- a/gpgme/posix-sema.c +++ b/gpgme/posix-sema.c @@ -1,6 +1,6 @@ /* posix-sema.c * 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. * @@ -19,53 +19,101 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ - +#ifdef HAVE_CONFIG_H #include -#ifndef HAVE_DOSISH_SYSTEM - +#endif #include #include #include #include #include -#include -#include #include #include -#include "syshdr.h" +#include +#include +#include #include "util.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 _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 -_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 _gpgme_sema_cs_leave (struct critsect_s *s) { + if (!s->private) + critsect_init (s); + mutex_unlock (*((mutex_t *) s->private)); } 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*/ - - - - - diff --git a/gpgme/posix-util.c b/gpgme/posix-util.c index ef59076..337f226 100644 --- a/gpgme/posix-util.c +++ b/gpgme/posix-util.c @@ -1,6 +1,6 @@ /* posix-util.c - Utility functions for Posix * 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. * @@ -19,10 +19,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ - +#ifdef HAVE_CONFIG_H #include -#ifndef HAVE_DOSISH_SYSTEM - +#endif #include #include #include @@ -49,5 +48,3 @@ _gpgme_get_gpgsm_path (void) return NULL; #endif } - -#endif /*!HAVE_DOSISH_SYSTEM*/ diff --git a/gpgme/syshdr.h b/gpgme/syshdr.h deleted file mode 100644 index af5e4ad..0000000 --- a/gpgme/syshdr.h +++ /dev/null @@ -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 - -#ifdef HAVE_DOSISH_SYSTEM -#include -#else -#include -#include -#endif - - -#endif /* SYSHDR_H */ - - - - - diff --git a/gpgme/w32-io.c b/gpgme/w32-io.c index de7e670..602be1f 100644 --- a/gpgme/w32-io.c +++ b/gpgme/w32-io.c @@ -1,6 +1,6 @@ /* w32-io.c - W32 API I/O functions * 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. * @@ -19,20 +19,20 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ +#ifdef HAVE_CONFIG_H #include -#ifdef HAVE_DOSISH_SYSTEM - +#endif #include #include #include #include #include -#include -#include #include #include +#include +#include #include -#include "syshdr.h" +#include #include "util.h" #include "sema.h" @@ -1120,14 +1120,3 @@ _gpgme_io_select ( struct io_select_fd_s *fds, size_t nfds ) return count; } - -#endif /*HAVE_DOSISH_SYSTEM*/ - - - - - - - - - diff --git a/gpgme/w32-sema.c b/gpgme/w32-sema.c index b8507f8..6f701ae 100644 --- a/gpgme/w32-sema.c +++ b/gpgme/w32-sema.c @@ -1,6 +1,6 @@ /* w32-sema.c * 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. * @@ -19,21 +19,20 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ - +#ifdef HAVE_CONFIG_H #include -#ifdef HAVE_DOSISH_SYSTEM - +#endif #include #include #include #include #include -#include -#include #include #include +#include +#include #include -#include "syshdr.h" +#include #include "util.h" #include "sema.h" @@ -113,12 +112,3 @@ _gpgme_sema_cs_destroy ( struct critsect_s *s ) s->private = NULL; } } - - - -#endif /*HAVE_DOSISH_SYSTEM*/ - - - - - diff --git a/gpgme/w32-util.c b/gpgme/w32-util.c index 2cbf6c2..c6e1931 100644 --- a/gpgme/w32-util.c +++ b/gpgme/w32-util.c @@ -1,7 +1,7 @@ /* w32-util.c - Utility functions for the W32 API * Copyright (C) 1999 Free Software Foundation, Inc * 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. * @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ - +#ifdef HAVE_CONFIG_H #include -#ifdef HAVE_DOSISH_SYSTEM - +#endif #include #include #include @@ -34,60 +33,61 @@ #include #include #include -#include "syshdr.h" +#include #include "util.h" -/**************** - * Return a string from the Win32 Registry or NULL in case of - * error. Caller must release the return value. A NULL for root - * is an alias for HKEY_CURRENT_USER. - */ +/* Return a string from the Win32 Registry or NULL in case of error. + Caller must release the return value. A NULL for root is an alias + for HKEY_CURRENT_USER. */ static char * -read_w32_registry_string ( const char *root, - const char *dir, const char *name ) +read_w32_registry_string (const char *root, const char *dir, const char *name) { - HKEY root_key, key_handle; - DWORD n1, nbytes; - char *result = NULL; + HKEY root_key, key_handle; + DWORD n1, nbytes; + char *result = NULL; - if( !root ) - root_key = HKEY_CURRENT_USER; - else if( !strcmp( root, "HKEY_CLASSES_ROOT" ) ) - root_key = HKEY_CLASSES_ROOT; - else if( !strcmp( root, "HKEY_CURRENT_USER" ) ) - root_key = HKEY_CURRENT_USER; - else if( !strcmp( root, "HKEY_LOCAL_MACHINE" ) ) - root_key = HKEY_LOCAL_MACHINE; - else if( !strcmp( root, "HKEY_USERS" ) ) - root_key = HKEY_USERS; - else if( !strcmp( root, "HKEY_PERFORMANCE_DATA" ) ) - root_key = HKEY_PERFORMANCE_DATA; - else if( !strcmp( root, "HKEY_CURRENT_CONFIG" ) ) - root_key = HKEY_CURRENT_CONFIG; - else - return NULL; + if (!root) + root_key = HKEY_CURRENT_USER; + else if (!strcmp (root, "HKEY_CLASSES_ROOT")) + root_key = HKEY_CLASSES_ROOT; + else if (!strcmp (root, "HKEY_CURRENT_USER")) + root_key = HKEY_CURRENT_USER; + else if (!strcmp (root, "HKEY_LOCAL_MACHINE")) + root_key = HKEY_LOCAL_MACHINE; + else if (!strcmp (root, "HKEY_USERS")) + root_key = HKEY_USERS; + else if (!strcmp (root, "HKEY_PERFORMANCE_DATA")) + root_key = HKEY_PERFORMANCE_DATA; + else if (!strcmp (root, "HKEY_CURRENT_CONFIG")) + root_key = HKEY_CURRENT_CONFIG; + else + return NULL; - if( RegOpenKeyEx( root_key, dir, 0, KEY_READ, &key_handle ) ) - return NULL; /* no need for a RegClose, so return direct */ + if (RegOpenKeyEx (root_key, dir, 0, KEY_READ, &key_handle)) + return NULL; /* No need for a RegClose, so return directly. */ - nbytes = 1; - if( RegQueryValueEx( key_handle, name, 0, NULL, NULL, &nbytes ) ) - goto leave; - result = xtrymalloc( (n1=nbytes+1) ); - if( !result ) - goto leave; - if( RegQueryValueEx( key_handle, name, 0, NULL, result, &n1 ) ) { - xfree(result); result = NULL; - goto leave; + nbytes = 1; + if (RegQueryValueEx (key_handle, name, 0, NULL, NULL, &nbytes)) + goto leave; + n1 = nbytes + 1; + result = xtrymalloc (n1); + if (!result) + goto leave; + if (RegQueryValueEx (key_handle, name, 0, NULL, result, &n1)) + { + xfree(result); + result = NULL; + goto leave; } - result[nbytes] = 0; /* make sure it is really a string */ + result[nbytes] = 0; /* Make sure it is really a string. */ - leave: - RegCloseKey( key_handle ); - return result; + leave: + RegCloseKey (key_handle); + return result; } + static const char * find_program_in_registry (const char *name) { @@ -98,7 +98,7 @@ find_program_in_registry (const char *name) { int i; - DEBUG1 ("found %s in registry: `%s'", name, program ); + DEBUG1 ("found %s in registry: `%s'", name, program); for (i = 0; program[i]; i++) { if (program[i] == '/') @@ -108,6 +108,7 @@ find_program_in_registry (const char *name) return program; } + const char * _gpgme_get_gpg_path (void) { @@ -135,6 +136,3 @@ _gpgme_get_gpgsm_path (void) #endif return gpgsm_program; } - - -#endif /*HAVE_DOSISH_SYSTEM*/ diff --git a/gpgme/wait.c b/gpgme/wait.c index e7ce286..6292bde 100644 --- a/gpgme/wait.c +++ b/gpgme/wait.c @@ -26,7 +26,6 @@ #include #include #include -#include "syshdr.h" #include "util.h" #include "context.h" diff --git a/gpgme/wait.h b/gpgme/wait.h index 857e5d5..49737d6 100644 --- a/gpgme/wait.h +++ b/gpgme/wait.h @@ -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) 2001 g10 Code GmbH + * Copyright (C) 2001, 2002 g10 Code GmbH * * This file is part of GPGME. * @@ -24,17 +24,11 @@ #include "gpgme.h" -void _gpgme_remove_proc_from_wait_queue ( int pid ); - -GpgmeError _gpgme_register_pipe_handler ( - void *opaque, - int (*handler)(void*,int,int), - void *handler_value, - int pid, int fd, int inbound ); - -#endif /* WAIT_H */ - - - +void _gpgme_remove_proc_from_wait_queue (int pid); +GpgmeError _gpgme_register_pipe_handler (void *opaque, + int (*handler) (void*, int, int), + void *handler_value, + int pid, int fd, int inbound); +#endif /* WAIT_H */