2 This file is part of GNUnet.
3 (C) 2006-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file util/common_logging.c
23 * @brief error handling API
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
32 * After how many milliseconds do we always print
33 * that "message X was repeated N times"? Use 12h.
35 #define BULK_DELAY_THRESHOLD (12 * 60 * 60 * 1000LL * 1000LL)
38 * After how many repetitions do we always print
39 * that "message X was repeated N times"? (even if
40 * we have not yet reached the delay threshold)
42 #define BULK_REPEAT_THRESHOLD 1000
45 * How many characters do we use for matching of
48 #define BULK_TRACK_SIZE 256
51 * How many characters do we use for matching of
54 #define COMP_TRACK_SIZE 32
57 * How many characters can a date/time string
60 #define DATE_STR_SIZE 64
63 * How many log files to keep?
65 #define ROTATION_KEEP 3
69 * Assumed maximum path length (for the log file name).
76 * Linked list of active loggers.
81 * This is a linked list.
83 struct CustomLogger *next;
97 * The last "bulk" error message that we have been logging.
98 * Note that this message maybe truncated to the first BULK_TRACK_SIZE
99 * characters, in which case it is NOT 0-terminated!
101 static char last_bulk[BULK_TRACK_SIZE];
104 * Type of the last bulk message.
106 static enum GNUNET_ErrorType last_bulk_kind;
109 * Time of the last bulk error message (0 for none)
111 static struct GNUNET_TIME_Absolute last_bulk_time;
114 * Number of times that bulk message has been repeated since.
116 static unsigned int last_bulk_repeat;
119 * Component when the last bulk was logged. Will be 0-terminated.
121 static char last_bulk_comp[COMP_TRACK_SIZE + 1];
126 static char *component;
129 * Running component (without pid).
131 static char *component_nopid;
134 * Format string describing the name of the log file.
136 static char *log_file_name;
141 static enum GNUNET_ErrorType min_level;
144 * Linked list of our custom loggres.
146 static struct CustomLogger *loggers;
149 * Number of log calls to ignore.
154 * File descriptor to use for "stderr", or NULL for none.
156 static FILE *GNUNET_stderr;
159 * Represents a single logging definition
164 * Component name regex
166 regex_t component_regex;
174 * Function name regex
176 regex_t function_regex;
179 * Lowest line at which this definition matches.
180 * Defaults to 0. Must be <= to_line.
185 * Highest line at which this definition matches.
186 * Defaults to INT_MAX. Must be >= from_line.
191 * Maximal log level allowed for calls that match this definition.
192 * Calls with higher log level will be disabled.
198 * 1 if this definition comes from GNUNET_FORCE_LOG, which means that it
199 * overrides any configuration options. 0 otherwise.
205 * Dynamic array of logging definitions
207 static struct LogDef *logdefs;
210 * Allocated size of logdefs array (in units)
212 static int logdefs_size;
215 * The number of units used in logdefs array.
217 static int logdefs_len;
220 * GNUNET_YES if GNUNET_LOG environment variable is already parsed.
222 static int gnunet_log_parsed;
225 * GNUNET_YES if GNUNET_FORCE_LOG environment variable is already parsed.
227 static int gnunet_force_log_parsed;
230 * GNUNET_YES if at least one definition with forced == 1 is available.
232 static int gnunet_force_log_present;
236 * Contains the number of performance counts per second.
238 static LARGE_INTEGER performance_frequency;
243 * Convert a textual description of a loglevel
244 * to the respective GNUNET_GE_KIND.
246 * @param log loglevel to parse
247 * @return GNUNET_GE_INVALID if log does not parse
249 static enum GNUNET_ErrorType
250 get_type (const char *log)
253 return GNUNET_ERROR_TYPE_UNSPECIFIED;
254 if (0 == strcasecmp (log, _("DEBUG")))
255 return GNUNET_ERROR_TYPE_DEBUG;
256 if (0 == strcasecmp (log, _("INFO")))
257 return GNUNET_ERROR_TYPE_INFO;
258 if (0 == strcasecmp (log, _("WARNING")))
259 return GNUNET_ERROR_TYPE_WARNING;
260 if (0 == strcasecmp (log, _("ERROR")))
261 return GNUNET_ERROR_TYPE_ERROR;
262 if (0 == strcasecmp (log, _("NONE")))
263 return GNUNET_ERROR_TYPE_NONE;
264 return GNUNET_ERROR_TYPE_INVALID;
268 #if !defined(GNUNET_CULL_LOGGING)
270 * Utility function - reallocates logdefs array to be twice as large.
275 logdefs_size = (logdefs_size + 1) * 2;
276 logdefs = GNUNET_realloc (logdefs, logdefs_size * sizeof (struct LogDef));
281 * Abort the process, generate a core dump if possible.
294 * Rotate logs, deleting the oldest log.
296 * @param new_name new name to add to the rotation
299 log_rotate (const char *new_name)
301 static char *rotation[ROTATION_KEEP];
302 static unsigned int rotation_off;
305 if ('\0' == *new_name)
306 return; /* not a real log file name */
307 discard = rotation[rotation_off % ROTATION_KEEP];
310 /* Note: can't log errors during logging (recursion!), so this
311 operation MUST silently fail... */
312 (void) UNLINK (discard);
313 GNUNET_free (discard);
315 rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name);
321 * Setup the log file.
323 * @param tm timestamp for which we should setup logging
324 * @return GNUNET_OK on success, GNUNET_SYSERR on error
327 setup_log_file (const struct tm *tm)
329 static char last_fn[PATH_MAX + 1];
330 char fn[PATH_MAX + 1];
337 if (NULL == log_file_name)
338 return GNUNET_SYSERR;
339 if (0 == strftime (fn, sizeof (fn), log_file_name, tm))
340 return GNUNET_SYSERR;
341 leftsquare = strrchr (fn, '[');
342 if ( (NULL != leftsquare) && (']' == leftsquare[1]) )
344 char *logfile_copy = GNUNET_strdup (fn);
345 logfile_copy[leftsquare - fn] = '\0';
346 logfile_copy[leftsquare - fn + 1] = '\0';
347 snprintf (fn, PATH_MAX, "%s%d%s",
348 logfile_copy, getpid (), &logfile_copy[leftsquare - fn + 2]);
349 GNUNET_free (logfile_copy);
351 if (0 == strcmp (fn, last_fn))
352 return GNUNET_OK; /* no change */
353 log_rotate (last_fn);
354 strcpy (last_fn, fn);
355 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
357 altlog_fd = OPEN (fn, O_APPEND |
360 _S_IREAD | _S_IWRITE);
362 altlog_fd = OPEN (fn, O_APPEND |
364 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
368 if (NULL != GNUNET_stderr)
369 fclose (GNUNET_stderr);
370 dup_return = dup2 (altlog_fd, 2);
371 (void) close (altlog_fd);
372 if (-1 != dup_return)
374 altlog = fdopen (2, "ab");
388 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
390 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
391 _("Failed to create or access directory for log file `%s'\n"),
393 return GNUNET_SYSERR;
395 GNUNET_stderr = altlog;
400 * Utility function - adds a parsed definition to logdefs array.
402 * @param component see struct LogDef, can't be NULL
403 * @param file see struct LogDef, can't be NULL
404 * @param function see struct LogDef, can't be NULL
405 * @param from_line see struct LogDef
406 * @param to_line see struct LogDef
407 * @param level see struct LogDef, must be >= 0
408 * @param force see struct LogDef
409 * @return 0 on success, regex-specific error otherwise
412 add_definition (char *component, char *file, char *function, int from_line,
413 int to_line, int level, int force)
418 if (logdefs_size == logdefs_len)
420 memset (&n, 0, sizeof (n));
421 if (0 == strlen (component))
422 component = (char *) ".*";
423 r = regcomp (&n.component_regex, (const char *) component, REG_NOSUB);
428 if (0 == strlen (file))
429 file = (char *) ".*";
430 r = regcomp (&n.file_regex, (const char *) file, REG_NOSUB);
433 regfree (&n.component_regex);
436 if ((NULL == function) || (0 == strlen (function)))
437 function = (char *) ".*";
438 r = regcomp (&n.function_regex, (const char *) function, REG_NOSUB);
441 regfree (&n.component_regex);
442 regfree (&n.file_regex);
445 n.from_line = from_line;
449 logdefs[logdefs_len++] = n;
455 * Decides whether a particular logging call should or should not be allowed
456 * to be made. Used internally by GNUNET_log*()
458 * @param caller_level loglevel the caller wants to use
459 * @param comp component name the caller uses (NULL means that global
460 * component name is used)
461 * @param file file name containing the logging call, usually __FILE__
462 * @param function function which tries to make a logging call,
463 * usually __FUNCTION__
464 * @param line line at which the call is made, usually __LINE__
465 * @return 0 to disallow the call, 1 to allow it
468 GNUNET_get_log_call_status (int caller_level, const char *comp,
469 const char *file, const char *function, int line)
476 /* Use default component */
477 comp = component_nopid;
479 /* We have no definitions to override globally configured log level,
480 * so just use it right away.
482 if ( (min_level >= 0) && (GNUNET_NO == gnunet_force_log_present) )
483 return caller_level <= min_level;
485 /* Only look for forced definitions? */
486 force_only = min_level >= 0;
487 for (i = 0; i < logdefs_len; i++)
490 if (( (!force_only) || ld->force) &&
491 (line >= ld->from_line && line <= ld->to_line) &&
492 (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) &&
493 (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) &&
494 (0 == regexec (&ld->function_regex, function, 0, NULL, 0)))
497 return caller_level <= ld->level;
500 /* No matches - use global level, if defined */
502 return caller_level <= min_level;
503 /* All programs/services previously defaulted to WARNING.
504 * Now WE default to WARNING, and THEY default to NULL.
506 return caller_level <= GNUNET_ERROR_TYPE_WARNING;
511 * Utility function - parses a definition
514 * component;file;function;from_line-to_line;level[/component...]
515 * All entries are mandatory, but may be empty.
516 * Empty entries for component, file and function are treated as
517 * "matches anything".
518 * Empty line entry is treated as "from 0 to INT_MAX"
519 * Line entry with only one line is treated as "this line only"
520 * Entry for level MUST NOT be empty.
521 * Entries for component, file and function that consist of a
522 * single character "*" are treated (at the moment) the same way
523 * empty entries are treated (wildcard matching is not implemented (yet?)).
524 * file entry is matched to the end of __FILE__. That is, it might be
525 * a base name, or a base name with leading directory names (some compilers
526 * define __FILE__ to absolute file path).
528 * @param constname name of the environment variable from which to get the
529 * string to be parsed
530 * @param force 1 if definitions found in constname are to be forced
531 * @return number of added definitions
534 parse_definitions (const char *constname, int force)
540 char *function = NULL;
546 int from_line, to_line;
548 int keep_looking = 1;
550 tmp = getenv (constname);
553 def = GNUNET_strdup (tmp);
556 for (p = def, state = 0, start = def; keep_looking; p++)
560 case ';': /* found a field separator */
564 case 0: /* within a component name */
567 case 1: /* within a file name */
570 case 2: /* within a function name */
571 /* after a file name there must be a function name */
574 case 3: /* within a from-to line range */
575 if (strlen (start) > 0)
578 from_line = strtol (start, &t, 10);
579 if ( (0 != errno) || (from_line < 0) )
584 if ( (t < p) && ('-' == t[0]) )
588 to_line = strtol (start, &t, 10);
589 if ( (0 != errno) || (to_line < 0) || (t != p) )
595 else /* one number means "match this line only" */
598 else /* default to 0-max */
608 case '\0': /* found EOL */
610 /* fall through to '/' */
611 case '/': /* found a definition separator */
614 case 4: /* within a log level */
617 level = get_type ((const char *) start);
618 if ( (GNUNET_ERROR_TYPE_INVALID == level) ||
619 (GNUNET_ERROR_TYPE_UNSPECIFIED == level) ||
620 (0 != add_definition (comp, file, function, from_line, to_line,
642 * Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG.
645 parse_all_definitions ()
647 if (GNUNET_NO == gnunet_log_parsed)
648 parse_definitions ("GNUNET_LOG", 0);
649 gnunet_log_parsed = GNUNET_YES;
650 if (GNUNET_NO == gnunet_force_log_parsed)
651 gnunet_force_log_present =
652 parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
653 gnunet_force_log_parsed = GNUNET_YES;
661 * @param comp default component to use
662 * @param loglevel what types of messages should be logged
663 * @param logfile which file to write log messages to (can be NULL)
664 * @return #GNUNET_OK on success
667 GNUNET_log_setup (const char *comp,
668 const char *loglevel,
671 const char *env_logfile;
675 min_level = get_type (loglevel);
676 #if !defined(GNUNET_CULL_LOGGING)
677 parse_all_definitions ();
680 QueryPerformanceFrequency (&performance_frequency);
682 GNUNET_free_non_null (component);
683 GNUNET_asprintf (&component, "%s-%d", comp, getpid ());
684 GNUNET_free_non_null (component_nopid);
685 component_nopid = GNUNET_strdup (comp);
687 env_logfile = getenv ("GNUNET_FORCE_LOGFILE");
688 if ((NULL != env_logfile) && (strlen (env_logfile) > 0))
689 logfile = env_logfile;
692 GNUNET_free_non_null (log_file_name);
693 log_file_name = GNUNET_STRINGS_filename_expand (logfile);
694 if (NULL == log_file_name)
695 return GNUNET_SYSERR;
698 return setup_log_file (tm);
703 * Add a custom logger.
705 * @param logger log function
706 * @param logger_cls closure for logger
709 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls)
711 struct CustomLogger *entry;
713 entry = GNUNET_malloc (sizeof (struct CustomLogger));
714 entry->logger = logger;
715 entry->logger_cls = logger_cls;
716 entry->next = loggers;
722 * Remove a custom logger.
724 * @param logger log function
725 * @param logger_cls closure for logger
728 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
730 struct CustomLogger *pos;
731 struct CustomLogger *prev;
735 while ((pos != NULL) &&
736 ((pos->logger != logger) || (pos->logger_cls != logger_cls)))
741 GNUNET_assert (pos != NULL);
745 prev->next = pos->next;
750 CRITICAL_SECTION output_message_cs;
755 * Actually output the log message.
757 * @param kind how severe was the issue
758 * @param comp component responsible
759 * @param datestr current date/time
760 * @param msg the actual message
763 output_message (enum GNUNET_ErrorType kind, const char *comp,
764 const char *datestr, const char *msg)
766 struct CustomLogger *pos;
768 EnterCriticalSection (&output_message_cs);
770 if (NULL != GNUNET_stderr)
772 FPRINTF (GNUNET_stderr, "%s %s %s %s", datestr, comp,
773 GNUNET_error_type_to_string (kind), msg);
774 fflush (GNUNET_stderr);
779 pos->logger (pos->logger_cls, kind, comp, datestr, msg);
783 LeaveCriticalSection (&output_message_cs);
789 * Flush an existing bulk report to the output.
791 * @param datestr our current timestamp
794 flush_bulk (const char *datestr)
796 char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256];
801 if ((0 == last_bulk_time.abs_value_us) || (0 == last_bulk_repeat))
804 last = memchr (last_bulk, '\0', BULK_TRACK_SIZE);
806 last = &last_bulk[BULK_TRACK_SIZE - 1];
807 else if (last != last_bulk)
814 ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
815 (last_bulk_time), GNUNET_YES);
816 snprintf (msg, sizeof (msg),
817 _("Message `%.*s' repeated %u times in the last %s\n"),
818 BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
821 output_message (last_bulk_kind, last_bulk_comp, datestr, msg);
822 last_bulk_time = GNUNET_TIME_absolute_get ();
823 last_bulk_repeat = 0;
828 * Ignore the next n calls to the log function.
830 * @param n number of log calls to ignore (could be negative)
831 * @param check_reset #GNUNET_YES to assert that the log skip counter is currently zero
834 GNUNET_log_skip (int n,
841 ok = (0 == skip_log);
854 * Get the number of log calls that are going to be skipped
856 * @return number of log calls to be ignored
859 GNUNET_get_log_skip ()
866 * Output a log message using the default mechanism.
868 * @param kind how severe was the issue
869 * @param comp component responsible
870 * @param message the actual message
871 * @param va arguments to the format string "message"
874 mylog (enum GNUNET_ErrorType kind,
879 char date[DATE_STR_SIZE];
880 char date2[DATE_STR_SIZE];
886 size = VSNPRINTF (NULL, 0, message, vacp) + 1;
887 GNUNET_assert (0 != size);
889 memset (date, 0, DATE_STR_SIZE);
897 offset = GNUNET_TIME_get_offset ();
899 timetmp += offset / 1000;
900 tmptr = localtime (&timetmp);
902 QueryPerformanceCounter (&pc);
905 strcpy (date, "localtime error");
909 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr);
910 snprintf (date, sizeof (date), date2,
911 (long long) (pc.QuadPart /
912 (performance_frequency.QuadPart / 1000)));
915 struct timeval timeofday;
917 gettimeofday (&timeofday, NULL);
918 offset = GNUNET_TIME_get_offset ();
921 timeofday.tv_sec += offset / 1000LL;
922 timeofday.tv_usec += (offset % 1000LL) * 1000LL;
923 if (timeofday.tv_usec > 1000000LL)
925 timeofday.tv_usec -= 1000000LL;
931 timeofday.tv_sec += offset / 1000LL;
932 if (timeofday.tv_usec > - (offset % 1000LL) * 1000LL)
934 timeofday.tv_usec += (offset % 1000LL) * 1000LL;
938 timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL;
942 tmptr = localtime (&timeofday.tv_sec);
945 strcpy (date, "localtime error");
949 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr);
950 snprintf (date, sizeof (date), date2, timeofday.tv_usec);
953 VSNPRINTF (buf, size, message, va);
955 (void) setup_log_file (tmptr);
956 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&
957 (0 != last_bulk_time.abs_value_us) &&
958 (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
961 if ( (GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value_us >
962 BULK_DELAY_THRESHOLD) ||
963 (last_bulk_repeat > BULK_REPEAT_THRESHOLD) )
968 strncpy (last_bulk, buf, sizeof (last_bulk));
969 last_bulk_repeat = 0;
970 last_bulk_kind = kind;
971 last_bulk_time = GNUNET_TIME_absolute_get ();
972 strncpy (last_bulk_comp, comp, COMP_TRACK_SIZE);
973 output_message (kind, comp, date, buf);
981 * @param kind how serious is the error?
982 * @param message what is the message (format string)
983 * @param ... arguments for format string
986 GNUNET_log_nocheck (enum GNUNET_ErrorType kind,
987 const char *message, ...)
991 va_start (va, message);
992 mylog (kind, component, message, va);
998 * Log function that specifies an alternative component.
999 * This function should be used by plugins.
1001 * @param kind how serious is the error?
1002 * @param comp component responsible for generating the message
1003 * @param message what is the message (format string)
1004 * @param ... arguments for format string
1007 GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
1008 const char *message, ...)
1011 char comp_w_pid[128];
1014 comp = component_nopid;
1016 va_start (va, message);
1017 GNUNET_snprintf (comp_w_pid, sizeof (comp_w_pid), "%s-%d", comp, getpid ());
1018 mylog (kind, comp_w_pid, message, va);
1024 * Convert error type to string.
1026 * @param kind type to convert
1027 * @return string corresponding to the type
1030 GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
1032 if ((kind & GNUNET_ERROR_TYPE_ERROR) > 0)
1034 if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0)
1035 return _("WARNING");
1036 if ((kind & GNUNET_ERROR_TYPE_INFO) > 0)
1038 if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0)
1040 if ((kind & ~GNUNET_ERROR_TYPE_BULK) == 0)
1042 return _("INVALID");
1047 * Convert a hash to a string (for printing debug messages).
1048 * This is one of the very few calls in the entire API that is
1051 * @param hc the hash code
1052 * @return string form; will be overwritten by next call to GNUNET_h2s.
1055 GNUNET_h2s (const struct GNUNET_HashCode * hc)
1057 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1059 GNUNET_CRYPTO_hash_to_enc (hc, &ret);
1060 ret.encoding[8] = '\0';
1061 return (const char *) ret.encoding;
1066 * Convert a hash to a string (for printing debug messages).
1067 * This is one of the very few calls in the entire API that is
1070 * @param hc the hash code
1071 * @return string form; will be overwritten by next call to GNUNET_h2s_full.
1074 GNUNET_h2s_full (const struct GNUNET_HashCode * hc)
1076 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1078 GNUNET_CRYPTO_hash_to_enc (hc, &ret);
1079 ret.encoding[sizeof (ret) - 1] = '\0';
1080 return (const char *) ret.encoding;
1085 * Convert a peer identity to a string (for printing debug messages).
1086 * This is one of the very few calls in the entire API that is
1089 * @param pid the peer identity
1090 * @return string form of the pid; will be overwritten by next
1091 * call to #GNUNET_i2s.
1094 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
1096 static char buf[256];
1099 ret = GNUNET_CRYPTO_ecc_public_sign_key_to_string (&pid->public_key);
1108 * Convert a peer identity to a string (for printing debug messages).
1109 * This is one of the very few calls in the entire API that is
1112 * @param pid the peer identity
1113 * @return string form of the pid; will be overwritten by next
1114 * call to #GNUNET_i2s_full.
1117 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid)
1119 static char buf[256];
1122 ret = GNUNET_CRYPTO_ecc_public_sign_key_to_string (&pid->public_key);
1130 * Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string
1131 * (for printing debug messages). This is one of the very few calls
1132 * in the entire API that is NOT reentrant!
1134 * @param addr the address
1135 * @param addrlen the length of the address
1136 * @return nicely formatted string for the address
1137 * will be overwritten by next call to GNUNET_a2s.
1140 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
1142 static char buf[INET6_ADDRSTRLEN + 8];
1144 const struct sockaddr_in *v4;
1145 const struct sockaddr_un *un;
1146 const struct sockaddr_in6 *v6;
1150 return _("unknown address");
1151 switch (addr->sa_family)
1154 if (addrlen != sizeof (struct sockaddr_in))
1155 return "<invalid v4 address>";
1156 v4 = (const struct sockaddr_in *) addr;
1157 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
1158 if (0 == ntohs (v4->sin_port))
1161 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
1165 if (addrlen != sizeof (struct sockaddr_in6))
1166 return "<invalid v4 address>";
1167 v6 = (const struct sockaddr_in6 *) addr;
1169 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
1170 if (0 == ntohs (v6->sin6_port))
1173 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
1177 if (addrlen <= sizeof (sa_family_t))
1178 return "<unbound UNIX client>";
1179 un = (const struct sockaddr_un *) addr;
1181 if (un->sun_path[0] == '\0')
1183 memset (buf, 0, sizeof (buf));
1184 snprintf (buf, sizeof (buf) - 1, "%s%.*s", (off == 1) ? "@" : "",
1185 (int) (addrlen - sizeof (sa_family_t) - 1 - off),
1186 &un->sun_path[off]);
1189 return _("invalid address");
1195 * Log error message about missing configuration option.
1197 * @param kind log level
1198 * @param section section with missing option
1199 * @param option name of missing option
1202 GNUNET_log_config_missing (enum GNUNET_ErrorType kind,
1203 const char *section,
1207 _("Configuration fails to specify option `%s' in section `%s'!\n"),
1214 * Log error message about invalid configuration option value.
1216 * @param kind log level
1217 * @param section section with invalid option
1218 * @param option name of invalid option
1219 * @param required what is required that is invalid about the option
1222 GNUNET_log_config_invalid (enum GNUNET_ErrorType kind,
1223 const char *section,
1225 const char *required)
1228 _("Configuration specifies invalid value for option `%s' in section `%s': %s\n"),
1229 option, section, required);
1236 void __attribute__ ((constructor)) GNUNET_util_cl_init ()
1238 GNUNET_stderr = stderr;
1240 GNInitWinEnv (NULL);
1243 if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400))
1252 void __attribute__ ((destructor)) GNUNET_util_cl_fini ()
1255 DeleteCriticalSection (&output_message_cs);
1258 GNShutdownWinEnv ();
1262 /* end of common_logging.c */