2 This file is part of GNUnet.
3 (C) 2006, 2008, 2009 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 2, 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
25 * @author Christian Grothoff
28 #include "gnunet_common.h"
29 #include "gnunet_crypto_lib.h"
30 #include "gnunet_strings_lib.h"
31 #include "gnunet_time_lib.h"
36 * After how many milliseconds do we always print
37 * that "message X was repeated N times"? Use 12h.
39 #define BULK_DELAY_THRESHOLD (12 * 60 * 60 * 1000)
42 * After how many repetitions do we always print
43 * that "message X was repeated N times"? (even if
44 * we have not yet reached the delay threshold)
46 #define BULK_REPEAT_THRESHOLD 1000
49 * How many characters do we use for matching of
52 #define BULK_TRACK_SIZE 256
55 * How many characters do we use for matching of
58 #define COMP_TRACK_SIZE 32
61 * How many characters can a date/time string
64 #define DATE_STR_SIZE 64
67 * How many log files to keep?
69 #define ROTATION_KEEP 3
73 * Assumed maximum path length (for the log file name).
80 * Linked list of active loggers.
85 * This is a linked list.
87 struct CustomLogger *next;
101 * The last "bulk" error message that we have been logging.
102 * Note that this message maybe truncated to the first BULK_TRACK_SIZE
103 * characters, in which case it is NOT 0-terminated!
105 static char last_bulk[BULK_TRACK_SIZE];
108 * Type of the last bulk message.
110 static enum GNUNET_ErrorType last_bulk_kind;
113 * Time of the last bulk error message (0 for none)
115 static struct GNUNET_TIME_Absolute last_bulk_time;
118 * Number of times that bulk message has been repeated since.
120 static unsigned int last_bulk_repeat;
123 * Component when the last bulk was logged. Will be 0-terminated.
125 static char last_bulk_comp[COMP_TRACK_SIZE + 1];
130 static char *component;
133 * Running component (without pid).
135 static char *component_nopid;
138 * Format string describing the name of the log file.
140 static char *log_file_name;
145 static enum GNUNET_ErrorType min_level;
148 * Linked list of our custom loggres.
150 static struct CustomLogger *loggers;
153 * Number of log calls to ignore.
158 * File descriptor to use for "stderr", or NULL for none.
160 static FILE *GNUNET_stderr;
163 * Represents a single logging definition
168 * Component name regex
170 regex_t component_regex;
178 * Function name regex
180 regex_t function_regex;
183 * Lowest line at which this definition matches.
184 * Defaults to 0. Must be <= to_line.
189 * Highest line at which this definition matches.
190 * Defaults to INT_MAX. Must be >= from_line.
195 * Maximal log level allowed for calls that match this definition.
196 * Calls with higher log level will be disabled.
202 * 1 if this definition comes from GNUNET_FORCE_LOG, which means that it
203 * overrides any configuration options. 0 otherwise.
209 * Dynamic array of logging definitions
211 static struct LogDef *logdefs;
214 * Allocated size of logdefs array (in units)
216 static int logdefs_size;
219 * The number of units used in logdefs array.
221 static int logdefs_len;
224 * GNUNET_YES if GNUNET_LOG environment variable is already parsed.
226 static int gnunet_log_parsed;
229 * GNUNET_YES if GNUNET_FORCE_LOG environment variable is already parsed.
231 static int gnunet_force_log_parsed;
234 * GNUNET_YES if at least one definition with forced == 1 is available.
236 static int gnunet_force_log_present;
240 * Contains the number of performance counts per second.
242 static LARGE_INTEGER performance_frequency;
247 * Convert a textual description of a loglevel
248 * to the respective GNUNET_GE_KIND.
250 * @param log loglevel to parse
251 * @return GNUNET_GE_INVALID if log does not parse
253 static enum GNUNET_ErrorType
254 get_type (const char *log)
257 return GNUNET_ERROR_TYPE_UNSPECIFIED;
258 if (0 == strcasecmp (log, _("DEBUG")))
259 return GNUNET_ERROR_TYPE_DEBUG;
260 if (0 == strcasecmp (log, _("INFO")))
261 return GNUNET_ERROR_TYPE_INFO;
262 if (0 == strcasecmp (log, _("WARNING")))
263 return GNUNET_ERROR_TYPE_WARNING;
264 if (0 == strcasecmp (log, _("ERROR")))
265 return GNUNET_ERROR_TYPE_ERROR;
266 if (0 == strcasecmp (log, _("NONE")))
267 return GNUNET_ERROR_TYPE_NONE;
268 return GNUNET_ERROR_TYPE_INVALID;
272 #if !defined(GNUNET_CULL_LOGGING)
274 * Utility function - reallocates logdefs array to be twice as large.
279 logdefs_size = (logdefs_size + 1) * 2;
280 logdefs = GNUNET_realloc (logdefs, logdefs_size * sizeof (struct LogDef));
285 * Abort the process, generate a core dump if possible.
298 * Rotate logs, deleting the oldest log.
300 * @param new_name new name to add to the rotation
303 log_rotate (const char *new_name)
305 static char *rotation[ROTATION_KEEP];
306 static unsigned int rotation_off;
309 if ('\0' == *new_name)
310 return; /* not a real log file name */
311 discard = rotation[rotation_off % ROTATION_KEEP];
314 /* Note: can't log errors during logging (recursion!), so this
315 operation MUST silently fail... */
316 (void) UNLINK (discard);
317 GNUNET_free (discard);
319 rotation[rotation_off % ROTATION_KEEP] = GNUNET_strdup (new_name);
325 * Setup the log file.
327 * @param tm timestamp for which we should setup logging
328 * @return GNUNET_OK on success, GNUNET_SYSERR on error
331 setup_log_file (const struct tm *tm)
333 static char last_fn[PATH_MAX + 1];
334 char fn[PATH_MAX + 1];
341 if (NULL == log_file_name)
342 return GNUNET_SYSERR;
343 if (0 == strftime (fn, sizeof (fn), log_file_name, tm))
344 return GNUNET_SYSERR;
345 leftsquare = strrchr (fn, '[');
346 if ( (NULL != leftsquare) && (']' == leftsquare[1]) )
348 char *logfile_copy = GNUNET_strdup (fn);
349 logfile_copy[leftsquare - fn] = '\0';
350 logfile_copy[leftsquare - fn + 1] = '\0';
351 snprintf (fn, PATH_MAX, "%s%d%s",
352 logfile_copy, getpid (), &logfile_copy[leftsquare - fn + 2]);
353 GNUNET_free (logfile_copy);
355 if (0 == strcmp (fn, last_fn))
356 return GNUNET_OK; /* no change */
357 log_rotate (last_fn);
358 strcpy (last_fn, fn);
359 dirwarn = (GNUNET_OK != GNUNET_DISK_directory_create_for_file (fn));
361 altlog_fd = OPEN (fn, O_APPEND |
364 _S_IREAD | _S_IWRITE);
366 altlog_fd = OPEN (fn, O_APPEND |
368 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
372 if (NULL != GNUNET_stderr)
373 fclose (GNUNET_stderr);
374 dup_return = dup2 (altlog_fd, 2);
375 (void) close (altlog_fd);
376 if (-1 != dup_return)
378 altlog = fdopen (2, "ab");
392 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", fn);
394 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
395 _("Failed to create or access directory for log file `%s'\n"),
397 return GNUNET_SYSERR;
399 GNUNET_stderr = altlog;
404 * Utility function - adds a parsed definition to logdefs array.
406 * @param component see struct LogDef, can't be NULL
407 * @param file see struct LogDef, can't be NULL
408 * @param function see struct LogDef, can't be NULL
409 * @param from_line see struct LogDef
410 * @param to_line see struct LogDef
411 * @param level see struct LogDef, must be >= 0
412 * @param force see struct LogDef
413 * @return 0 on success, regex-specific error otherwise
416 add_definition (char *component, char *file, char *function, int from_line,
417 int to_line, int level, int force)
422 if (logdefs_size == logdefs_len)
424 memset (&n, 0, sizeof (n));
425 if (0 == strlen (component))
426 component = (char *) ".*";
427 r = regcomp (&n.component_regex, (const char *) component, REG_NOSUB);
432 if (0 == strlen (file))
433 file = (char *) ".*";
434 r = regcomp (&n.file_regex, (const char *) file, REG_NOSUB);
437 regfree (&n.component_regex);
440 if ((NULL == function) || (0 == strlen (function)))
441 function = (char *) ".*";
442 r = regcomp (&n.function_regex, (const char *) function, REG_NOSUB);
445 regfree (&n.component_regex);
446 regfree (&n.file_regex);
449 n.from_line = from_line;
453 logdefs[logdefs_len++] = n;
459 * Decides whether a particular logging call should or should not be allowed
460 * to be made. Used internally by GNUNET_log*()
462 * @param caller_level loglevel the caller wants to use
463 * @param comp component name the caller uses (NULL means that global
464 * component name is used)
465 * @param file file name containing the logging call, usually __FILE__
466 * @param function function which tries to make a logging call,
467 * usually __FUNCTION__
468 * @param line line at which the call is made, usually __LINE__
469 * @return 0 to disallow the call, 1 to allow it
472 GNUNET_get_log_call_status (int caller_level, const char *comp,
473 const char *file, const char *function, int line)
480 /* Use default component */
481 comp = component_nopid;
483 /* We have no definitions to override globally configured log level,
484 * so just use it right away.
486 if ( (min_level >= 0) && (GNUNET_NO == gnunet_force_log_present) )
487 return caller_level <= min_level;
489 /* Only look for forced definitions? */
490 force_only = min_level >= 0;
491 for (i = 0; i < logdefs_len; i++)
494 if (( (!force_only) || ld->force) &&
495 (line >= ld->from_line && line <= ld->to_line) &&
496 (0 == regexec (&ld->component_regex, comp, 0, NULL, 0)) &&
497 (0 == regexec (&ld->file_regex, file, 0, NULL, 0)) &&
498 (0 == regexec (&ld->function_regex, function, 0, NULL, 0)))
501 return caller_level <= ld->level;
504 /* No matches - use global level, if defined */
506 return caller_level <= min_level;
507 /* All programs/services previously defaulted to WARNING.
508 * Now WE default to WARNING, and THEY default to NULL.
510 return caller_level <= GNUNET_ERROR_TYPE_WARNING;
515 * Utility function - parses a definition
518 * component;file;function;from_line-to_line;level[/component...]
519 * All entries are mandatory, but may be empty.
520 * Empty entries for component, file and function are treated as
521 * "matches anything".
522 * Empty line entry is treated as "from 0 to INT_MAX"
523 * Line entry with only one line is treated as "this line only"
524 * Entry for level MUST NOT be empty.
525 * Entries for component, file and function that consist of a
526 * single character "*" are treated (at the moment) the same way
527 * empty entries are treated (wildcard matching is not implemented (yet?)).
528 * file entry is matched to the end of __FILE__. That is, it might be
529 * a base name, or a base name with leading directory names (some compilers
530 * define __FILE__ to absolute file path).
532 * @param constname name of the environment variable from which to get the
533 * string to be parsed
534 * @param force 1 if definitions found in constname are to be forced
535 * @return number of added definitions
538 parse_definitions (const char *constname, int force)
544 char *function = NULL;
550 int from_line, to_line;
552 int keep_looking = 1;
554 tmp = getenv (constname);
557 def = GNUNET_strdup (tmp);
560 for (p = def, state = 0, start = def; keep_looking; p++)
564 case ';': /* found a field separator */
568 case 0: /* within a component name */
571 case 1: /* within a file name */
574 case 2: /* within a function name */
575 /* after a file name there must be a function name */
578 case 3: /* within a from-to line range */
579 if (strlen (start) > 0)
582 from_line = strtol (start, &t, 10);
583 if ( (0 != errno) || (from_line < 0) )
588 if ( (t < p) && ('-' == t[0]) )
592 to_line = strtol (start, &t, 10);
593 if ( (0 != errno) || (to_line < 0) || (t != p) )
599 else /* one number means "match this line only" */
602 else /* default to 0-max */
612 case '\0': /* found EOL */
614 /* fall through to '/' */
615 case '/': /* found a definition separator */
618 case 4: /* within a log level */
621 level = get_type ((const char *) start);
622 if ( (GNUNET_ERROR_TYPE_INVALID == level) ||
623 (GNUNET_ERROR_TYPE_UNSPECIFIED == level) ||
624 (0 != add_definition (comp, file, function, from_line, to_line,
646 * Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG.
649 parse_all_definitions ()
651 if (GNUNET_NO == gnunet_log_parsed)
652 parse_definitions ("GNUNET_LOG", 0);
653 gnunet_log_parsed = GNUNET_YES;
654 if (GNUNET_NO == gnunet_force_log_parsed)
655 gnunet_force_log_present =
656 parse_definitions ("GNUNET_FORCE_LOG", 1) > 0 ? GNUNET_YES : GNUNET_NO;
657 gnunet_force_log_parsed = GNUNET_YES;
665 * @param comp default component to use
666 * @param loglevel what types of messages should be logged
667 * @param logfile which file to write log messages to (can be NULL)
668 * @return GNUNET_OK on success
671 GNUNET_log_setup (const char *comp, const char *loglevel, const char *logfile)
673 const char *env_logfile;
677 min_level = get_type (loglevel);
678 #if !defined(GNUNET_CULL_LOGGING)
679 parse_all_definitions ();
682 QueryPerformanceFrequency (&performance_frequency);
684 GNUNET_free_non_null (component);
685 GNUNET_asprintf (&component, "%s-%d", comp, getpid ());
686 GNUNET_free_non_null (component_nopid);
687 component_nopid = GNUNET_strdup (comp);
689 env_logfile = getenv ("GNUNET_FORCE_LOGFILE");
690 if ((NULL != env_logfile) && (strlen (env_logfile) > 0))
691 logfile = env_logfile;
694 GNUNET_free_non_null (log_file_name);
695 log_file_name = GNUNET_STRINGS_filename_expand (logfile);
696 if (NULL == log_file_name)
697 return GNUNET_SYSERR;
700 return setup_log_file (tm);
705 * Add a custom logger.
707 * @param logger log function
708 * @param logger_cls closure for logger
711 GNUNET_logger_add (GNUNET_Logger logger, void *logger_cls)
713 struct CustomLogger *entry;
715 entry = GNUNET_malloc (sizeof (struct CustomLogger));
716 entry->logger = logger;
717 entry->logger_cls = logger_cls;
718 entry->next = loggers;
724 * Remove a custom logger.
726 * @param logger log function
727 * @param logger_cls closure for logger
730 GNUNET_logger_remove (GNUNET_Logger logger, void *logger_cls)
732 struct CustomLogger *pos;
733 struct CustomLogger *prev;
737 while ((pos != NULL) &&
738 ((pos->logger != logger) || (pos->logger_cls != logger_cls)))
743 GNUNET_assert (pos != NULL);
747 prev->next = pos->next;
752 CRITICAL_SECTION output_message_cs;
757 * Actually output the log message.
759 * @param kind how severe was the issue
760 * @param comp component responsible
761 * @param datestr current date/time
762 * @param msg the actual message
765 output_message (enum GNUNET_ErrorType kind, const char *comp,
766 const char *datestr, const char *msg)
768 struct CustomLogger *pos;
770 EnterCriticalSection (&output_message_cs);
772 if (NULL != GNUNET_stderr)
774 FPRINTF (GNUNET_stderr, "%s %s %s %s", datestr, comp,
775 GNUNET_error_type_to_string (kind), msg);
776 fflush (GNUNET_stderr);
781 pos->logger (pos->logger_cls, kind, comp, datestr, msg);
785 LeaveCriticalSection (&output_message_cs);
791 * Flush an existing bulk report to the output.
793 * @param datestr our current timestamp
796 flush_bulk (const char *datestr)
798 char msg[DATE_STR_SIZE + BULK_TRACK_SIZE + 256];
803 if ((last_bulk_time.abs_value == 0) || (last_bulk_repeat == 0))
806 last = memchr (last_bulk, '\0', BULK_TRACK_SIZE);
808 last = &last_bulk[BULK_TRACK_SIZE - 1];
809 else if (last != last_bulk)
816 ft = GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration
818 snprintf (msg, sizeof (msg),
819 _("Message `%.*s' repeated %u times in the last %s\n"),
820 BULK_TRACK_SIZE, last_bulk, last_bulk_repeat, ft);
824 output_message (last_bulk_kind, last_bulk_comp, datestr, msg);
825 last_bulk_time = GNUNET_TIME_absolute_get ();
826 last_bulk_repeat = 0;
831 * Ignore the next n calls to the log function.
833 * @param n number of log calls to ignore (could be negative)
834 * @param check_reset GNUNET_YES to assert that the log skip counter is currently zero
837 GNUNET_log_skip (int n, int check_reset)
843 ok = (0 == skip_log);
855 * Get the number of log calls that are going to be skipped
857 * @return number of log calls to be ignored
860 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, const char *comp, const char *message,
877 char date[DATE_STR_SIZE];
878 char date2[DATE_STR_SIZE];
884 size = VSNPRINTF (NULL, 0, message, vacp) + 1;
885 GNUNET_assert (0 != size);
887 memset (date, 0, DATE_STR_SIZE);
895 tmptr = localtime (&timetmp);
897 QueryPerformanceCounter (&pc);
900 strcpy (date, "localtime error");
904 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%020llu", tmptr);
905 snprintf (date, sizeof (date), date2,
906 (long long) (pc.QuadPart /
907 (performance_frequency.QuadPart / 1000)));
910 struct timeval timeofday;
912 gettimeofday (&timeofday, NULL);
913 tmptr = localtime (&timeofday.tv_sec);
916 strcpy (date, "localtime error");
920 strftime (date2, DATE_STR_SIZE, "%b %d %H:%M:%S-%%06u", tmptr);
921 snprintf (date, sizeof (date), date2, timeofday.tv_usec);
924 VSNPRINTF (buf, size, message, va);
926 (void) setup_log_file (tmptr);
927 if ((0 != (kind & GNUNET_ERROR_TYPE_BULK)) &&
928 (last_bulk_time.abs_value != 0) &&
929 (0 == strncmp (buf, last_bulk, sizeof (last_bulk))))
932 if ((GNUNET_TIME_absolute_get_duration (last_bulk_time).rel_value >
933 BULK_DELAY_THRESHOLD) || (last_bulk_repeat > BULK_REPEAT_THRESHOLD))
938 strncpy (last_bulk, buf, sizeof (last_bulk));
939 last_bulk_repeat = 0;
940 last_bulk_kind = kind;
941 last_bulk_time = GNUNET_TIME_absolute_get ();
942 strncpy (last_bulk_comp, comp, COMP_TRACK_SIZE);
943 output_message (kind, comp, date, buf);
951 * @param kind how serious is the error?
952 * @param message what is the message (format string)
953 * @param ... arguments for format string
956 GNUNET_log_nocheck (enum GNUNET_ErrorType kind, const char *message, ...)
960 va_start (va, message);
961 mylog (kind, component, message, va);
967 * Log function that specifies an alternative component.
968 * This function should be used by plugins.
970 * @param kind how serious is the error?
971 * @param comp component responsible for generating the message
972 * @param message what is the message (format string)
973 * @param ... arguments for format string
976 GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind, const char *comp,
977 const char *message, ...)
980 char comp_w_pid[128];
983 comp = component_nopid;
985 va_start (va, message);
986 GNUNET_snprintf (comp_w_pid, sizeof (comp_w_pid), "%s-%d", comp, getpid ());
987 mylog (kind, comp_w_pid, message, va);
993 * Convert error type to string.
995 * @param kind type to convert
996 * @return string corresponding to the type
999 GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
1001 if ((kind & GNUNET_ERROR_TYPE_ERROR) > 0)
1003 if ((kind & GNUNET_ERROR_TYPE_WARNING) > 0)
1004 return _("WARNING");
1005 if ((kind & GNUNET_ERROR_TYPE_INFO) > 0)
1007 if ((kind & GNUNET_ERROR_TYPE_DEBUG) > 0)
1009 if ((kind & ~GNUNET_ERROR_TYPE_BULK) == 0)
1011 return _("INVALID");
1016 * Convert a hash to a string (for printing debug messages).
1017 * This is one of the very few calls in the entire API that is
1020 * @param hc the hash code
1021 * @return string form; will be overwritten by next call to GNUNET_h2s.
1024 GNUNET_h2s (const struct GNUNET_HashCode * hc)
1026 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1028 GNUNET_CRYPTO_hash_to_enc (hc, &ret);
1029 ret.encoding[8] = '\0';
1030 return (const char *) ret.encoding;
1035 * Convert a hash to a string (for printing debug messages).
1036 * This is one of the very few calls in the entire API that is
1039 * @param hc the hash code
1040 * @return string form; will be overwritten by next call to GNUNET_h2s_full.
1043 GNUNET_h2s_full (const struct GNUNET_HashCode * hc)
1045 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1047 GNUNET_CRYPTO_hash_to_enc (hc, &ret);
1048 ret.encoding[sizeof (ret) - 1] = '\0';
1049 return (const char *) ret.encoding;
1054 * Convert a peer identity to a string (for printing debug messages).
1055 * This is one of the very few calls in the entire API that is
1058 * @param pid the peer identity
1059 * @return string form of the pid; will be overwritten by next
1060 * call to GNUNET_i2s.
1063 GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
1065 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1067 GNUNET_CRYPTO_hash_to_enc (&pid->hashPubKey, &ret);
1068 ret.encoding[4] = '\0';
1069 return (const char *) ret.encoding;
1074 * Convert a peer identity to a string (for printing debug messages).
1075 * This is one of the very few calls in the entire API that is
1078 * @param pid the peer identity
1079 * @return string form of the pid; will be overwritten by next
1080 * call to GNUNET_i2s.
1083 GNUNET_i2s_full (const struct GNUNET_PeerIdentity *pid)
1085 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
1087 GNUNET_CRYPTO_hash_to_enc (&pid->hashPubKey, &ret);
1088 return (const char *) ret.encoding;
1093 * Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string
1094 * (for printing debug messages). This is one of the very few calls
1095 * in the entire API that is NOT reentrant!
1097 * @param addr the address
1098 * @param addrlen the length of the address
1099 * @return nicely formatted string for the address
1100 * will be overwritten by next call to GNUNET_a2s.
1103 GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
1105 static char buf[INET6_ADDRSTRLEN + 8];
1107 const struct sockaddr_in *v4;
1108 const struct sockaddr_un *un;
1109 const struct sockaddr_in6 *v6;
1113 return _("unknown address");
1114 switch (addr->sa_family)
1117 if (addrlen != sizeof (struct sockaddr_in))
1118 return "<invalid v4 address>";
1119 v4 = (const struct sockaddr_in *) addr;
1120 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
1121 if (0 == ntohs (v4->sin_port))
1124 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v4->sin_port));
1128 if (addrlen != sizeof (struct sockaddr_in6))
1129 return "<invalid v4 address>";
1130 v6 = (const struct sockaddr_in6 *) addr;
1132 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
1133 if (0 == ntohs (v6->sin6_port))
1136 GNUNET_snprintf (b2, sizeof (b2), "%u", ntohs (v6->sin6_port));
1140 if (addrlen <= sizeof (sa_family_t))
1141 return "<unbound UNIX client>";
1142 un = (const struct sockaddr_un *) addr;
1144 if (un->sun_path[0] == '\0')
1146 snprintf (buf, sizeof (buf), "%s%.*s", (off == 1) ? "@" : "",
1147 (int) (addrlen - sizeof (sa_family_t) - 1 - off),
1148 &un->sun_path[off]);
1151 return _("invalid address");
1159 void __attribute__ ((constructor)) GNUNET_util_cl_init ()
1161 GNUNET_stderr = stderr;
1163 GNInitWinEnv (NULL);
1166 if (!InitializeCriticalSectionAndSpinCount (&output_message_cs, 0x00000400))
\r
1175 void __attribute__ ((destructor)) GNUNET_util_cl_fini ()
1178 DeleteCriticalSection (&output_message_cs);
1181 GNShutdownWinEnv ();
1185 /* end of common_logging.c */