[Pkg-gnupg-commit] [gnupg2] 62/118: common: Add an assuan logging monitor.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 15 18:25:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch encoding-and-speling
in repository gnupg2.

commit 0ac671f8a2b65a4b339f615c6420287a549779fa
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Sep 5 10:55:10 2016 +0200

    common: Add an assuan logging monitor.
    
    * common/asshelp.c (my_log_monitor): New var.
    (my_libassuan_log_handler): Run that monitor.
    (setup_libassuan_logging): Add arg to set a log monitor and change all
    callers.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 agent/gpg-agent.c      |  2 +-
 common/asshelp.c       | 18 +++++++++++++++---
 common/asshelp.h       |  5 ++++-
 dirmngr/dirmngr.c      |  2 +-
 g10/gpg.c              |  2 +-
 g13/g13-syshelp.c      |  2 +-
 g13/g13.c              |  2 +-
 scd/scdaemon.c         |  2 +-
 sm/gpgsm.c             |  2 +-
 tools/gpg-wks-client.c |  2 +-
 10 files changed, 27 insertions(+), 12 deletions(-)

diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index b8a5a3e..79c83a5 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -771,7 +771,7 @@ main (int argc, char **argv )
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
   assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
   assuan_sock_init ();
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
diff --git a/common/asshelp.c b/common/asshelp.c
index c03e67b..bb01a03 100644
--- a/common/asshelp.c
+++ b/common/asshelp.c
@@ -69,6 +69,12 @@
 static int log_cats;
 #define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1))))
 
+/* The assuan log monitor used to temporary inhibit log messages from
+ * assuan.  */
+static int (*my_log_monitor) (assuan_context_t ctx,
+                              unsigned int cat,
+                              const char *msg);
+
 
 static int
 my_libassuan_log_handler (assuan_context_t ctx, void *hook,
@@ -76,8 +82,6 @@ my_libassuan_log_handler (assuan_context_t ctx, void *hook,
 {
   unsigned int dbgval;
 
-  (void)ctx;
-
   if (! TEST_LOG_CAT (cat))
     return 0;
 
@@ -85,6 +89,9 @@ my_libassuan_log_handler (assuan_context_t ctx, void *hook,
   if (!(dbgval & 1024))
     return 0; /* Assuan debugging is not enabled.  */
 
+  if (ctx && my_log_monitor && !my_log_monitor (ctx, cat, msg))
+    return 0; /* Temporary disabled.  */
+
   if (msg)
     log_string (GPGRT_LOG_DEBUG, msg);
 
@@ -95,7 +102,10 @@ my_libassuan_log_handler (assuan_context_t ctx, void *hook,
 /* Setup libassuan to use our own logging functions.  Should be used
    early at startup.  */
 void
-setup_libassuan_logging (unsigned int *debug_var_address)
+setup_libassuan_logging (unsigned int *debug_var_address,
+                         int (*log_monitor)(assuan_context_t ctx,
+                                            unsigned int cat,
+                                            const char *msg))
 {
   char *flagstr;
 
@@ -104,9 +114,11 @@ setup_libassuan_logging (unsigned int *debug_var_address)
     log_cats = atoi (flagstr);
   else /* Default to log the control channel.  */
     log_cats = (1 << (ASSUAN_LOG_CONTROL - 1));
+  my_log_monitor = log_monitor;
   assuan_set_log_cb (my_libassuan_log_handler, debug_var_address);
 }
 
+
 /* Change the Libassuan log categories to those given by NEWCATS.
    NEWCATS is 0 the default category of ASSUAN_LOG_CONTROL is
    selected.  Note, that setup_libassuan_logging overrides the values
diff --git a/common/asshelp.h b/common/asshelp.h
index 4eb1d92..609b203 100644
--- a/common/asshelp.h
+++ b/common/asshelp.h
@@ -38,7 +38,10 @@
 
 /*-- asshelp.c --*/
 
-void setup_libassuan_logging (unsigned int *debug_var_address);
+void setup_libassuan_logging (unsigned int *debug_var_address,
+                              int (*log_monitor)(assuan_context_t ctx,
+                                                 unsigned int cat,
+                                                 const char *msg));
 void set_libassuan_log_cats (unsigned int newcats);
 
 
diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
index 0667e59..2bb57b2 100644
--- a/dirmngr/dirmngr.c
+++ b/dirmngr/dirmngr.c
@@ -702,7 +702,7 @@ main (int argc, char **argv)
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
   assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
   assuan_sock_init ();
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   setup_libgcrypt_logging ();
 
diff --git a/g10/gpg.c b/g10/gpg.c
index 0b0fb7e..9f7da05 100644
--- a/g10/gpg.c
+++ b/g10/gpg.c
@@ -2317,7 +2317,7 @@ main (int argc, char **argv)
     malloc_hooks.free = gcry_free;
     assuan_set_malloc_hooks (&malloc_hooks);
     assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
-    setup_libassuan_logging (&opt.debug);
+    setup_libassuan_logging (&opt.debug, NULL);
 
     /* Try for a version specific config file first */
     default_configname = get_default_configname ();
diff --git a/g13/g13-syshelp.c b/g13/g13-syshelp.c
index 7976be4..7b46239 100644
--- a/g13/g13-syshelp.c
+++ b/g13/g13-syshelp.c
@@ -302,7 +302,7 @@ main ( int argc, char **argv)
   /* Prepare libassuan.  */
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
   /*assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);*/
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   /* Setup a default control structure for command line mode.  */
   memset (&ctrl, 0, sizeof ctrl);
diff --git a/g13/g13.c b/g13/g13.c
index 7744855..33f82d6 100644
--- a/g13/g13.c
+++ b/g13/g13.c
@@ -431,7 +431,7 @@ main ( int argc, char **argv)
   /* Prepare libassuan.  */
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
   assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   /* Setup a default control structure for command line mode.  */
   memset (&ctrl, 0, sizeof ctrl);
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index 514e3c2..bf54d95 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -433,7 +433,7 @@ main (int argc, char **argv )
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
   assuan_set_system_hooks (ASSUAN_SYSTEM_NPTH);
   assuan_sock_init ();
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   setup_libgcrypt_logging ();
   gcry_control (GCRYCTL_USE_SECURE_RNDPOOL);
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index e3b1e88..9bb3053 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -1006,7 +1006,7 @@ main ( int argc, char **argv)
   malloc_hooks.free = gcry_free;
   assuan_set_malloc_hooks (&malloc_hooks);
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   keybox_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free);
 
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index c0e34c4..660d1bd 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -211,7 +211,7 @@ main (int argc, char **argv)
   init_common_subsystems (&argc, &argv);
 
   assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
-  setup_libassuan_logging (&opt.debug);
+  setup_libassuan_logging (&opt.debug, NULL);
 
   /* Parse the command line. */
   pargs.argc  = &argc;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list