-LRN: Change logskipping to use functions only:
authorChristian Grothoff <christian@grothoff.org>
Sat, 23 Jun 2012 22:24:50 +0000 (22:24 +0000)
committerChristian Grothoff <christian@grothoff.org>
Sat, 23 Jun 2012 22:24:50 +0000 (22:24 +0000)
  Remember these weird "skip_log" functions in my gdb backtraces?
I hope that this patch will get rid of them.
Shouldn't affect existing uses of the API.

src/hostlist/test_gnunet_daemon_hostlist.c
src/hostlist/test_gnunet_daemon_hostlist_learning.c
src/include/gnunet_common.h
src/stream/test_stream_api.c
src/util/common_logging.c

index f13f86dfaf9ca7dff3c4528aaba4edcd68d2924b..5f07ce4151e2f465b0fa466e625f7a003f8e5107 100644 (file)
 #include "gnunet_arm_service.h"
 #include "gnunet_transport_service.h"
 
-#define VERBOSE GNUNET_NO
-
-#define START_ARM GNUNET_YES
-
 
 /**
  * How long until we give up on transmitting the message?
@@ -47,9 +43,7 @@ struct PeerContext
   struct GNUNET_TRANSPORT_Handle *th;
   struct GNUNET_MessageHeader *hello;
   struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
-#if START_ARM
   struct GNUNET_OS_Process *arm_proc;
-#endif
 };
 
 static struct PeerContext p1;
@@ -138,12 +132,10 @@ static void
 setup_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
-#if START_ARM
   p->arm_proc =
       GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm",
                                "-c", cfgname, NULL);
-#endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
   p->th =
       GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, &notify_connect, NULL);
@@ -157,7 +149,6 @@ waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct PeerContext *p = cls;
 
-#if START_ARM
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Killing ARM process.\n");
   if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
@@ -167,7 +158,6 @@ waitpid_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
               GNUNET_OS_process_get_pid (p->arm_proc));
   GNUNET_OS_process_destroy (p->arm_proc);
   p->arm_proc = NULL;
-#endif
   GNUNET_CONFIGURATION_destroy (p->cfg);
 }
 
index b7d96687c63b8dae76e4951df439449a9bc42630..6f0ab4c9e29261488c0405f16ba3c8b329a705a2 100644 (file)
@@ -30,8 +30,6 @@
 #include "gnunet_resolver_service.h"
 #include "gnunet_statistics_service.h"
 
-#define START_ARM GNUNET_YES
-
 #define MAX_URL_LEN 1000
 
 /**
@@ -49,9 +47,7 @@ struct PeerContext
   struct GNUNET_MessageHeader *hello;
   struct GNUNET_CORE_Handle *core;
   struct GNUNET_STATISTICS_Handle *stats;
-#if START_ARM
   struct GNUNET_OS_Process *arm_proc;
-#endif
 };
 
 static int timeout;
@@ -147,7 +143,6 @@ shutdown_testcase ()
     GNUNET_CORE_disconnect (learn_peer.core);
     learn_peer.core = NULL;
   }
-#if START_ARM
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Killing hostlist server ARM process.\n");
   if (0 != GNUNET_OS_process_kill (adv_peer.arm_proc, SIGTERM))
@@ -164,7 +159,6 @@ shutdown_testcase ()
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
   GNUNET_OS_process_destroy (learn_peer.arm_proc);
   learn_peer.arm_proc = NULL;
-#endif
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown complete....\n");
 }
 
@@ -390,12 +384,10 @@ setup_learn_peer (struct PeerContext *p, const char *cfgname)
   unsigned int result;
 
   p->cfg = GNUNET_CONFIGURATION_create ();
-#if START_ARM
   p->arm_proc =
     GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm",
                                "-c", cfgname, NULL);
-#endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
   if (GNUNET_OK ==
       GNUNET_CONFIGURATION_get_value_string (p->cfg, "HOSTLIST", "HOSTLISTFILE",
@@ -423,12 +415,10 @@ static void
 setup_adv_peer (struct PeerContext *p, const char *cfgname)
 {
   p->cfg = GNUNET_CONFIGURATION_create ();
-#if START_ARM
   p->arm_proc =
     GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-arm",
                                "gnunet-service-arm",
                                "-c", cfgname, NULL);
-#endif
   GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
   p->stats = GNUNET_STATISTICS_create ("hostlist", p->cfg);
   GNUNET_assert (NULL != p->stats);
index 63a154390b67ab80ae2de0cbfa3c4a440ccc45f1..e0a827911b4598a6271b4d3a8cf4eab479131018 100644 (file)
@@ -284,9 +284,12 @@ typedef void (*GNUNET_Logger) (void *cls, enum GNUNET_ErrorType kind,
 
 
 /**
- * Number of log calls to ignore.
+ * Get the number of log calls that are going to be skipped
+ *
+ * @return number of log calls to be ignored
  */
