From: Christian Grothoff Date: Sat, 23 Jun 2012 22:24:50 +0000 (+0000) Subject: -LRN: Change logskipping to use functions only: X-Git-Tag: initial-import-from-subversion-38251~12859 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d30c25b427875a16cc46cfd091f595f119e570bc;p=oweals%2Fgnunet.git -LRN: Change logskipping to use functions only: 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. --- diff --git a/src/hostlist/test_gnunet_daemon_hostlist.c b/src/hostlist/test_gnunet_daemon_hostlist.c index f13f86dfa..5f07ce415 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist.c +++ b/src/hostlist/test_gnunet_daemon_hostlist.c @@ -27,10 +27,6 @@ #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, ¬ify_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); } diff --git a/src/hostlist/test_gnunet_daemon_hostlist_learning.c b/src/hostlist/test_gnunet_daemon_hostlist_learning.c index b7d96687c..6f0ab4c9e 100644 --- a/src/hostlist/test_gnunet_daemon_hostlist_learning.c +++ b/src/hostlist/test_gnunet_daemon_hostlist_learning.c @@ -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); diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 63a154390..e0a827911 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -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); /** diff --git a/src/stream/test_stream_api.c b/src/stream/test_stream_api.c index 20581f9b6..e78973dcf 100644 --- a/src/stream/test_stream_api.c +++ b/src/stream/test_stream_api.c @@ -78,6 +78,7 @@ static GNUNET_SCHEDULER_TaskIdentifier read_task; static char *data = "ABCD"; static int result; + /** * Shutdown nicely */ diff --git a/src/util/common_logging.c b/src/util/common_logging.c index ff11c7777..20f852c35 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c @@ -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.