diff options
author | Werner Koch <[email protected]> | 2010-08-18 19:25:15 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2010-08-18 19:25:15 +0000 |
commit | 34dde9666975c6c258a5983a5bc334d9b8b80a55 (patch) | |
tree | 35921e17de3f1564e86182755d0ca5fa027652d6 /common | |
parent | Auto-start dirmngr. (diff) | |
download | gnupg-34dde9666975c6c258a5983a5bc334d9b8b80a55.tar.gz gnupg-34dde9666975c6c258a5983a5bc334d9b8b80a55.zip |
Fix regression in logging.
Add a registry key to enable catch-all remote debugging for W32.
Replace more stdio stuff by estream.
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 11 | ||||
-rw-r--r-- | common/estream.c | 57 | ||||
-rw-r--r-- | common/estream.h | 7 | ||||
-rw-r--r-- | common/logging.c | 27 | ||||
-rw-r--r-- | common/logging.h | 1 |
5 files changed, 78 insertions, 25 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index 070305370..f53a19293 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,5 +1,16 @@ +2010-08-18 Werner Koch <[email protected]> + + * logging.c (writen): Add arg IS_SOCKET. + (fun_writer): Pass the is_socket flag. + (do_logv) [W32]: Allow for a default log stream + + * estream.c (struct estream_internal): Remove obsolete fields + PRINT_FP, PRINT_ERRNO, PRINT_ERR and all remaining code cruft. + 2010-08-16 Werner Koch <[email protected]> + * estream.c (es_printf_unlocked, es_printf): New. + * asshelp.c (lock_agent_t): Rename to lock_spawn_t. (lock_agent_spawning, unlock_agent_spawning): Factor code out to ... (lock_spawning, unlock_spawning): .. new. diff --git a/common/estream.c b/common/estream.c index f3ba109ee..ea5d4d00f 100644 --- a/common/estream.c +++ b/common/estream.c @@ -218,7 +218,7 @@ struct estream_internal es_cookie_seek_function_t func_seek; es_cookie_close_function_t func_close; int strategy; - int fd; + int fd; /* Value to return by es_fileno(). */ struct { unsigned int err: 1; @@ -227,11 +227,8 @@ struct estream_internal unsigned int deallocate_buffer: 1; unsigned int is_stdstream:1; /* This is a standard stream. */ unsigned int stdstream_fd:2; /* 0, 1 or 2 for a standard stream. */ - unsigned int print_err: 1; /* Error in print_fun_writer. */ unsigned int printable_fname_inuse: 1; /* es_fname_get has been used. */ - int print_errno; /* Errno from print_fun_writer. */ - size_t print_ntotal; /* Bytes written from in print_fun_writer. */ - FILE *print_fp; /* Stdio stream used by print_fun_writer. */ + size_t print_ntotal; /* Bytes written from in print_writer. */ }; @@ -899,7 +896,8 @@ typedef struct estream_cookie_fp int no_close; /* If set we won't close the file pointer. */ } *estream_cookie_fp_t; -/* Create function for fd objects. */ + +/* Create function for FILE objects. */ static int es_func_fp_create (void **cookie, FILE *fp, unsigned int modeflags, int no_close) @@ -924,7 +922,7 @@ es_func_fp_create (void **cookie, FILE *fp, *cookie = fp_cookie; err = 0; } - + return err; } @@ -948,12 +946,10 @@ es_func_fp_read (void *cookie, void *buffer, size_t size) /* Write function for FILE* objects. */ static ssize_t es_func_fp_write (void *cookie, const void *buffer, size_t size) - { estream_cookie_fp_t file_cookie = cookie; size_t bytes_written; - if (file_cookie->fp) { #ifdef HAVE_W32_SYSTEM @@ -1285,10 +1281,7 @@ es_initialize (estream_t stream, stream->intern->func_close = functions.func_close; stream->intern->strategy = _IOFBF; stream->intern->fd = fd; - stream->intern->print_err = 0; - stream->intern->print_errno = 0; stream->intern->print_ntotal = 0; - stream->intern->print_fp = NULL; stream->intern->indicators.err = 0; stream->intern->indicators.eof = 0; stream->intern->is_stdstream = 0; @@ -1319,14 +1312,6 @@ es_deinitialize (estream_t stream) es_cookie_close_function_t func_close; int err, tmp_err; - if (stream->intern->print_fp) - { - int save_errno = errno; - fclose (stream->intern->print_fp); - stream->intern->print_fp = NULL; - _set_errno (save_errno); - } - func_close = stream->intern->func_close; err = 0; @@ -3205,6 +3190,38 @@ es_fprintf (estream_t ES__RESTRICT stream, return ret; } + +int +es_printf_unlocked (const char *ES__RESTRICT format, ...) +{ + int ret; + + va_list ap; + va_start (ap, format); + ret = es_print (es_stdout, format, ap); + va_end (ap); + + return ret; +} + + +int +es_printf (const char *ES__RESTRICT format, ...) +{ + int ret; + estream_t stream = es_stdout; + + va_list ap; + va_start (ap, format); + ESTREAM_LOCK (stream); + ret = es_print (stream, format, ap); + ESTREAM_UNLOCK (stream); + va_end (ap); + + return ret; +} + + /* A variant of asprintf. The function returns the allocated buffer or NULL on error; ERRNO is set in the error case. The caller should use es_free to release the buffer. This function actually diff --git a/common/estream.h b/common/estream.h index f7ef162f5..34ff5ce77 100644 --- a/common/estream.h +++ b/common/estream.h @@ -121,6 +121,8 @@ #define es_free _ESTREAM_PREFIX(es_free) #define es_fprintf _ESTREAM_PREFIX(es_fprintf) #define es_fprintf_unlocked _ESTREAM_PREFIX(es_fprintf_unlocked) +#define es_printf _ESTREAM_PREFIX(es_printf) +#define es_printf_unlocked _ESTREAM_PREFIX(es_printf_unlocked) #define es_vfprintf _ESTREAM_PREFIX(es_vfprint) #define es_vfprintf_unlocked _ESTREAM_PREFIX(es_vfprint_unlocked) #define es_setvbuf _ESTREAM_PREFIX(es_setvbuf) @@ -345,6 +347,11 @@ int es_fprintf_unlocked (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format, ...) _ESTREAM_GCC_A_PRINTF(2,3); +int es_printf (const char *ES__RESTRICT format, ...) + _ESTREAM_GCC_A_PRINTF(1,2); +int es_printf_unlocked (const char *ES__RESTRICT format, ...) + _ESTREAM_GCC_A_PRINTF(1,2); + int es_vfprintf (estream_t ES__RESTRICT stream, const char *ES__RESTRICT format, va_list ap) _ESTREAM_GCC_A_PRINTF(2,0); diff --git a/common/logging.c b/common/logging.c index 87e335b07..4c2d61b1e 100644 --- a/common/logging.c +++ b/common/logging.c @@ -120,19 +120,24 @@ struct fun_cookie_s /* Write NBYTES of BUFFER to file descriptor FD. */ static int -writen (int fd, const void *buffer, size_t nbytes) +writen (int fd, const void *buffer, size_t nbytes, int is_socket) { const char *buf = buffer; size_t nleft = nbytes; int nwritten; +#ifndef HAVE_W32_SYSTEM + (void)is_socket; /* Not required. */ +#endif while (nleft > 0) { #ifdef HAVE_W32_SYSTEM - nwritten = send (fd, buf, nleft, 0); -#else - nwritten = write (fd, buf, nleft); + if (is_socket) + nwritten = send (fd, buf, nleft, 0); + else #endif + nwritten = write (fd, buf, nleft); + if (nwritten < 0 && errno == EINTR) continue; if (nwritten < 0) @@ -171,6 +176,9 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size) { struct fun_cookie_s *cookie = cookie_arg; + /* FIXME: Use only estream with a callback for socket writing. This + avoids the ugly mix of fd and estream code. */ + /* Note that we always try to reconnect to the socket but print error messages only the first time an error occured. If RUNNING_DETACHED is set we don't fall back to stderr and even do @@ -345,7 +353,7 @@ fun_writer (void *cookie_arg, const void *buffer, size_t size) } log_socket = cookie->fd; - if (cookie->fd != -1 && !writen (cookie->fd, buffer, size)) + if (cookie->fd != -1 && !writen (cookie->fd, buffer, size, cookie->is_socket)) return (ssize_t)size; /* Okay. */ if (!running_detached && cookie->fd != -1 @@ -561,7 +569,16 @@ do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr) { if (!logstream) { +#ifdef HAVE_W32_SYSTEM + char *tmp; + + tmp = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG", + "DefaultLogFile"); + log_set_file (tmp); + jnlib_free (tmp); +#else log_set_file (NULL); /* Make sure a log stream has been set. */ +#endif assert (logstream); } diff --git a/common/logging.h b/common/logging.h index 91619179a..3ee4db6ef 100644 --- a/common/logging.h +++ b/common/logging.h @@ -24,6 +24,7 @@ #include <stdio.h> #include "estream.h" #include "mischelp.h" +#include "w32help.h" /* Flag values for log_set_prefix. */ #define JNLIB_LOG_WITH_PREFIX 1 |