From 6126f27cccbc426dd18ebc14f3dc12bf70813579 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 20 Aug 2003 20:20:46 +0000 Subject: [PATCH] 2003-08-18 Marcus Brinkmann *configure.ac (AM_PATH_GPG_ERROR): Require 0.3. assuan/ See README.1st. gpgme/ 2003-08-19 Marcus Brinkmann The ath files (ath.h, ath.c, ath-pth.c, ath-pthread.c, ath-compat.c, ath-pth-compat.c and ath-pthread-compat.c) have been updated to have better thread support, and the Makefile.am was changed to reflect that. * util.h [!HAVE_FOPENCOOKIE]: Remove fopencookie declaration. * engine-gpgsm.c (gpgsm_assuan_simple_command): Set ERR to return value of status_fnc. * rungpg.c (start): Return SAVED_ERRNO, not errno. --- trunk/ChangeLog | 1 + trunk/NEWS | 10 ++ trunk/TODO | 6 +- trunk/assuan/Makefile.am | 1 + trunk/assuan/README.1st | 19 ++++ trunk/assuan/assuan-io.c | 17 +++ trunk/assuan/assuan.h | 117 ++++++++++++++++++++ trunk/configure.ac | 15 ++- trunk/gpgme/ChangeLog | 16 +++ trunk/gpgme/Makefile.am | 79 ++++++++++---- trunk/gpgme/ath-pth-compat.c | 123 +++++++++++++++++++++ trunk/gpgme/ath-pth.c | 170 +++++++++++++++++++---------- trunk/gpgme/ath-pthread-compat.c | 104 ++++++++++++++++++ trunk/gpgme/ath-pthread.c | 179 ++++++++++++++++++++++--------- trunk/gpgme/ath.c | 155 +++++++++++++------------- trunk/gpgme/ath.h | 90 +++++++++------- trunk/gpgme/engine-gpgsm.c | 4 +- trunk/gpgme/rungpg.c | 2 +- trunk/gpgme/util.h | 16 +-- 19 files changed, 850 insertions(+), 274 deletions(-) create mode 100644 trunk/gpgme/ath-pth-compat.c create mode 100644 trunk/gpgme/ath-pthread-compat.c diff --git a/trunk/ChangeLog b/trunk/ChangeLog index 676701c..4cdc4fb 100644 --- a/trunk/ChangeLog +++ b/trunk/ChangeLog @@ -3,6 +3,7 @@ * configure.ac: If building Assuan, check for funopen and fopencookie, and make isascii, putc_unlocked and memrchr replacement functions. + (AM_PATH_GPG_ERROR): Require 0.3. 2003-07-31 Marcus Brinkmann diff --git a/trunk/NEWS b/trunk/NEWS index 3e66093..34e461e 100644 --- a/trunk/NEWS +++ b/trunk/NEWS @@ -1,6 +1,16 @@ Noteworthy changes in version 0.4.3 (unreleased) ------------------------------------------------ + * libgpgme should not be used for threaded programs anymore. This + never worked reliably in all cases, because you had to + be careful about the linking order and libtool wouldn't do that for + you automatically. Instead, now you have to link against + libgpgme-pthread for applications using pthread and libgpgme-pth for + applications using GNU Pth. + + The old code for automagically detecting the thread library is + still part of libgpgme, but it is DEPRECATED. + * gpgme_get_key fails with GPG_ERR_AMBIGUOUS_NAME if the key ID provided was not unique, instead returning the first matching key. diff --git a/trunk/TODO b/trunk/TODO index 9c71ac6..57da7f0 100644 --- a/trunk/TODO +++ b/trunk/TODO @@ -1,12 +1,14 @@ Hey Emacs, this is -*- outline -*- mode! * Before release: -** Nothing. +** Write --thread option for gpgme-config. +** Document new thread support. * ABI's to break: ** I/O and User Data could be made extensible. But this can be done without breaking the ABI hopefully. ** Compatibility interfaces that can be removed in future versions: +*** ath compatibility modules. *** gpgme_data_new_from_filepart *** gpgme_data_new_from_file *** gpgme_data_new_with_read_cb @@ -24,6 +26,7 @@ Hey Emacs, this is -*- outline -*- mode! *** All Gpgme* typedefs. * Thread support: +** When GNU Pth supports sendmsg/recvmsg, wrap them properly. ** Build thread modules for static linking (which just suck in the desired symbols the hard way). !! ** Ordering the libs is important, but libtool gets it wrong. Argh. @@ -76,6 +79,7 @@ Hey Emacs, this is -*- outline -*- mode! * Operations ** If an operation failed, make sure that the result functions don't return corrupt partial information. !!! + NOTE: The EOF status handler is not called in this case !!! ** If no passphrase cb is installed, status handler is not run even if password is required by crypto engine. !! ** Export status handler need much more work. !!! diff --git a/trunk/assuan/Makefile.am b/trunk/assuan/Makefile.am index db29d18..8c4d88c 100644 --- a/trunk/assuan/Makefile.am +++ b/trunk/assuan/Makefile.am @@ -26,6 +26,7 @@ MOSTLYCLEANFILES = assuan-errors.c noinst_LTLIBRARIES = libassuan.la +AM_CPPFLAGS = -D_ASSUAN_IN_GPGME_BUILD_ASSUAN #libassuan_la_LDFLAGS = libassuan_la_SOURCES = \ diff --git a/trunk/assuan/README.1st b/trunk/assuan/README.1st index b7d5311..7b6074f 100644 --- a/trunk/assuan/README.1st +++ b/trunk/assuan/README.1st @@ -1,3 +1,22 @@ This is a modified copy of the libassuan library. Don't modify it, but instead modify the original Assuan library and merge the changes back into this copy. + +The changes to the original libassuan, that have to preserved when +updating this directory, are: + +* Makefile.am +** Build the library with libtool as a convenience library, which can + be linked into the shared library GPGME. +** Do not install the library or the header file. +** Define -D_ASSUAN_IN_GPGME_BUILD_ASSUAN to wrap some POSIX functions + with ATH replacements. + +* assuan.h +** Define _ASSUAN_IN_GPGME to enable GPGME specific code. +** Put all exported Assuan functions in the _gpgme namespace. +** Also wrap all system functions that are wrapped by GNU Pth to + _gpgme wrappers. + +* assuan-io.c +** Don't try to support GNU Pth here. diff --git a/trunk/assuan/assuan-io.c b/trunk/assuan/assuan-io.c index b10571b..5dca009 100644 --- a/trunk/assuan/assuan-io.c +++ b/trunk/assuan/assuan-io.c @@ -22,6 +22,21 @@ #include #include +#ifdef _ASSUAN_IN_GPGME +ssize_t +_assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size) +{ + return read (ctx->inbound.fd, buffer, size); +} + +ssize_t +_assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer, size_t size) +{ + return write (ctx->outbound.fd, buffer, size); +} + +#else + extern ssize_t pth_read (int fd, void *buffer, size_t size); extern ssize_t pth_write (int fd, const void *buffer, size_t size); @@ -39,3 +54,5 @@ _assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer, size_t size) { return (pth_write ? pth_write : write) (ctx->outbound.fd, buffer, size); } + +#endif diff --git a/trunk/assuan/assuan.h b/trunk/assuan/assuan.h index f898c26..05f0212 100644 --- a/trunk/assuan/assuan.h +++ b/trunk/assuan/assuan.h @@ -25,10 +25,127 @@ #include #include +#include + +#define _ASSUAN_IN_GPGME +#ifdef _ASSUAN_IN_GPGME +#define _ASSUAN_EXT_SYM_PREFIX _gpgme_ + +#ifdef _ASSUAN_IN_GPGME_BUILD_ASSUAN +int _gpgme_io_read (int fd, void *buffer, size_t count); +int _gpgme_io_write (int fd, const void *buffer, size_t count); +ssize_t _gpgme_ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, + struct timeval *timeout); +ssize_t _gpgme_ath_waitpid (pid_t pid, int *status, int options); +int _gpgme_ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr); +int _gpgme_ath_connect (int s, struct sockaddr *addr, socklen_t length); +int _gpgme_ath_sendmsg (int s, const struct msghdr *msg, int flags); +int _gpgme_ath_recvmsg (int s, struct msghdr *msg, int flags); + +#define read _gpgme_io_read +#define write _gpgme_io_write +#define waitpid _gpgme_ath_waitpid +#define select _gpgme_ath_select +#define accept _gpgme_ath_accept +#define connect _gpgme_ath_connect +#define sendmsg _gpgme_ath_sendmsg +#define recvmsg _gpgme_ath_recvmsg +#endif +#endif + +#ifdef _ASSUAN_EXT_SYM_PREFIX +#define _ASSUAN_PREFIX1(x,y) x ## y +#define _ASSUAN_PREFIX2(x,y) _ASSUAN_PREFIX1(x,y) +#define _ASSUAN_PREFIX(x) _ASSUAN_PREFIX2(_ASSUAN_EXT_SYM_PREFIX,x) +#define assuan_ _ASSUAN_PREFIX(assuan_) +#define assuan_register_command _ASSUAN_PREFIX(assuan_register_command) +#define assuan_register_bye_notify _ASSUAN_PREFIX(assuan_register_bye_notify) +#define assuan_register_reset_notify \ + _ASSUAN_PREFIX(assuan_register_reset_notify) +#define assuan_register_cancel_notify \ + _ASSUAN_PREFIX(assuan_register_cancel_notify) +#define assuan_register_input_notify \ + _ASSUAN_PREFIX(assuan_register_input_notify) +#define assuan_register_output_notify \ + _ASSUAN_PREFIX(assuan_register_output_notify) +#define assuan_register_option_handler \ + _ASSUAN_PREFIX(assuan_register_option_handler) +#define assuan_process _ASSUAN_PREFIX(assuan_process) +#define assuan_process_next _ASSUAN_PREFIX(assuan_process_next) +#define assuan_get_active_fds _ASSUAN_PREFIX(assuan_get_active_fds) +#define assuan_get_data_fp _ASSUAN_PREFIX(assuan_get_data_fp) +#define assuan_set_okay_line _ASSUAN_PREFIX(assuan_set_okay_line) +#define assuan_write_status _ASSUAN_PREFIX(assuan_write_status) +#define assuan_command_parse_fd _ASSUAN_PREFIX(assuan_command_parse_fd) +#define assuan_set_hello_line _ASSUAN_PREFIX(assuan_set_hello_line) +#define assuan_accept _ASSUAN_PREFIX(assuan_accept) +#define assuan_get_input_fd _ASSUAN_PREFIX(assuan_get_input_fd) +#define assuan_get_output_fd _ASSUAN_PREFIX(assuan_get_output_fd) +#define assuan_close_input_fd _ASSUAN_PREFIX(assuan_close_input_fd) +#define assuan_close_output_fd _ASSUAN_PREFIX(assuan_close_output_fd) +#define assuan_init_pipe_server _ASSUAN_PREFIX(assuan_init_pipe_server) +#define assuan_deinit_server _ASSUAN_PREFIX(assuan_deinit_server) +#define assuan_init_socket_server _ASSUAN_PREFIX(assuan_init_socket_server) +#define assuan_init_connected_socket_server \ + _ASSUAN_PREFIX(assuan_init_connected_socket_server) +#define assuan_pipe_connect _ASSUAN_PREFIX(assuan_pipe_connect) +#define assuan_socket_connect _ASSUAN_PREFIX(assuan_socket_connect) +#define assuan_domain_connect _ASSUAN_PREFIX(assuan_domain_connect) +#define assuan_init_domain_server _ASSUAN_PREFIX(assuan_init_domain_server) +#define assuan_disconnect _ASSUAN_PREFIX(assuan_disconnect) +#define assuan_get_pid _ASSUAN_PREFIX(assuan_get_pid) +#define assuan_transact _ASSUAN_PREFIX(assuan_transact) +#define assuan_inquire _ASSUAN_PREFIX(assuan_inquire) +#define assuan_read_line _ASSUAN_PREFIX(assuan_read_line) +#define assuan_pending_line _ASSUAN_PREFIX(assuan_pending_line) +#define assuan_write_line _ASSUAN_PREFIX(assuan_write_line) +#define assuan_send_data _ASSUAN_PREFIX(assuan_send_data) +#define assuan_sendfd _ASSUAN_PREFIX(assuan_sendfd) +#define assuan_receivefd _ASSUAN_PREFIX(assuan_receivefd) +#define assuan_set_malloc_hooks _ASSUAN_PREFIX(assuan_set_malloc_hooks) +#define assuan_set_log_stream _ASSUAN_PREFIX(assuan_set_log_stream) +#define assuan_set_error _ASSUAN_PREFIX(assuan_set_error) +#define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer) +#define assuan_get_pointer _ASSUAN_PREFIX(assuan_get_pointer) +#define assuan_begin_confidential _ASSUAN_PREFIX(assuan_begin_confidential) +#define assuan_end_confidential _ASSUAN_PREFIX(assuan_end_confidential) +#define assuan_strerror _ASSUAN_PREFIX(assuan_strerror) +#define assuan_set_assuan_log_stream \ + _ASSUAN_PREFIX(assuan_set_assuan_log_stream) +#define assuan_get_assuan_log_stream \ + _ASSUAN_PREFIX(assuan_get_assuan_log_stream) +#define assuan_get_assuan_log_prefix \ + _ASSUAN_PREFIX(assuan_get_assuan_log_prefix) + +/* And now the internal functions, argh... */ +#define _assuan_read_line _ASSUAN_PREFIX(_assuan_read_line) +#define _assuan_cookie_write_data _ASSUAN_PREFIX(_assuan_cookie_write_data) +#define _assuan_cookie_write_flush _ASSUAN_PREFIX(_assuan_cookie_write_flush) +#define _assuan_read_from_server _ASSUAN_PREFIX(_assuan_read_from_server) +#define _assuan_domain_init _ASSUAN_PREFIX(_assuan_domain_init) +#define _assuan_register_std_commands \ + _ASSUAN_PREFIX(_assuan_register_std_commands) +#define _assuan_simple_read _ASSUAN_PREFIX(_assuan_simple_read) +#define _assuan_simple_write _ASSUAN_PREFIX(_assuan_simple_write) +#define _assuan_simple_read _ASSUAN_PREFIX(_assuan_simple_read) +#define _assuan_simple_write _ASSUAN_PREFIX(_assuan_simple_write) +#define _assuan_new_context _ASSUAN_PREFIX(_assuan_new_context) +#define _assuan_release_context _ASSUAN_PREFIX(_assuan_release_context) +#define _assuan_malloc _ASSUAN_PREFIX(_assuan_malloc) +#define _assuan_realloc _ASSUAN_PREFIX(_assuan_realloc) +#define _assuan_calloc _ASSUAN_PREFIX(_assuan_calloc) +#define _assuan_free _ASSUAN_PREFIX(_assuan_free) +#define _assuan_log_print_buffer _ASSUAN_PREFIX(_assuan_log_print_buffer) +#define _assuan_log_sanitized_string \ + _ASSUAN_PREFIX(_assuan_log_sanitized_string) + +#endif + #ifdef __cplusplus extern "C" { #endif + typedef enum { diff --git a/trunk/configure.ac b/trunk/configure.ac index 1515a0c..e8cebc2 100644 --- a/trunk/configure.ac +++ b/trunk/configure.ac @@ -157,7 +157,7 @@ if test "$ac_cv_func_vasprintf" != yes; then GNUPG_CHECK_VA_COPY fi -AM_PATH_GPG_ERROR(0.1,, AC_MSG_ERROR([libgpg-error was not found])) +AM_PATH_GPG_ERROR(0.3,, AC_MSG_ERROR([libgpg-error was not found])) AC_DEFINE(GPG_ERR_SOURCE_DEFAULT, GPG_ERR_SOURCE_GPGME, [The default error source for GPGME.]) @@ -243,24 +243,23 @@ fi AM_CONDITIONAL(BUILD_COMPLUS, test "$component_system" = "COM+") -dnl Make the version number in gpgme/gpgme.h the same as the one here. -dnl (this is easier than to have a *.in file just for one substitution) +# Make the version number in gpgme/gpgme.h the same as the one here. +# (this is easier than to have a *.in file just for one substitution) GNUPG_FIX_HDR_VERSION(gpgme/gpgme.h, GPGME_VERSION) -dnl Substitution used for gpgme-config +# Substitution used for gpgme-config GPGME_CONFIG_LIBS="-lgpgme" GPGME_CONFIG_CFLAGS="" AC_SUBST(GPGME_CONFIG_LIBS) AC_SUBST(GPGME_CONFIG_CFLAGS) -dnl Frob'da Variables +# Frob'da Variables LTLIBOBJS=`echo "$LIB@&t@OBJS" | sed 's,\.[[^.]]* ,.lo ,g;s,\.[[^.]]*$,.lo,'` AC_SUBST(LTLIBOBJS) -dnl -dnl Create config files -dnl +# +# Create config files AC_CONFIG_FILES(Makefile assuan/Makefile gpgme/Makefile tests/Makefile tests/gpg/Makefile tests/gpgsm/Makefile diff --git a/trunk/gpgme/ChangeLog b/trunk/gpgme/ChangeLog index 34667d2..c860269 100644 --- a/trunk/gpgme/ChangeLog +++ b/trunk/gpgme/ChangeLog @@ -1,3 +1,19 @@ +2003-08-19 Marcus Brinkmann + + The ath files (ath.h, ath.c, ath-pth.c, ath-pthread.c, + ath-compat.c, ath-pth-compat.c and ath-pthread-compat.c) have been + updated to have better thread support, and the Makefile.am was + changed to reflect that. + + * util.h [!HAVE_FOPENCOOKIE]: Remove fopencookie declaration. + * engine-gpgsm.c (gpgsm_assuan_simple_command): Set ERR to return + value of status_fnc. + * rungpg.c (start): Return SAVED_ERRNO, not errno. + +2003-08-18 Marcus Brinkmann + + * rungpg.c (start): Use saved_errno instead errno. + 2003-08-18 Marcus Brinkmann * funopen.c, putc_unlocked.c, isascii.c, memrchr.c: New files. diff --git a/trunk/gpgme/Makefile.am b/trunk/gpgme/Makefile.am index d86229c..49c17e8 100644 --- a/trunk/gpgme/Makefile.am +++ b/trunk/gpgme/Makefile.am @@ -26,7 +26,20 @@ bin_SCRIPTS = gpgme-config m4datadir = $(datadir)/aclocal m4data_DATA = gpgme.m4 include_HEADERS = gpgme.h -lib_LTLIBRARIES = libgpgme.la + +if HAVE_PTHREAD +ltlib_gpgme_pthread = libgpgme-pthread.la +else +ltlib_gpgme_pthread = +endif +if HAVE_PTH +ltlib_gpgme_pth = libgpgme-pth.la +else +ltlib_gpgme_pth = +endif + +noinst_LTLIBRARIES = libgpgme-real.la +lib_LTLIBRARIES = libgpgme.la $(ltlib_gpgme_pthread) $(ltlib_gpgme_pth) if HAVE_LD_VERSION_SCRIPT libgpgme_version_script_cmd = -Wl,--version-script=$(srcdir)/libgpgme.vers @@ -34,9 +47,6 @@ else libgpgme_version_script_cmd = endif -libgpgme_la_LDFLAGS = $(libgpgme_version_script_cmd) -version-info \ - @LIBGPGME_LT_CURRENT@:@LIBGPGME_LT_REVISION@:@LIBGPGME_LT_AGE@ - if BUILD_ASSUAN assuan_cppflags = -I$(top_srcdir)/assuan assuan_libobjs = ../assuan/libassuan.la @@ -45,22 +55,10 @@ assuan_cppflags = assuan_libobjs = endif -if HAVE_PTHREAD -ath_components_pthread = ath-pthread.c -else -ath_components_pthread = -endif -if HAVE_PTH -ath_components_pth = ath-pth.c -else -ath_components_pth = -endif -ath_components = ath.h ath.c ${ath_components_pthread} ${ath_components_pth} - if HAVE_DOSISH_SYSTEM system_components = w32-util.c w32-sema.c w32-io.c else -system_components = ${ath_components} posix-util.c posix-sema.c posix-io.c +system_components = ath.h posix-util.c posix-sema.c posix-io.c endif if HAVE_GPGSM @@ -69,7 +67,7 @@ else gpgsm_components = endif -libgpgme_la_SOURCES = \ +libgpgme_real_la_SOURCES = \ gpgme.h util.h conversion.c context.h ops.h \ data.h data.c data-fd.c data-stream.c data-mem.c data-user.c \ data-compat.c \ @@ -81,13 +79,48 @@ libgpgme_la_SOURCES = \ key.c keylist.c trust-item.c trustlist.c \ import.c export.c genkey.c delete.c edit.c \ engine.h engine-backend.h engine.c rungpg.c status-table.h \ - ${gpgsm_components} sema.h io.h ${system_components} \ + $(gpgsm_components) sema.h io.h $(system_components) \ debug.c debug.h gpgme.c version.c error.c -AM_CPPFLAGS = ${assuan_cppflags} @GPG_ERROR_CFLAGS@ -libgpgme_la_DEPENDENCIES = ${assuan_libobjs} @LTLIBOBJS@ \ - $(srcdir)/libgpgme.vers -libgpgme_la_LIBADD = ${assuan_libobjs} @LTLIBOBJS@ @GPG_ERROR_LIBS@ +# libgpgme_la_SOURCES = ath.h ath.c +if HAVE_PTH + ath_pth_src = ath-pth-compat.c +else + ath_pth_src = +endif +if HAVE_PTHREAD + ath_pthread_src = ath-pthread-compat.c +else + ath_pthread_src = +endif +libgpgme_la_SOURCES = ath.h ath-compat.c $(ath_pth_src) $(ath_pthread_src) +libgpgme_pthread_la_SOURCES = ath.h ath-pthread.c +libgpgme_pth_la_SOURCES = ath.h ath-pth.c + +AM_CPPFLAGS = $(assuan_cppflags) @GPG_ERROR_CFLAGS@ + +libgpgme_la_LDFLAGS = $(libgpgme_version_script_cmd) -version-info \ + @LIBGPGME_LT_CURRENT@:@LIBGPGME_LT_REVISION@:@LIBGPGME_LT_AGE@ +libgpgme_la_DEPENDENCIES = libgpgme-real.la $(assuan_libobjs) \ + @LTLIBOBJS@ $(srcdir)/libgpgme.vers +libgpgme_la_LIBADD = libgpgme-real.la $(assuan_libobjs) @LTLIBOBJS@ \ + @GPG_ERROR_LIBS@ + +libgpgme_pthread_la_LDFLAGS = $(libgpgme_version_script_cmd) -version-info \ + @LIBGPGME_LT_CURRENT@:@LIBGPGME_LT_REVISION@:@LIBGPGME_LT_AGE@ +libgpgme_pthread_la_DEPENDENCIES = libgpgme-real.la $(assuan_libobjs) \ + @LTLIBOBJS@ $(srcdir)/libgpgme.vers +libgpgme_pthread_la_LIBADD = libgpgme-real.la $(assuan_libobjs) @LTLIBOBJS@ \ + -lpthread @GPG_ERROR_LIBS@ + +libgpgme_pth_la_CPPFLAGS = $(AM_CPPFLAGS) @PTH_CPPFLAGS@ +libgpgme_pth_la_LDFLAGS = @PTH_LDFLAGS@ \ + $(libgpgme_version_script_cmd) -version-info \ + @LIBGPGME_LT_CURRENT@:@LIBGPGME_LT_REVISION@:@LIBGPGME_LT_AGE@ +libgpgme_pth_la_DEPENDENCIES = libgpgme-real.la $(assuan_libobjs) \ + @LTLIBOBJS@ $(srcdir)/libgpgme.vers +libgpgme_pth_la_LIBADD = libgpgme-real.la $(assuan_libobjs) @LTLIBOBJS@ \ + @PTH_LIBS@ @GPG_ERROR_LIBS@ status-table.h : gpgme.h $(srcdir)/mkstatus < $(srcdir)/gpgme.h > status-table.h diff --git a/trunk/gpgme/ath-pth-compat.c b/trunk/gpgme/ath-pth-compat.c new file mode 100644 index 0000000..75b6fb4 --- /dev/null +++ b/trunk/gpgme/ath-pth-compat.c @@ -0,0 +1,123 @@ +/* ath-pth.c - Pth module for self-adapting thread-safeness 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 + */ + +#include +#include +#include + +#include "ath.h" + +#pragma weak pth_mutex_init +#pragma weak pth_mutex_acquire +#pragma weak pth_mutex_release +#pragma weak pth_read +#pragma weak pth_write +#pragma weak pth_select +#pragma weak pth_waitpid +#pragma weak pth_accept +#pragma weak pth_connect + +/* The lock we take while checking for lazy lock initialization. */ +static pth_mutex_t check_init_lock = PTH_MUTEX_INIT; + +/* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if + it is not already initialized. */ +static int +mutex_pth_init (void **priv, int just_check) +{ + int err = 0; + + if (just_check) + pth_mutex_acquire (&check_init_lock, 0, NULL); + if (!*priv || !just_check) + { + pth_mutex_t *lock = malloc (sizeof (pth_mutex_t)); + if (!lock) + err = ENOMEM; + if (!err) + { + err = pth_mutex_init (lock); + if (err == FALSE) + err = errno; + else + err = 0; + + if (err) + free (lock); + else + *priv = lock; + } + } + if (just_check) + pth_mutex_release (&check_init_lock); + return err; +} + + +static int +mutex_pth_destroy (void *priv) +{ + free (priv); + return 0; +} + + +static int +mutex_pth_lock (void *priv) +{ + int ret = pth_mutex_acquire ((pth_mutex_t *) priv, 0, NULL); + return ret == FALSE ? errno : 0; +} + + +static int +mutex_pth_unlock (void *priv) +{ + int ret = pth_mutex_release ((pth_mutex_t *) priv); + return ret == FALSE ? errno : 0; +} + + +static struct ath_ops ath_pth_ops = + { + mutex_pth_init, + mutex_pth_destroy, + mutex_pth_lock, + mutex_pth_unlock, + pth_read, + pth_write, + pth_select, + pth_waitpid, + pth_accept, + pth_connect, + NULL, /* FIXME: When GNU PTh has sendmsg. */ + NULL /* FIXME: When GNU PTh has recvmsg. */ + }; + + +struct ath_ops * +ath_pth_available (void) +{ + if (pth_mutex_init && pth_mutex_acquire && pth_mutex_release + && pth_read && pth_write && pth_select && pth_waitpid) + return &ath_pth_ops; + else + return 0; +} diff --git a/trunk/gpgme/ath-pth.c b/trunk/gpgme/ath-pth.c index 73c3894..e58d5de 100644 --- a/trunk/gpgme/ath-pth.c +++ b/trunk/gpgme/ath-pth.c @@ -1,36 +1,34 @@ /* ath-pth.c - Pth module for self-adapting thread-safeness 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 - */ + Copyright (C) 2002, 2003 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. */ + + +#ifdef HAVE_CONFIG_H +#include +#endif #include #include + #include #include "ath.h" -#pragma weak pth_mutex_init -#pragma weak pth_mutex_acquire -#pragma weak pth_mutex_release -#pragma weak pth_read -#pragma weak pth_write -#pragma weak pth_select -#pragma weak pth_waitpid /* The lock we take while checking for lazy lock initialization. */ static pth_mutex_t check_init_lock = PTH_MUTEX_INIT; @@ -38,7 +36,7 @@ static pth_mutex_t check_init_lock = PTH_MUTEX_INIT; /* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if it is not already initialized. */ static int -mutex_pth_init (void **priv, int just_check) +mutex_pth_init (ath_mutex_t *priv, int just_check) { int err = 0; @@ -60,7 +58,7 @@ mutex_pth_init (void **priv, int just_check) if (err) free (lock); else - *priv = lock; + *priv = (ath_mutex_t) lock; } } if (just_check) @@ -69,49 +67,111 @@ mutex_pth_init (void **priv, int just_check) } -static int -mutex_pth_destroy (void *priv) +void +ath_init (void) { - free (priv); - return 0; + /* Nothing to do. */ } -static int -mutex_pth_lock (void *priv) +int +ath_mutex_init (ath_mutex_t *lock) { - int ret = pth_mutex_acquire ((pth_mutex_t *) priv, 0, NULL); + return mutex_pth_init (lock, 0); +} + + +int +ath_mutex_destroy (ath_mutex_t *lock) +{ + int err = mutex_pth_init (lock, 1); + if (!err) + { + /* GNU Pth has no destructor function. */ + free (*lock); + } + return err; +} + + +int +ath_mutex_lock (ath_mutex_t *lock) +{ + int ret = mutex_pth_init (lock, 1); + if (ret) + return ret; + + ret = pth_mutex_acquire ((pth_mutex_t *) *lock, 0, NULL); return ret == FALSE ? errno : 0; } -static int -mutex_pth_unlock (void *priv) +int +ath_mutex_unlock (ath_mutex_t *lock) { - int ret = pth_mutex_release ((pth_mutex_t *) priv); + int ret = mutex_pth_init (lock, 1); + if (ret) + return ret; + + ret = pth_mutex_release ((pth_mutex_t *) *lock); return ret == FALSE ? errno : 0; } -static struct ath_ops ath_pth_ops = - { - mutex_pth_init, - mutex_pth_destroy, - mutex_pth_lock, - mutex_pth_unlock, - pth_read, - pth_write, - pth_select, - pth_waitpid - }; +ssize_t +ath_read (int fd, void *buf, size_t nbytes) +{ + return pth_read (fd, buf, nbytes); +} + + +ssize_t +ath_write (int fd, const void *buf, size_t nbytes) +{ + return pth_write (fd, buf, nbytes); +} + +ssize_t +ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, + struct timeval *timeout) +{ + return pth_select (nfd, rset, wset, eset, timeout); +} -struct ath_ops * -ath_pth_available (void) + +ssize_t +ath_waitpid (pid_t pid, int *status, int options) { - if (pth_mutex_init && pth_mutex_acquire && pth_mutex_release - && pth_read && pth_write && pth_select && pth_waitpid) - return &ath_pth_ops; - else - return 0; + return pth_waitpid (pid, status, options); } + + +int +ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr) +{ + return pth_accept (s, addr, length_ptr); +} + + +int +ath_connect (int s, struct sockaddr *addr, socklen_t length) +{ + return pth_connect (s, addr, length); +} + +int +ath_sendmsg (int s, const struct msghdr *msg, int flags) +{ + /* FIXME: GNU Pth is missing pth_sendmsg. */ + return sendmsg (s, msg, flags); +} + + +int +ath_recvmsg (int s, struct msghdr *msg, int flags) +{ + /* FIXME: GNU Pth is missing pth_recvmsg. */ + return recvmsg (s, msg, flags); +} + diff --git a/trunk/gpgme/ath-pthread-compat.c b/trunk/gpgme/ath-pthread-compat.c new file mode 100644 index 0000000..365cf97 --- /dev/null +++ b/trunk/gpgme/ath-pthread-compat.c @@ -0,0 +1,104 @@ +/* ath-pthread.c - pthread module for self-adapting thread-safeness 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 + */ + +#include +#include +#include + +#include "ath.h" + +/* Need to include pthread_create in our check, as the GNU C library + has the pthread_mutex_* functions in their public interface. */ +#pragma weak pthread_create +#pragma weak pthread_mutex_init +#pragma weak pthread_mutex_destroy +#pragma weak pthread_mutex_lock +#pragma weak pthread_mutex_unlock + +/* The lock we take while checking for lazy lock initialization. */ +static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER; + +/* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if + it is not already initialized. */ +static int +mutex_pthread_init (void **priv, int just_check) +{ + int err = 0; + + if (just_check) + pthread_mutex_lock (&check_init_lock); + if (!*priv || !just_check) + { + pthread_mutex_t *lock = malloc (sizeof (pthread_mutex_t)); + if (!lock) + err = ENOMEM; + if (!err) + { + err = pthread_mutex_init (lock, NULL); + if (err) + free (lock); + else + *priv = lock; + } + } + if (just_check) + pthread_mutex_unlock (&check_init_lock); + return err; +} + + +static int +mutex_pthread_destroy (void *priv) +{ + int err = pthread_mutex_destroy ((pthread_mutex_t *) priv); + free (priv); + return err; +} + + +static struct ath_ops ath_pthread_ops = + { + mutex_pthread_init, + mutex_pthread_destroy, + (int (*) (void *)) pthread_mutex_lock, + (int (*) (void *)) pthread_mutex_unlock, + NULL, /* read */ + NULL, /* write */ + NULL, /* select */ + NULL, /* waitpid */ + NULL, /* accept */ + NULL, /* connect */ + NULL, /* sendmsg */ + NULL /* recvmsg */ + }; + + +struct ath_ops * +ath_pthread_available (void) +{ + /* Need to include pthread_create in our check, as the GNU C library + has the pthread_mutex_* functions in their public interface. */ + if (pthread_create + && pthread_mutex_init && pthread_mutex_destroy + && pthread_mutex_lock && pthread_mutex_unlock) + return &ath_pthread_ops; + else + return 0; +} diff --git a/trunk/gpgme/ath-pthread.c b/trunk/gpgme/ath-pthread.c index 6c74efd..db5ade6 100644 --- a/trunk/gpgme/ath-pthread.c +++ b/trunk/gpgme/ath-pthread.c @@ -1,36 +1,42 @@ /* ath-pthread.c - pthread module for self-adapting thread-safeness 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 - */ + Copyright (C) 2002, 2003 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. */ + + +#ifdef HAVE_CONFIG_H +#include +#endif #include #include +#include +#ifdef HAVE_SYS_SELECT_H +# include +#else +# include +#endif +#include +#include + #include #include "ath.h" -/* Need to include pthread_create in our check, as the GNU C library - has the pthread_mutex_* functions in their public interface. */ -#pragma weak pthread_create -#pragma weak pthread_mutex_init -#pragma weak pthread_mutex_destroy -#pragma weak pthread_mutex_lock -#pragma weak pthread_mutex_unlock /* The lock we take while checking for lazy lock initialization. */ static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER; @@ -38,7 +44,7 @@ static pthread_mutex_t check_init_lock = PTHREAD_MUTEX_INITIALIZER; /* Initialize the mutex *PRIV. If JUST_CHECK is true, only do this if it is not already initialized. */ static int -mutex_pthread_init (void **priv, int just_check) +mutex_pthread_init (ath_mutex_t *priv, int just_check) { int err = 0; @@ -55,7 +61,7 @@ mutex_pthread_init (void **priv, int just_check) if (err) free (lock); else - *priv = lock; + *priv = (ath_mutex_t) lock; } } if (just_check) @@ -64,37 +70,106 @@ mutex_pthread_init (void **priv, int just_check) } -static int -mutex_pthread_destroy (void *priv) +void +ath_init (void) +{ + /* Nothing to do. */ +} + + +int +ath_mutex_init (ath_mutex_t *lock) +{ + return mutex_pthread_init (lock, 0); +} + + +int +ath_mutex_destroy (ath_mutex_t *lock) { - int err = pthread_mutex_destroy ((pthread_mutex_t *) priv); - free (priv); + int err = mutex_pthread_init (lock, 1); + if (!err) + { + err = pthread_mutex_destroy ((pthread_mutex_t *) *lock); + free (*lock); + } return err; } -static struct ath_ops ath_pthread_ops = - { - mutex_pthread_init, - mutex_pthread_destroy, - (int (*) (void *)) pthread_mutex_lock, - (int (*) (void *)) pthread_mutex_unlock, - NULL, /* read */ - NULL, /* write */ - NULL, /* select */ - NULL /* waitpid */ - }; +int +ath_mutex_lock (ath_mutex_t *lock) +{ + int ret = mutex_pthread_init (lock, 1); + if (ret) + return ret; + + return pthread_mutex_lock ((pthread_mutex_t *) *lock); +} + + +int +ath_mutex_unlock (ath_mutex_t *lock) +{ + int ret = mutex_pthread_init (lock, 1); + if (ret) + return ret; + + return pthread_mutex_unlock ((pthread_mutex_t *) *lock); +} + + +ssize_t +ath_read (int fd, void *buf, size_t nbytes) +{ + return read (fd, buf, nbytes); +} + + +ssize_t +ath_write (int fd, const void *buf, size_t nbytes) +{ + return write (fd, buf, nbytes); +} + + +ssize_t +ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, + struct timeval *timeout) +{ + return select (nfd, rset, wset, eset, timeout); +} + + +ssize_t +ath_waitpid (pid_t pid, int *status, int options) +{ + return waitpid (pid, status, options); +} + + +int +ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr) +{ + return accept (s, addr, length_ptr); +} + + +int +ath_connect (int s, struct sockaddr *addr, socklen_t length) +{ + return connect (s, addr, length); +} + +int +ath_sendmsg (int s, const struct msghdr *msg, int flags) +{ + return sendmsg (s, msg, flags); +} -struct ath_ops * -ath_pthread_available (void) +int +ath_recvmsg (int s, struct msghdr *msg, int flags) { - /* Need to include pthread_create in our check, as the GNU C library - has the pthread_mutex_* functions in their public interface. */ - if (pthread_create - && pthread_mutex_init && pthread_mutex_destroy - && pthread_mutex_lock && pthread_mutex_unlock) - return &ath_pthread_ops; - else - return 0; + return recvmsg (s, msg, flags); } diff --git a/trunk/gpgme/ath.c b/trunk/gpgme/ath.c index 1d8d94b..cdef2b8 100644 --- a/trunk/gpgme/ath.c +++ b/trunk/gpgme/ath.c @@ -1,27 +1,27 @@ -/* ath.c - self-adapting thread-safeness 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 - */ +/* ath.c - Thread-safeness library. + Copyright (C) 2002, 2003 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. */ #ifdef HAVE_CONFIG_H #include #endif +#include #include #ifdef HAVE_SYS_SELECT_H # include @@ -33,94 +33,69 @@ #include "ath.h" -static struct ath_ops *ath_ops; -void -ath_init (void) -{ -#ifdef HAVE_PTHREAD - if (!ath_ops) - ath_ops = ath_pthread_available (); -#endif -#ifdef HAVE_PTH - if (!ath_ops) - ath_ops = ath_pth_available (); -#endif -#ifdef HAVE_ATH_DUMMY - if (!ath_ops) - ath_ops = ath_dummy_available (); -#endif -} +#define MUTEX_UNLOCKED ((ath_mutex_t) 0) +#define MUTEX_LOCKED ((ath_mutex_t) 1) +#define MUTEX_DESTROYED ((ath_mutex_t) 2) int ath_mutex_init (ath_mutex_t *lock) { - if (!ath_ops) - return 0; - - return ath_ops->mutex_init (lock, 0); +#ifndef NDEBUG + *lock = MUTEX_UNLOCKED; +#endif + return 0; } int ath_mutex_destroy (ath_mutex_t *lock) { - int err; - if (!ath_ops) - return 0; - err = ath_ops->mutex_init (lock, 1); - if (!err) - err = ath_ops->mutex_destroy (*lock); - return err; +#ifndef NDEBUG + assert (*lock == MUTEX_UNLOCKED); + + *lock = MUTEX_DESTROYED; +#endif + return 0; } int ath_mutex_lock (ath_mutex_t *lock) { - int err; - - if (!ath_ops) - return 0; - err = ath_ops->mutex_init (lock, 1); - if (!err) - err = ath_ops->mutex_lock (*lock); - return err; +#ifndef NDEBUG + assert (*lock == MUTEX_UNLOCKED); + + *lock = MUTEX_LOCKED; +#endif + return 0; } int ath_mutex_unlock (ath_mutex_t *lock) { - int err; - - if (!ath_ops) - return 0; - err = ath_ops->mutex_init (lock, 1); - if (!err) - err = ath_ops->mutex_unlock (*lock); - return err; +#ifndef NDEBUG + assert (*lock == MUTEX_LOCKED); + + *lock = MUTEX_UNLOCKED; +#endif + return 0; } ssize_t ath_read (int fd, void *buf, size_t nbytes) { - if (ath_ops && ath_ops->read) - return ath_ops->read (fd, buf, nbytes); - else - return read (fd, buf, nbytes); + return read (fd, buf, nbytes); } ssize_t ath_write (int fd, const void *buf, size_t nbytes) { - if (ath_ops && ath_ops->write) - return ath_ops->write (fd, buf, nbytes); - else - return write (fd, buf, nbytes); + return write (fd, buf, nbytes); } @@ -128,18 +103,40 @@ ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout) { - if (ath_ops && ath_ops->select) - return ath_ops->select (nfd, rset, wset, eset, timeout); - else - return select (nfd, rset, wset, eset, timeout); + return select (nfd, rset, wset, eset, timeout); } ssize_t ath_waitpid (pid_t pid, int *status, int options) { - if (ath_ops && ath_ops->waitpid) - return ath_ops->waitpid (pid, status, options); - else - return waitpid (pid, status, options); + return waitpid (pid, status, options); +} + + +int +ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr) +{ + return accept (s, addr, length_ptr); +} + + +int +ath_connect (int s, struct sockaddr *addr, socklen_t length) +{ + return connect (s, addr, length); +} + + +int +ath_sendmsg (int s, const struct msghdr *msg, int flags) +{ + return sendmsg (s, msg, flags); +} + + +int +ath_recvmsg (int s, struct msghdr *msg, int flags) +{ + return recvmsg (s, msg, flags); } diff --git a/trunk/gpgme/ath.h b/trunk/gpgme/ath.h index 20e2fff..54f74d9 100644 --- a/trunk/gpgme/ath.h +++ b/trunk/gpgme/ath.h @@ -1,47 +1,49 @@ -/* ath.h - interfaces for self-adapting thread-safeness 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 - */ +/* ath.h - Interfaces for thread-safeness library. + Copyright (C) 2002, 2003 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. */ #ifndef ATH_H #define ATH_H #include +#include -/* Define ATH_EXT_SYM_PREFIX if you want to give all external symbols + +/* Define _ATH_EXT_SYM_PREFIX if you want to give all external symbols a prefix. */ -#define ATH_EXT_SYM_PREFIX _gpgme_ +#define _ATH_EXT_SYM_PREFIX _gpgme_ -#ifdef ATH_EXT_SYM_PREFIX -#define ATH_PREFIX1(x,y) x ## y -#define ATH_PREFIX2(x,y) ATH_PREFIX1(x,y) -#define ATH_PREFIX(x) ATH_PREFIX2(ATH_EXT_SYM_PREFIX,x) -#define ath_init ATH_PREFIX(ath_init) -#define ath_mutex_init ATH_PREFIX(ath_mutex_init) -#define ath_mutex_destroy ATH_PREFIX(ath_mutex_destroy) -#define ath_mutex_lock ATH_PREFIX(ath_mutex_lock) -#define ath_mutex_unlock ATH_PREFIX(ath_mutex_unlock) -#define ath_read ATH_PREFIX(ath_read) -#define ath_write ATH_PREFIX(ath_write) -#define ath_select ATH_PREFIX(ath_select) -#define ath_waitpid ATH_PREFIX(ath_waitpid) -#define ath_pthread_available ATH_PREFIX(ath_pthread_available) -#define ath_pth_available ATH_PREFIX(ath_pth_available) +#ifdef _ATH_EXT_SYM_PREFIX +#define _ATH_PREFIX1(x,y) x ## y +#define _ATH_PREFIX2(x,y) _ATH_PREFIX1(x,y) +#define _ATH_PREFIX(x) _ATH_PREFIX2(_ATH_EXT_SYM_PREFIX,x) +#define ath_mutex_init _ATH_PREFIX(ath_mutex_init) +#define ath_mutex_destroy _ATH_PREFIX(ath_mutex_destroy) +#define ath_mutex_lock _ATH_PREFIX(ath_mutex_lock) +#define ath_mutex_unlock _ATH_PREFIX(ath_mutex_unlock) +#define ath_read _ATH_PREFIX(ath_read) +#define ath_write _ATH_PREFIX(ath_write) +#define ath_select _ATH_PREFIX(ath_select) +#define ath_waitpid _ATH_PREFIX(ath_waitpid) +#define ath_connect _ATH_PREFIX(ath_connect) +#define ath_accept _ATH_PREFIX(ath_accept) +#define ath_sendmsg _ATH_PREFIX(ath_sendmsg) +#define ath_recvmsg _ATH_PREFIX(ath_recvmsg) #endif @@ -61,8 +63,13 @@ ssize_t ath_write (int fd, const void *buf, size_t nbytes); ssize_t ath_select (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout); ssize_t ath_waitpid (pid_t pid, int *status, int options); +int ath_accept (int s, struct sockaddr *addr, socklen_t *length_ptr); +int ath_connect (int s, struct sockaddr *addr, socklen_t length); +int ath_sendmsg (int s, const struct msghdr *msg, int flags); +int ath_recvmsg (int s, struct msghdr *msg, int flags); - +#define _ATH_COMPAT +#ifdef _ATH_COMPAT struct ath_ops { int (*mutex_init) (void **priv, int just_check); @@ -74,14 +81,21 @@ struct ath_ops ssize_t (*select) (int nfd, fd_set *rset, fd_set *wset, fd_set *eset, struct timeval *timeout); ssize_t (*waitpid) (pid_t pid, int *status, int options); + int (*accept) (int s, struct sockaddr *addr, socklen_t *length_ptr); + int (*connect) (int s, struct sockaddr *addr, socklen_t length); + int (*sendmsg) (int s, const struct msghdr *msg, int flags); + int (*recvmsg) (int s, struct msghdr *msg, int flags); }; /* Initialize the any-thread package. */ +#define ath_init _ATH_PREFIX(ath_init) void ath_init (void); /* Used by ath_pkg_init. */ +#define ath_pthread_available _ATH_PREFIX(ath_pthread_available) struct ath_ops *ath_pthread_available (void); +#define ath_pth_available _ATH_PREFIX(ath_pth_available) struct ath_ops *ath_pth_available (void); -struct ath_ops *ath_dummy_available (void); +#endif #endif /* ATH_H */ diff --git a/trunk/gpgme/engine-gpgsm.c b/trunk/gpgme/engine-gpgsm.c index 6ab1ad5..c8f9757 100644 --- a/trunk/gpgme/engine-gpgsm.c +++ b/trunk/gpgme/engine-gpgsm.c @@ -601,7 +601,7 @@ gpgsm_assuan_simple_command (ASSUAN_CONTEXT ctx, char *cmd, r = parse_status (line + 2); if (r >= 0 && status_fnc) - status_fnc (status_fnc_value, r, rest); + err = status_fnc (status_fnc_value, r, rest); else err = gpg_error (GPG_ERR_GENERAL); } @@ -685,7 +685,7 @@ status_handler (void *opaque, int fd) if (assuan_err) { /* Try our best to terminate the connection friendly. */ - assuan_write_line (gpgsm->assuan_ctx, "BYE"); + /* assuan_write_line (gpgsm->assuan_ctx, "BYE"); */ err = map_assuan_error (assuan_err); } else if (linelen >= 3 diff --git a/trunk/gpgme/rungpg.c b/trunk/gpgme/rungpg.c index fb5b737..616ff3d 100644 --- a/trunk/gpgme/rungpg.c +++ b/trunk/gpgme/rungpg.c @@ -1097,7 +1097,7 @@ start (engine_gpg_t gpg) saved_errno = errno; free (fd_child_list); if (status == -1) - return gpg_error_from_errno (errno); + return gpg_error_from_errno (saved_errno); /*_gpgme_register_term_handler ( closure, closure_value, pid );*/ diff --git a/trunk/gpgme/util.h b/trunk/gpgme/util.h index fcb4825..358c290 100644 --- a/trunk/gpgme/util.h +++ b/trunk/gpgme/util.h @@ -43,21 +43,7 @@ char *stpcpy (char *a, const char *b); int vasprintf (char **result, const char *format, va_list args); int asprintf (char **result, const char *format, ...); #endif - -#if !HAVE_FOPENCOOKIE -#include /* make sure that ssize_t and off_t are defined */ -typedef struct -{ - ssize_t (*read)(void*,char*,size_t); - ssize_t (*write)(void*,const char*,size_t); - int (*seek)(void*,off_t*,int); - int (*close)(void*); -} _IO_cookie_io_functions_t; -typedef _IO_cookie_io_functions_t cookie_io_functions_t; -FILE *fopencookie (void *cookie, const char *opentype, - cookie_io_functions_t funclist); -#endif /*!HAVE_FOPENCOOKIE*/ -#endif /*HAVE_CONFIG_H*/ +#endif /*-- conversion.c --*/ -- 2.26.2