From: Marcus Brinkmann Date: Fri, 13 Jul 2007 01:57:02 +0000 (+0000) Subject: 2007-07-13 Marcus Brinkmann X-Git-Tag: gpgme-1.1.6~49 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5d25b54f30d2335694e98760e3560915bf639bff;p=gpgme.git 2007-07-13 Marcus Brinkmann * Revert the "close_notify_handler" returns int stuff. Always close in the _gpgme_io_close implementations. * engine-gpgsm.c (status_handler): Try to terminate the connection in case of error. * w32-io.c (_gpgme_io_read): Return C->error_code in ERRNO. (_gpgme_io_write): Likewise. --- diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 33f9b23..716b29c 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,5 +1,12 @@ 2007-07-13 Marcus Brinkmann + * Revert the "close_notify_handler" returns int stuff. Always + close in the _gpgme_io_close implementations. + * engine-gpgsm.c (status_handler): Try to terminate the connection + in case of error. + * w32-io.c (_gpgme_io_read): Return C->error_code in ERRNO. + (_gpgme_io_write): Likewise. + * priv-io.h (_gpgme_io_set_close_notify): Change type of HANDLER to _gpgme_close_notify_handler. (_gpgme_close_notify_handler): New type. diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index 4827fbe..4e3f1e7 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -112,7 +112,7 @@ gpgsm_get_req_version (void) } -static int +static void close_notify_handler (int fd, void *opaque) { engine_gpgsm_t gpgsm = opaque; @@ -124,9 +124,6 @@ close_notify_handler (int fd, void *opaque) (*gpgsm->io_cbs.remove) (gpgsm->status_cb.tag); gpgsm->status_cb.fd = -1; gpgsm->status_cb.tag = NULL; - /* We do not want to close the status FD, as it is controled by - Assuan. */ - return 0; } else if (gpgsm->input_cb.fd == fd) { @@ -149,7 +146,6 @@ close_notify_handler (int fd, void *opaque) gpgsm->message_cb.fd = -1; gpgsm->message_cb.tag = NULL; } - return 1; } @@ -287,8 +283,6 @@ gpgsm_cancel (void *engine) if (!gpgsm) return gpg_error (GPG_ERR_INV_VALUE); - if (gpgsm->status_cb.fd != -1) - _gpgme_io_close (gpgsm->status_cb.fd); if (gpgsm->input_cb.fd != -1) _gpgme_io_close (gpgsm->input_cb.fd); if (gpgsm->output_cb.fd != -1) @@ -827,6 +821,8 @@ status_handler (void *opaque, int fd) err = gpg_error (GPG_ERR_GENERAL); DEBUG2 ("fd %d: ERR line - mapped to: %s\n", fd, err? gpg_strerror (err):"ok"); + /* Try our best to terminate the connection friendly. */ + assuan_write_line (gpgsm->assuan_ctx, "BYE"); } else if (linelen >= 2 && line[0] == 'O' && line[1] == 'K' @@ -846,7 +842,6 @@ status_handler (void *opaque, int fd) gpgsm->colon.any = 0; err = gpgsm->colon.fnc (gpgsm->colon.fnc_value, NULL); } - _gpgme_io_close (gpgsm->status_cb.fd); DEBUG2 ("fd %d: OK line - final status: %s\n", fd, err? gpg_strerror (err):"ok"); return err; @@ -990,8 +985,7 @@ start (engine_gpgsm_t gpgsm, const char *command) /* We used to duplicate the file descriptor so that we do not disturb Assuan. But this gets in the way of the Handle-to-Thread mapping in w32-io.c, so instead we just share the file descriptor - *carefully*, by avoiding to close it ourselves (this is achieved by - returning 0 from the close_notify_handler for this descriptor). */ + but leave it to Assuan to close it. */ gpgsm->status_cb.fd = fdlist[0]; if (_gpgme_io_set_close_notify (gpgsm->status_cb.fd, diff --git a/gpgme/posix-io.c b/gpgme/posix-io.c index 6ebe42a..7d7be1e 100644 --- a/gpgme/posix-io.c +++ b/gpgme/posix-io.c @@ -139,8 +139,6 @@ _gpgme_io_pipe (int filedes[2], int inherit_idx) int _gpgme_io_close (int fd) { - int really_close = 1; - if (fd == -1) return -1; /* First call the notify handler. */ @@ -149,16 +147,13 @@ _gpgme_io_close (int fd) { if (notify_table[fd].handler) { - really_close = 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].value = NULL; } } /* Then do the close. */ - if (really_close) - return close (fd); - - return 0; + return close (fd); } diff --git a/gpgme/priv-io.h b/gpgme/priv-io.h index 602fede..25d14dc 100644 --- a/gpgme/priv-io.h +++ b/gpgme/priv-io.h @@ -47,7 +47,7 @@ int _gpgme_io_read (int fd, void *buffer, size_t count); int _gpgme_io_write (int fd, const void *buffer, size_t count); int _gpgme_io_pipe (int filedes[2], int inherit_idx); int _gpgme_io_close (int fd); -typedef int (*_gpgme_close_notify_handler_t) (int,void*); +typedef void (*_gpgme_close_notify_handler_t) (int,void*); int _gpgme_io_set_close_notify (int fd, _gpgme_close_notify_handler_t handler, void *value); int _gpgme_io_set_nonblocking (int fd); diff --git a/gpgme/rungpg.c b/gpgme/rungpg.c index 91fc1ad..d6fd8fe 100644 --- a/gpgme/rungpg.c +++ b/gpgme/rungpg.c @@ -141,7 +141,7 @@ gpg_io_event (void *engine, gpgme_event_io_t type, void *type_data) } -static int +static void close_notify_handler (int fd, void *opaque) { engine_gpg_t gpg = opaque; @@ -183,7 +183,6 @@ close_notify_handler (int fd, void *opaque) } } } - return 1; } /* If FRONT is true, push at the front of the list. Use this for diff --git a/gpgme/w32-glib-io.c b/gpgme/w32-glib-io.c index 3372776..8f56eee 100644 --- a/gpgme/w32-glib-io.c +++ b/gpgme/w32-glib-io.c @@ -271,7 +271,6 @@ int _gpgme_io_close (int fd) { GIOChannel *chan; - int really_close = 1; if (fd < 0 || fd >= MAX_SLAFD) { @@ -283,24 +282,21 @@ _gpgme_io_close (int fd) DEBUG1 ("closing fd %d", fd); if (notify_table[fd].handler) { - really_close = 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].value = NULL; } /* Then do the close. */ - if (really_close) + chan = giochannel_table[fd]; + if (chan) { - chan = giochannel_table[fd]; - if (chan) - { - g_io_channel_shutdown (chan, 1, NULL); - g_io_channel_unref (chan); - giochannel_table[fd] = NULL; - } - else - _close (fd); + g_io_channel_shutdown (chan, 1, NULL); + g_io_channel_unref (chan); + giochannel_table[fd] = NULL; } + else + _close (fd); return 0; } diff --git a/gpgme/w32-io.c b/gpgme/w32-io.c index 3b034f6..e2a464d 100644 --- a/gpgme/w32-io.c +++ b/gpgme/w32-io.c @@ -374,6 +374,7 @@ _gpgme_io_read ( int fd, void *buffer, size_t count ) DEBUG2 ("fd %d: about to read %d bytes\n", fd, (int)count ); if ( !c ) { DEBUG0 ( "no reader thread\n"); + errno = EBADF; return -1; } if (c->eof_shortcut) { @@ -402,6 +403,7 @@ _gpgme_io_read ( int fd, void *buffer, size_t count ) return 0; } DEBUG1 ("fd %d: read error", fd ); + errno = c->error_code; return -1; } @@ -631,11 +633,12 @@ _gpgme_io_write ( int fd, const void *buffer, size_t count ) _gpgme_debug (2, "fd %d: write `%.*s'\n", fd, (int) count, buffer); if ( !c ) { DEBUG0 ( "no writer thread\n"); + errno = EBADF; return -1; } LOCK (c->mutex); - if ( c->nbytes ) { /* bytes are pending for send */ + if ( !c->error && c->nbytes ) { /* bytes are pending for send */ /* Reset the is_empty event. Better safe than sorry. */ if (!ResetEvent (c->is_empty)) DEBUG1 ("ResetEvent failed: ec=%d", (int)GetLastError ()); @@ -650,6 +653,7 @@ _gpgme_io_write ( int fd, const void *buffer, size_t count ) if ( c->error) { UNLOCK (c->mutex); DEBUG1 ("fd %d: write error", fd ); + errno = c->error_code; return -1; } @@ -729,7 +733,6 @@ _gpgme_io_close ( int fd ) int i; _gpgme_close_notify_handler_t handler = NULL; void *value = NULL; - int really_close = 1; if ( fd == -1 ) return -1; @@ -750,9 +753,9 @@ _gpgme_io_close ( int fd ) } UNLOCK (notify_table_lock); if (handler) - really_close = handler (fd, value); + handler (fd, value); - if ( really_close && !CloseHandle (fd_to_handle (fd)) ) { + if ( !CloseHandle (fd_to_handle (fd)) ) { DEBUG2 ("CloseHandle for fd %d failed: ec=%d\n", fd, (int)GetLastError ()); return -1;