Use a custom log handler for libassuan.

This commit is contained in:
Werner Koch 2010-03-11 12:34:11 +00:00
parent 02566c5856
commit 37870234a1
22 changed files with 177 additions and 95 deletions

View File

@ -1,3 +1,12 @@
2010-03-11 Werner Koch <wk@g10code.com>
* 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 <wk@g10code.com>
* Makefile.am (common_libs): Remove libjnlib.a.

View File

@ -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. */
{

View File

@ -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;

View File

@ -1,3 +1,11 @@
2010-03-11 Werner Koch <wk@g10code.com>
* 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 <wk@g10code.com>
* estream.c (es_func_fp_read, es_func_fp_write, es_func_fp_seek)

View File

@ -27,6 +27,7 @@
#include <locale.h>
#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)

View File

@ -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,

View File

@ -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);

View File

@ -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

View File

@ -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*/

View File

@ -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 *

View File

@ -1,3 +1,10 @@
2010-03-11 Werner Koch <wk@g10code.com>
* 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 <wk@g10code.com>
* Makefile.am (needed_libs): Remove libjnlib.a.

View File

@ -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 ();

View File

@ -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);

View File

@ -1,4 +1,4 @@
009-11-04 Werner Koch <wk@g10code.com>
2009-11-04 Werner Koch <wk@g10code.com>
Under initial development - no need for a ChangeLog.

View File

@ -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;

View File

@ -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);

View File

@ -1,3 +1,11 @@
2010-03-11 Werner Koch <wk@g10code.com>
* 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 <wk@g10code.com>
* Makefile.am (scdaemon_LDADD): Remove libjnlib.a.

View File

@ -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)

View File

@ -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;

View File

@ -1,3 +1,10 @@
2010-03-11 Werner Koch <wk@g10code.com>
* 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 <wk@g10code.com>
* Makefile.am (common_libs): Remove libjnlib.a. Change order.

View File

@ -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);

View File

@ -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);