-extern unsigned int skip_log;
+int
+GNUNET_get_log_skip ();
 
 #if !defined(GNUNET_CULL_LOGGING)
 int
@@ -344,7 +347,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
   if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \
     if (GN_UNLIKELY(log_call_enabled == -1))\
       log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), (comp), __FILE__, __FUNCTION__, log_line); \
-    if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
+    if (GN_UNLIKELY(GNUNET_get_log_skip () > 0)) { GNUNET_log_skip (-1, GNUNET_NO); }\
     else {\
       if (GN_UNLIKELY(log_call_enabled))\
         GNUNET_log_from_nocheck ((kind), comp, __VA_ARGS__);   \
@@ -357,7 +360,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
   if ((GNUNET_EXTRA_LOGGING > 0) || ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0)) { \
     if (GN_UNLIKELY(log_call_enabled == -1))\
       log_call_enabled = GNUNET_get_log_call_status ((kind) & (~GNUNET_ERROR_TYPE_BULK), NULL, __FILE__, __FUNCTION__, log_line);\
-    if (GN_UNLIKELY(skip_log > 0)) {skip_log--;}\
+    if (GN_UNLIKELY(GNUNET_get_log_skip () > 0)) { GNUNET_log_skip (-1, GNUNET_NO); }\
     else {\
       if (GN_UNLIKELY(log_call_enabled))\
         GNUNET_log_nocheck ((kind), __VA_ARGS__);      \
@@ -379,11 +382,11 @@ GNUNET_abort (void) GNUNET_NORETURN;
 /**
  * Ignore the next n calls to the log function.
  *
- * @param n number of log calls to ignore
+ * @param n number of log calls to ignore (could be negative)
  * @param check_reset GNUNET_YES to assert that the log skip counter is currently zero
  */
 void
-GNUNET_log_skip (unsigned int n, int check_reset);
+GNUNET_log_skip (int n, int check_reset);
 
 
 /**
index 20581f9b6f62f31a6765d9a8ea76b5d2a5ee1614..e78973dcf6d473cd4a75776de23f733384000dc8 100644 (file)
@@ -78,6 +78,7 @@ static GNUNET_SCHEDULER_TaskIdentifier read_task;
 static char *data = "ABCD";
 static int result;
 
+
 /**
  * Shutdown nicely
  */
index ff11c777733d57046894f35142040ddffd58729d..20f852c35660c4bd53fc52c441f24154ff884614 100644 (file)
@@ -152,7 +152,7 @@ static struct CustomLogger *loggers;
 /**
  * Number of log calls to ignore.
  */
-unsigned int skip_log;
+int skip_log = 0;
 
 /**
  * File descriptor to use for "stderr", or NULL for none.
@@ -810,11 +810,11 @@ flush_bulk (const char *datestr)
 /**
  * Ignore the next n calls to the log function.
  *
- * @param n number of log calls to ignore
+ * @param n number of log calls to ignore (could be negative)
  * @param check_reset GNUNET_YES to assert that the log skip counter is currently zero
  */
 void
-GNUNET_log_skip (unsigned int n, int check_reset)
+GNUNET_log_skip (int n, int check_reset)
 {
   int ok;
 
@@ -831,6 +831,16 @@ GNUNET_log_skip (unsigned int n, int check_reset)
   }
 }
 
+/**
+ * Get the number of log calls that are going to be skipped
+ *
+ * @return number of log calls to be ignored
+ */
+int
+GNUNET_get_log_skip ()
+{
+  return skip_log;
+}
 
 /**
  * Output a log message using the default mechanism.