X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Futil%2Fcommon_logging.c;h=23749dd99f6c9ac16e5622a965a71b2310f5d0a3;hb=27520ef39b732562a6c4ffa8640b44250ad72a4a;hp=ff11c777733d57046894f35142040ddffd58729d;hpb=ce0a88b825f63e418e034a1bdfc377e91da5e770;p=oweals%2Fgnunet.git diff --git a/src/util/common_logging.c b/src/util/common_logging.c index ff11c7777..23749dd99 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. @@ -336,11 +336,22 @@ setup_log_file (const struct tm *tm) int altlog_fd; int dup_return; FILE *altlog; + char *leftsquare; if (NULL == log_file_name) return GNUNET_SYSERR; if (0 == strftime (fn, sizeof (fn), log_file_name, tm)) return GNUNET_SYSERR; + leftsquare = strrchr (fn, '['); + if ( (NULL != leftsquare) && (']' == leftsquare[1]) ) + { + char *logfile_copy = GNUNET_strdup (fn); + logfile_copy[leftsquare - fn] = '\0'; + logfile_copy[leftsquare - fn + 1] = '\0'; + snprintf (fn, PATH_MAX, "%s%d%s", + logfile_copy, getpid (), &logfile_copy[leftsquare - fn + 2]); + GNUNET_free (logfile_copy); + } if (0 == strcmp (fn, last_fn)) return GNUNET_OK; /* no change */ log_rotate (last_fn); @@ -737,6 +748,10 @@ GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls) GNUNET_free (pos); } +#if WINDOWS +CRITICAL_SECTION output_message_cs; +#endif + /** * Actually output the log message. @@ -751,7 +766,9 @@ output_message (enum GNUNET_ErrorType kind, const char *comp, const char *datestr, const char *msg) { struct CustomLogger *pos; - +#if WINDOWS + EnterCriticalSection (&output_message_cs); +#endif if (NULL != GNUNET_stderr) { FPRINTF (GNUNET_stderr, "%s %s %s %s", datestr, comp, @@ -764,6 +781,9 @@ output_message (enum GNUNET_ErrorType kind, const char *comp, pos->logger (pos->logger_cls, kind, comp, datestr, msg); pos = pos->next; } +#if WINDOWS + LeaveCriticalSection (&output_message_cs); +#endif } @@ -778,7 +798,7 @@ flush_bulk (const char *datestr) char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256]; int rev; char *last; - char *ft; + const char *ft; if ((last_bulk_time.abs_value == 0) || (last_bulk_repeat == 0)) return; @@ -794,11 +814,10 @@ flush_bulk (const char *datestr) last[0] = '\0'; } ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration - (last_bulk_time)); + (last_bulk_time), GNUNET_YES); snprintf (msg, sizeof (msg), _("Message `%.*s' repeated %u times in the last %s\n"), BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft); - GNUNET_free (ft); if (rev == 1) last[0] = '\n'; output_message (last_bulk_kind, last_bulk_comp, datestr, msg); @@ -810,11 +829,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 +850,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. @@ -892,7 +921,8 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, } #endif VSNPRINTF (buf, size, message, va); - (void) setup_log_file (tmptr); + if (NULL != tmptr) + (void) setup_log_file (tmptr); if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) && (last_bulk_time.abs_value != 0) && (0 == strncmp (buf, last_bulk, sizeof (last_bulk)))) @@ -981,6 +1011,43 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind) } +/** + * Convert a short hash to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string form; will be overwritten by next call to GNUNET_h2s. + */ +const char * +GNUNET_short_h2s (const struct GNUNET_CRYPTO_ShortHashCode * hc) +{ + static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret; + + GNUNET_CRYPTO_short_hash_to_enc (hc, &ret); + ret.short_encoding[8] = '\0'; + return (const char *) ret.short_encoding; +} + + +/** + * Convert a short hash to a string (for printing debug messages). + * This is one of the very few calls in the entire API that is + * NOT reentrant! + * + * @param hc the short hash code + * @return string form; will be overwritten by next call to GNUNET_h2s_full. + */ +const char * +GNUNET_short_h2s_full (const struct GNUNET_CRYPTO_ShortHashCode * hc) +{ + static struct GNUNET_CRYPTO_ShortHashAsciiEncoded ret; + + GNUNET_CRYPTO_short_hash_to_enc (hc, &ret); + ret.short_encoding[sizeof (ret) - 1] = '\0'; + return (const char *) ret.short_encoding; +} + /** * Convert a hash to a string (for printing debug messages). * This is one of the very few calls in the entire API that is @@ -1122,6 +1189,45 @@ GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen) } +/** + * Log error message about missing configuration option. + * + * @param kind log level + * @param section section with missing option + * @param option name of missing option + */ +void +GNUNET_log_config_missing (enum GNUNET_ErrorType kind, + const char *section, + const char *option) +{ + GNUNET_log (kind, + _("Configuration fails to specify option `%s' in section `%s'!\n"), + option, + section); +} + + +/** + * Log error message about invalid configuration option value. + * + * @param kind log level + * @param section section with invalid option + * @param option name of invalid option + * @param required what is required that is invalid about the option + */ +void +GNUNET_log_config_invalid (enum GNUNET_ErrorType kind, + const char *section, + const char *option, + const char *required) +{ + GNUNET_log (kind, + _("Configuration specifies invalid value for option `%s' in section `%s': %s\n"), + option, section, required); +} + + /** * Initializer */ @@ -1131,6 +1237,10 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init () #ifdef MINGW GNInitWinEnv (NULL); #endif +#if WINDOWS + if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400)) + GNUNET_abort (); +#endif } @@ -1139,6 +1249,9 @@ void __attribute__ ((constructor)) GNUNET_util_cl_init () */ void __attribute__ ((destructor)) GNUNET_util_cl_fini () { +#if WINDOWS + DeleteCriticalSection (&output_message_cs); +#endif #ifdef MINGW GNShutdownWinEnv (); #endif