diff --git a/agent/ChangeLog b/agent/ChangeLog index e4fbe073b..d424f2b58 100644 --- a/agent/ChangeLog +++ b/agent/ChangeLog @@ -1,3 +1,12 @@ +2010-03-11 Werner Koch + + * gpg-agent.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + (handle_signal): Disable pth ctrl dumping. + (parse_rereadable_options, main): Remove assuan_set_assuan_log_stream. + * call-scd.c (start_scd): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (common_libs): Remove libjnlib.a. diff --git a/agent/call-scd.c b/agent/call-scd.c index f3303c11d..d37183ba6 100644 --- a/agent/call-scd.c +++ b/agent/call-scd.c @@ -354,8 +354,6 @@ start_scd (ctrl_t ctrl) if (opt.verbose) log_debug ("first connection to SCdaemon established\n"); - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); /* Get the name of the additional socket opened by scdaemon. */ { diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index 73f84ed82..4ff5774dc 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -49,6 +49,7 @@ #include "setenv.h" #include "gc-opt-flags.h" #include "exechelp.h" +#include "asshelp.h" enum cmd_and_opt_values { aNull = 0, @@ -494,8 +495,6 @@ parse_rereadable_options (ARGPARSE_ARGS *pargs, int reread) || strcmp (current_logfile, pargs->r.ret_str)) { log_set_file (pargs->r.ret_str); - if (DBG_ASSUAN) - assuan_set_assuan_log_stream (log_get_stream ()); xfree (current_logfile); current_logfile = xtrystrdup (pargs->r.ret_str); } @@ -616,10 +615,10 @@ main (int argc, char **argv ) malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); - assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); + assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); assuan_set_system_hooks (ASSUAN_SYSTEM_PTH); assuan_sock_init (); + setup_libassuan_logging (&opt.debug); setup_libgcrypt_logging (); gcry_control (GCRYCTL_USE_SECURE_RNDPOOL); @@ -946,8 +945,6 @@ main (int argc, char **argv ) |JNLIB_LOG_WITH_PID)); current_logfile = xstrdup (logfile); } - if (DBG_ASSUAN) - assuan_set_assuan_log_stream (log_get_stream ()); /* Make sure that we have a default ttyname. */ if (!default_ttyname && ttyname (1)) @@ -1711,7 +1708,9 @@ handle_signal (int signo) case SIGUSR1: log_info ("SIGUSR1 received - printing internal information:\n"); - pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); + /* Fixme: We need to see how to integrate pth dumping into our + logging system. */ + /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */ agent_query_dump_state (); agent_scd_dump_state (); break; diff --git a/common/ChangeLog b/common/ChangeLog index 5fd8b03a9..6f33deee8 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,11 @@ +2010-03-11 Werner Koch + + * estream.c (es_setvbuf): Fix parameter check. + (es_set_buffering): Allow a SIZE of 0. + * asshelp.c (setup_libassuan_logging, my_libassuan_log_handler): New. + * logging.c (do_logv): Add arg IGNORE_ARG_PTR. Change all callers. + (log_string): New. + 2010-03-10 Werner Koch * estream.c (es_func_fp_read, es_func_fp_write, es_func_fp_seek) diff --git a/common/asshelp.c b/common/asshelp.c index b2d13f32b..76518485f 100644 --- a/common/asshelp.c +++ b/common/asshelp.c @@ -27,6 +27,7 @@ #include #endif +#define JNLIB_NEED_LOG_LOGV #include "i18n.h" #include "util.h" #include "exechelp.h" @@ -34,6 +35,36 @@ #include "status.h" #include "asshelp.h" + +static int +my_libassuan_log_handler (assuan_context_t ctx, void *hook, + unsigned int cat, const char *msg) +{ + unsigned int dbgval; + + if (cat != ASSUAN_LOG_CONTROL) + return 0; /* We only want the control channel messages. */ + dbgval = hook? *(unsigned int*)hook : 0; + if (!(dbgval & 1024)) + return 0; /* Assuan debugging is not enabled. */ + + if (msg) + log_string (JNLIB_LOG_DEBUG, msg); + + return 1; +} + + +/* Setup libassuan to use our own logging functions. Should be used + early at startup. */ +void +setup_libassuan_logging (unsigned int *debug_var_address) +{ + assuan_set_log_cb (my_libassuan_log_handler, debug_var_address); +} + + + static gpg_error_t send_one_option (assuan_context_t ctx, gpg_err_source_t errsource, const char *name, const char *value, int use_putenv) diff --git a/common/asshelp.h b/common/asshelp.h index f7bc88bad..3c961fef8 100644 --- a/common/asshelp.h +++ b/common/asshelp.h @@ -25,6 +25,9 @@ #include "session-env.h" +void setup_libassuan_logging (unsigned int *debug_var_address); + + gpg_error_t send_pinentry_environment (assuan_context_t ctx, gpg_err_source_t errsource, diff --git a/common/estream.c b/common/estream.c index dfa2de4aa..32567e631 100644 --- a/common/estream.c +++ b/common/estream.c @@ -2028,6 +2028,8 @@ es_set_buffering (estream_t ES__RESTRICT stream, buffer_new = buffer; else { + if (!size) + size = BUFSIZ; buffer_new = mem_alloc (size); if (! buffer_new) { @@ -3207,8 +3209,8 @@ es_setvbuf (estream_t ES__RESTRICT stream, { int err; - if (((type == _IOFBF) || (type == _IOLBF) || (type == _IONBF)) - && (! ((! size) && (type != _IONBF)))) + if ((type == _IOFBF || type == _IOLBF || type == _IONBF) + && (!buf || size || type == _IONBF)) { ESTREAM_LOCK (stream); err = es_set_buffering (stream, buf, type, size); diff --git a/common/logging.c b/common/logging.c index c0e01da11..3b767cb97 100644 --- a/common/logging.c +++ b/common/logging.c @@ -415,7 +415,7 @@ log_get_stream () } static void -do_logv (int level, const char *fmt, va_list arg_ptr) +do_logv (int level, int ignore_arg_ptr, const char *fmt, va_list arg_ptr) { if (!logstream) { @@ -478,7 +478,10 @@ do_logv (int level, const char *fmt, va_list arg_ptr) if (fmt) { - es_vfprintf_unlocked (logstream, fmt, arg_ptr); + if (ignore_arg_ptr) + es_fputs_unlocked (fmt, logstream); + else + es_vfprintf_unlocked (logstream, fmt, arg_ptr); if (*fmt && fmt[strlen(fmt)-1] != '\n') missing_lf = 1; } @@ -503,76 +506,91 @@ do_logv (int level, const char *fmt, va_list arg_ptr) static void -do_log( int level, const char *fmt, ... ) +do_log (int level, const char *fmt, ...) { - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( level, fmt, arg_ptr ); - va_end(arg_ptr); + va_list arg_ptr ; + + va_start (arg_ptr, fmt) ; + do_logv (level, 0, fmt, arg_ptr); + va_end (arg_ptr); } void log_logv (int level, const char *fmt, va_list arg_ptr) { - do_logv (level, fmt, arg_ptr); -} - -void -log_info( const char *fmt, ... ) -{ - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_INFO, fmt, arg_ptr ); - va_end(arg_ptr); -} - -void -log_error( const char *fmt, ... ) -{ - va_list arg_ptr ; - - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_ERROR, fmt, arg_ptr ); - va_end(arg_ptr); - /* protect against counter overflow */ - if( errorcount < 30000 ) - errorcount++; + do_logv (level, 0, fmt, arg_ptr); } void -log_fatal( const char *fmt, ... ) +log_string (int level, const char *string) { - va_list arg_ptr ; + /* We need to provide a dummy arg_ptr. volatile is needed to + suppress compiler warnings. */ + volatile va_list dummy_arg_ptr; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_FATAL, fmt, arg_ptr ); - va_end(arg_ptr); - abort(); /* never called, but it makes the compiler happy */ + do_logv (level, 1, string, dummy_arg_ptr); } -void -log_bug( const char *fmt, ... ) -{ - va_list arg_ptr ; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_BUG, fmt, arg_ptr ); - va_end(arg_ptr); - abort(); /* never called, but it makes the compiler happy */ +void +log_info (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_INFO, 0, fmt, arg_ptr); + va_end (arg_ptr); } -void -log_debug( const char *fmt, ... ) -{ - va_list arg_ptr ; - va_start( arg_ptr, fmt ) ; - do_logv( JNLIB_LOG_DEBUG, fmt, arg_ptr ); - va_end(arg_ptr); +void +log_error (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_ERROR, 0, fmt, arg_ptr); + va_end (arg_ptr); + /* Protect against counter overflow. */ + if (errorcount < 30000) + errorcount++; +} + + +void +log_fatal (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_FATAL, 0, fmt, arg_ptr); + va_end (arg_ptr); + abort (); /* Never called; just to make the compiler happy. */ +} + + +void +log_bug (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_BUG, 0, fmt, arg_ptr); + va_end (arg_ptr); + abort (); /* Never called; just to make the compiler happy. */ +} + + +void +log_debug (const char *fmt, ...) +{ + va_list arg_ptr ; + + va_start (arg_ptr, fmt); + do_logv (JNLIB_LOG_DEBUG, 0, fmt, arg_ptr); + va_end (arg_ptr); } @@ -580,12 +598,13 @@ void log_printf (const char *fmt, ...) { va_list arg_ptr; - + va_start (arg_ptr, fmt); - do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, fmt, arg_ptr); + do_logv (fmt ? JNLIB_LOG_CONT : JNLIB_LOG_BEGIN, 0, fmt, arg_ptr); va_end (arg_ptr); } + /* Print a hexdump of BUFFER. With TEXT of NULL print just the raw dump, with TEXT just an empty string, print a trailing linefeed, otherwise print an entire debug line. */ @@ -610,17 +629,15 @@ log_printhex (const char *text, const void *buffer, size_t length) void bug_at( const char *file, int line, const char *func ) { - do_log( JNLIB_LOG_BUG, - ("... this is a bug (%s:%d:%s)\n"), file, line, func ); - abort(); /* never called, but it makes the compiler happy */ + do_log (JNLIB_LOG_BUG, ("... this is a bug (%s:%d:%s)\n"), file, line, func); + abort (); /* Never called; just to make the compiler happy. */ } #else void bug_at( const char *file, int line ) { - do_log( JNLIB_LOG_BUG, - _("you found a bug ... (%s:%d)\n"), file, line); - abort(); /* never called, but it makes the compiler happy */ + do_log (JNLIB_LOG_BUG, _("you found a bug ... (%s:%d)\n"), file, line); + abort (); /* Never called; just to make the compiler happy. */ } #endif diff --git a/common/logging.h b/common/logging.h index 7f595273d..f089cf0b5 100644 --- a/common/logging.h +++ b/common/logging.h @@ -65,6 +65,7 @@ enum jnlib_log_levels { JNLIB_LOG_DEBUG }; void log_logv (int level, const char *fmt, va_list arg_ptr); +void log_string (int level, const char *string); #endif /*JNLIB_NEED_LOG_LOGV*/ diff --git a/common/miscellaneous.c b/common/miscellaneous.c index 1c88068f1..396f7224f 100644 --- a/common/miscellaneous.c +++ b/common/miscellaneous.c @@ -26,7 +26,6 @@ #include "iobuf.h" #include "i18n.h" - /* Used by libgcrypt for logging. */ static void my_gcry_logger (void *dummy, int level, const char *fmt, va_list arg_ptr) @@ -97,7 +96,6 @@ setup_libgcrypt_logging (void) } - /* Decide whether the filename is stdout or a real filename and return * an appropriate string. */ const char * diff --git a/g10/ChangeLog b/g10/ChangeLog index b77ed8d9c..878627c12 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,10 @@ +2010-03-11 Werner Koch + + * gpg.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + * server.c (gpg_server): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (needed_libs): Remove libjnlib.a. diff --git a/g10/gpg.c b/g10/gpg.c index 1ca3dceef..b24157b29 100644 --- a/g10/gpg.c +++ b/g10/gpg.c @@ -53,6 +53,7 @@ #include "keyserver-internal.h" #include "exec.h" #include "gc-opt-flags.h" +#include "asshelp.h" #if defined(HAVE_DOSISH_SYSTEM) || defined(__CYGWIN__) #define MY_O_BINARY O_BINARY @@ -2070,8 +2071,8 @@ main (int argc, char **argv) malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); + setup_libassuan_logging (&opt.debug); /* Try for a version specific config file first */ default_configname = get_default_configname (); diff --git a/g10/server.c b/g10/server.c index 3aca9b9de..f67a34677 100644 --- a/g10/server.c +++ b/g10/server.c @@ -735,9 +735,6 @@ gpg_server (ctrl_t ctrl) ctrl->server_local->assuan_ctx = ctx; ctrl->server_local->message_fd = GNUPG_INVALID_FD; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - for (;;) { rc = assuan_accept (ctx); diff --git a/g13/ChangeLog b/g13/ChangeLog index b263b8403..cc51472cc 100644 --- a/g13/ChangeLog +++ b/g13/ChangeLog @@ -1,4 +1,4 @@ -009-11-04 Werner Koch +2009-11-04 Werner Koch Under initial development - no need for a ChangeLog. diff --git a/g13/g13.c b/g13/g13.c index 5058d2c46..28dfa8d36 100644 --- a/g13/g13.c +++ b/g13/g13.c @@ -35,6 +35,7 @@ #include "i18n.h" #include "sysutils.h" #include "gc-opt-flags.h" +#include "asshelp.h" #include "keyblob.h" #include "server.h" #include "runner.h" @@ -432,10 +433,9 @@ main ( int argc, char **argv) } /* Prepare libassuan. */ - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); assuan_set_system_hooks (ASSUAN_SYSTEM_PTH); - + setup_libassuan_logging (&opt.debug); /* Setup a default control structure for command line mode. */ memset (&ctrl, 0, sizeof ctrl); @@ -799,7 +799,9 @@ handle_signal (int signo) case SIGUSR1: log_info ("SIGUSR1 received - printing internal information:\n"); - pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); + /* Fixme: We need to see how to integrate pth dumping into our + logging system. */ + /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */ mountinfo_dump_all (); break; diff --git a/g13/server.c b/g13/server.c index 76bfdf486..0c2b880f4 100644 --- a/g13/server.c +++ b/g13/server.c @@ -642,9 +642,6 @@ g13_server (ctrl_t ctrl) } ctrl->server_local->assuan_ctx = ctx; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - while ( !(err = assuan_accept (ctx)) ) { err = assuan_process (ctx); diff --git a/scd/ChangeLog b/scd/ChangeLog index 44497364d..3bb00f178 100644 --- a/scd/ChangeLog +++ b/scd/ChangeLog @@ -1,3 +1,11 @@ +2010-03-11 Werner Koch + + * scdaemon.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + (handle_signal): Disable pth ctrl dumping. + * command.c (scd_command_handler): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (scdaemon_LDADD): Remove libjnlib.a. diff --git a/scd/command.c b/scd/command.c index 2e7c5b998..fa1d46ce1 100644 --- a/scd/command.c +++ b/scd/command.c @@ -1947,9 +1947,6 @@ scd_command_handler (ctrl_t ctrl, int fd) ctrl->server_local->ctrl_backlink = ctrl; ctrl->server_local->assuan_ctx = ctx; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - /* We open the reader right at startup so that the ticker is able to update the status file. */ if (ctrl->reader_slot == -1) diff --git a/scd/scdaemon.c b/scd/scdaemon.c index fd7d6a22f..9a5e01f31 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -52,6 +52,7 @@ #include "ccid-driver.h" #include "mkdtemp.h" #include "gc-opt-flags.h" +#include "asshelp.h" enum cmd_and_opt_values { aNull = 0, @@ -432,10 +433,10 @@ main (int argc, char **argv ) malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); assuan_set_system_hooks (ASSUAN_SYSTEM_PTH); assuan_sock_init (); + setup_libassuan_logging (&opt.debug); setup_libgcrypt_logging (); gcry_control (GCRYCTL_USE_SECURE_RNDPOOL); @@ -951,7 +952,9 @@ handle_signal (int signo) case SIGUSR1: log_info ("SIGUSR1 received - printing internal information:\n"); - pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); + /* Fixme: We need to see how to integrate pth dumping into our + logging system. */ + /* pth_ctrl (PTH_CTRL_DUMPSTATE, log_get_stream ()); */ app_dump_state (); break; diff --git a/sm/ChangeLog b/sm/ChangeLog index 104f6caaf..ab25af8d4 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,3 +1,10 @@ +2010-03-11 Werner Koch + + * gpgsm.c: Include "asshelp.h". + (main): Remove assuan_set_assuan_log_prefix. Add + assuan_set_log_cb. + * server.c (gpgsm_server): Remove assuan_set_log_stream. + 2010-03-10 Werner Koch * Makefile.am (common_libs): Remove libjnlib.a. Change order. diff --git a/sm/gpgsm.c b/sm/gpgsm.c index 39de29181..8774f7c32 100644 --- a/sm/gpgsm.c +++ b/sm/gpgsm.c @@ -37,7 +37,7 @@ #include "keydb.h" #include "sysutils.h" #include "gc-opt-flags.h" - +#include "asshelp.h" #ifndef O_BINARY #define O_BINARY 0 @@ -982,8 +982,8 @@ main ( int argc, char **argv) malloc_hooks.realloc = gcry_realloc; malloc_hooks.free = gcry_free; assuan_set_malloc_hooks (&malloc_hooks); - assuan_set_assuan_log_prefix (log_get_prefix (NULL)); assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT); + setup_libassuan_logging (&opt.debug); keybox_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free); diff --git a/sm/server.c b/sm/server.c index 42cadcca1..85c061312 100644 --- a/sm/server.c +++ b/sm/server.c @@ -1311,9 +1311,6 @@ gpgsm_server (certlist_t default_recplist) ctrl.server_local->list_external = 0; ctrl.server_local->default_recplist = default_recplist; - if (DBG_ASSUAN) - assuan_set_log_stream (ctx, log_get_stream ()); - for (;;) { rc = assuan_accept (ctx);