36#define BULK_DELAY_THRESHOLD (12 * 60 * 60 * 1000LL * 1000LL)
43#define BULK_REPEAT_THRESHOLD 1000
49#define BULK_TRACK_SIZE 256
55#define COMP_TRACK_SIZE 32
61#define DATE_STR_SIZE 64
66#define ROTATION_KEEP 3
213#if ! defined(GNUNET_CULL_LOGGING)
258 if (0 == strcasecmp (log,
"DEBUG"))
260 if (0 == strcasecmp (log,
"INFO"))
262 if (0 == strcasecmp (log,
"MESSAGE"))
264 if (0 == strcasecmp (log,
"WARNING"))
266 if (0 == strcasecmp (log,
"ERROR"))
268 if (0 == strcasecmp (log,
"NONE"))
284#if ! defined(GNUNET_CULL_LOGGING)
305 static unsigned int rotation_off;
308 if (
'\0' == *new_name)
315 (void) unlink (discard);
365 leftsquare = strrchr (fn,
'[');
366 if ((NULL != leftsquare) && (
']' == leftsquare[1]))
370 logfile_copy[leftsquare - fn] =
'\0';
371 logfile_copy[leftsquare - fn + 1] =
'\0';
377 &logfile_copy[leftsquare - fn + 2]);
380 if (0 == strcmp (fn, last_fn))
383 strcpy (last_fn, fn);
387 "Failed to create directory for `%s': %s\n",
392 altlog_fd = open (fn,
393 O_APPEND | O_WRONLY | O_CREAT,
394 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
400 dup_return = dup2 (altlog_fd, 2);
401 (void) close (altlog_fd);
402 if (-1 != dup_return)
404 altlog = fdopen (2,
"ab");
441 const char *function,
452 memset (&n, 0,
sizeof(n));
453 if (0 == strlen (lcomponent))
454 lcomponent = (
char *)
".*";
455 r = regcomp (&n.
component_regex, (
const char *) lcomponent, REG_NOSUB);
460 if (0 == strlen (file))
461 file = (
char *)
".*";
462 r = regcomp (&n.
file_regex, (
const char *) file, REG_NOSUB);
468 if ((NULL == function) || (0 == strlen (function)))
469 function = (
char *)
".*";
470 r = regcomp (&n.
function_regex, (
const char *) function, REG_NOSUB);
503 const char *function,
525 if (((! force_only) || ld->
force) &&
528 (0 == regexec (&ld->
file_regex, file, 0, NULL, 0)) &&
532 return caller_level <= ld->
level;
576 char *function = NULL;
584 int keep_looking = 1;
592 for (
p = def,
state = 0,
start = def; keep_looking;
p++)
614 if (strlen (
start) > 0)
623 if ((
t <
p) && (
'-' ==
t[0]))
628 if ((0 != errno) || (
to_line < 0) || (
t !=
p))
647 _ (
"ERROR: Unable to parse log definition: Syntax error at `%s'.\n"),
686 _ (
"ERROR: Unable to parse log definition: Syntax error at `%s'.\n"),
730 const char *loglevel,
733 const char *env_logfile;
736#if ! defined(GNUNET_CULL_LOGGING)
747 env_logfile =
getenv (
"GNUNET_FORCE_LOGFILE");
748 if ((NULL != env_logfile) && (strlen (env_logfile) > 0))
749 logfile = env_logfile;
756#if defined(GNUNET_CULL_LOGGING)
796 while ( (NULL != pos) &&
826 static int have_journald = -1;
828 const char *optional_newline =
"\n";
830 if ((strlen (
msg) > 0) &&
831 (
'\n' ==
msg[strlen (
msg) - 1]))
832 optional_newline =
"";
834 if (-1 == have_journald)
840 if (NULL !=
getenv (
"JOURNAL_STREAM"))
943 else if (last != last_bulk)
956 _ (
"Message `%.*s' repeated %u times in the last %s\n"),
1014 const char *message,
1025 size = vsnprintf (NULL,
1036 struct timeval timeofday;
1038 gettimeofday (&timeofday,
1043 timeofday.tv_sec += offset / 1000LL / 1000LL;
1044 timeofday.tv_usec += (offset % 1000000LL) * 1000000LL;
1045 if (timeofday.tv_usec > 1000000LL)
1047 timeofday.tv_usec -= 1000000LL;
1053 timeofday.tv_sec += offset / 1000LL / 1000LL;
1054 if (timeofday.tv_usec > -(offset % 1000000LL) * 1000000LL)
1056 timeofday.tv_usec += (offset % 1000000LL) * 1000000LL;
1060 timeofday.tv_usec += 1000000LL + (offset % 1000000LL) * 1000000LL;
1064 tmptr = localtime (&timeofday.tv_sec);
1067 strcpy (date,
"localtime error");
1072 if (0 == strftime (date2,
1074 "%Y-%m-%dT%H:%M:%S.%%06u%z",
1078 if (0 > snprintf (date,
1085 vsnprintf (buf,
size, message, va);
1086#if ! defined(GNUNET_CULL_LOGGING)
1092 (0 == strncmp (buf, last_bulk,
sizeof(last_bulk))))
1129 const char *message,
1155 const char *message,
1159 char comp_w_pid[128];
1165 va_start (va, message);
1186 return _ (
"WARNING");
1188 return _ (
"MESSAGE");
1195 return _ (
"INVALID");
1212 ret.encoding[8] =
'\0';
1213 return (
const char *)
ret.encoding;
1234 ret.encoding[8] =
'\0';
1235 return (
const char *)
ret.encoding;
1250 ret.encoding[6] =
'\0';
1251 return (
const char *)
ret.encoding;
1266 ret.encoding[6] =
'\0';
1267 return (
const char *)
ret.encoding;
1282 ret.encoding[6] =
'\0';
1283 return (
const char *)
ret.encoding;
1298 ret.encoding[6] =
'\0';
1299 return (
const char *)
ret.encoding;
1322 return (
const char *) buf;
1342 return (
const char *) buf;
1360 ret.encoding[
sizeof(
ret) - 1] =
'\0';
1361 return (
const char *)
ret.encoding;
1447 GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \
1448 (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t)))
1452 const struct sockaddr_in *v4;
1453 const struct sockaddr_un *un;
1454 const struct sockaddr_in6 *v6;
1458 return _ (
"unknown address");
1459 switch (addr->sa_family)
1462 if (addrlen !=
sizeof(
struct sockaddr_in))
1463 return "<invalid v4 address>";
1464 v4 = (
const struct sockaddr_in *) addr;
1465 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
1466 if (0 == ntohs (v4->sin_port))
1474 if (addrlen !=
sizeof(
struct sockaddr_in6))
1475 return "<invalid v6 address>";
1476 v6 = (
const struct sockaddr_in6 *) addr;
1478 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
1479 if (0 == ntohs (v6->sin6_port))
1487 if (addrlen <=
sizeof(sa_family_t))
1488 return "<unbound UNIX client>";
1489 un = (
const struct sockaddr_un *) addr;
1491 if (
'\0' == un->sun_path[0])
1493 memset (buf, 0,
sizeof(buf));
1497 (1 == off) ?
"@" :
"",
1498 (int) (addrlen -
sizeof(sa_family_t) - off),
1499 &un->sun_path[off]);
1503 return _ (
"invalid address");
1510 const char *section,
1515 "Configuration fails to specify option `%s' in section `%s'!\n")
1524 const char *section,
1526 const char *required)
1531 "Configuration specifies invalid value for option `%s' in section `%s': %s\n"),
1598 const char *
line = src;
1605 while ((data_len < dstlen) &&
1606 (sscanf (
data,
" %02x%n", &read_byte, &off) == 1))
1609 buf[dstlen - 1 - data_len++] = read_byte;
1611 buf[data_len++] = read_byte;
1626 for (i = 0; i < buf_len; i++)
1630 if ((0 != fold) && (i % fold == 0))
1634 printf (
"%02x", ((
unsigned char*) buf)[buf_len - 1 - i]);
1636 printf (
"%02x", ((
unsigned char*) buf)[i]);
struct GNUNET_MessageHeader * msg
static int gnunet_force_log_present
GNUNET_YES if at least one definition with forced == 1 is available.
static void log_rotate(const char *new_name)
Rotate logs, deleting the oldest log.
static GNUNET_THREAD_LOCAL struct GNUNET_TIME_Absolute last_bulk_time
Time of the last bulk error message (0 for none)
static GNUNET_THREAD_LOCAL char last_bulk_comp[32+1]
Component when the last bulk was logged.
static void parse_all_definitions()
Utility function - parses GNUNET_LOG and GNUNET_FORCE_LOG.
static int logdefs_len
The number of units used in logdefs array.
#define BULK_DELAY_THRESHOLD
After how many milliseconds do we always print that "message X was repeated N times"?...
static int logdefs_size
Allocated size of logdefs array (in units)
void GNUNET_log_nocheck(enum GNUNET_ErrorType kind, const char *message,...)
Main log function.
static struct LogDef * logdefs
Dynamic array of logging definitions.
static int parse_definitions(const char *constname, int force)
Utility function - parses a definition.
static void mylog(enum GNUNET_ErrorType kind, const char *comp, const char *message, va_list va)
Output a log message using the default mechanism.
static int gnunet_force_log_parsed
GNUNET_YES if GNUNET_FORCE_LOG environment variable is already parsed.
static GNUNET_THREAD_LOCAL enum GNUNET_ErrorType last_bulk_kind
Type of the last bulk message.
#define BULK_REPEAT_THRESHOLD
After how many repetitions do we always print that "message X was repeated N times"?...
static void output_message(enum GNUNET_ErrorType kind, const char *comp, const char *datestr, const char *msg)
Actually output the log message.
static char * log_file_name
Format string describing the name of the log file.
static GNUNET_THREAD_LOCAL unsigned int last_bulk_repeat
Number of times that bulk message has been repeated since.
static char * component_nopid
Running component (without pid).
void GNUNET_util_cl_init(void)
static FILE * GNUNET_stderr
File descriptor to use for "stderr", or NULL for none.
static int gnunet_log_parsed
GNUNET_YES if GNUNET_LOG environment variable is already parsed.
void GNUNET_log_from_nocheck(enum GNUNET_ErrorType kind, const char *comp, const char *message,...)
Log function that specifies an alternative component.
static enum GNUNET_ErrorType get_type(const char *log)
Convert a textual description of a loglevel to the respective enumeration type.
static GNUNET_THREAD_LOCAL char last_bulk[256] __nonstring
The last "bulk" error message that we have been logging.
#define COMP_TRACK_SIZE
How many characters do we use for matching of bulk components?
static GNUNET_THREAD_LOCAL int skip_log
Number of log calls to ignore.
#define DATE_STR_SIZE
How many characters can a date/time string be at most?
static char * component
Running component.
#define BULK_TRACK_SIZE
How many characters do we use for matching of bulk messages?
static struct CustomLogger * loggers
Linked list of our custom loggres.
static enum GNUNET_GenericReturnValue setup_log_file(const struct tm *tm)
Setup the log file.
#define PATH_MAX
Assumed maximum path length (for the log file name).
static enum GNUNET_ErrorType min_level
Minimum log level.
#define ROTATION_KEEP
How many log files to keep?
static void flush_bulk(const char *datestr)
Flush an existing bulk report to the output.
static GNUNET_THREAD_LOCAL struct GNUNET_AsyncScopeSave current_async_scope
Asynchronous scope of the current thread, or NULL if we have not entered an async scope yet.
static void resize_logdefs(void)
Utility function - reallocates logdefs array to be twice as large.
static int add_definition(const char *lcomponent, const char *file, const char *function, int from_line, int to_line, int level, int force)
Utility function - adds a parsed definition to logdefs array.
static int start
Set if we are to start default services (including ARM).
static int ret
Final status code.
static int end
Set if we are to shutdown all services (including ARM).
static char * line
Desired phone line (string to be converted to a hash).
static char * data
The data to insert into the dht.
static struct GNUNET_PEERSTORE_StoreHelloContext * shc
HELLO store context handle.
static struct GNUNET_SCHEDULER_Task * t
Main task.
static int state
The current state of the parser.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_Process * p
Helper process we started.
struct GNUNET_PQ_ResultSpec __attribute__
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
void GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block, struct GNUNET_CRYPTO_HashAsciiEncoded *result)
Convert hash to ASCII encoding.
#define GNUNET_log(kind,...)
const char * GNUNET_b2s(const void *buf, size_t buf_size)
Convert a buffer to an 8-character string representative of the contents.
int GNUNET_get_log_call_status(int caller_level, const char *comp, const char *file, const char *function, int line)
Decides whether a particular logging call should or should not be allowed to be made.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
void GNUNET_async_scope_enter(const struct GNUNET_AsyncScopeId *aid, struct GNUNET_AsyncScopeSave *old_scope)
Set the async scope for the current thread.
int have_scope
GNUNET_YES unless this saved scope is the unnamed root scope.
void GNUNET_async_scope_get(struct GNUNET_AsyncScopeSave *scope_ret)
Get the current async scope.
void GNUNET_async_scope_fresh(struct GNUNET_AsyncScopeId *aid_ret)
Generate a fresh async scope identifier.
void GNUNET_async_scope_restore(struct GNUNET_AsyncScopeSave *old_scope)
Clear the current thread's async scope.
GNUNET_GenericReturnValue
Named constants for return values.
struct GNUNET_AsyncScopeId scope_id
Saved scope.
GNUNET_ErrorType
Types of errors.
const char * GNUNET_e2s2(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_p2s2(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
const char * GNUNET_uuid2s(const struct GNUNET_Uuid *uuid)
Convert a UUID to a string (for printing debug messages).
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash to a string (for printing debug messages).
const char * GNUNET_error_type_to_string(enum GNUNET_ErrorType kind)
Convert error type to string.
int GNUNET_get_log_skip()
Get the number of log calls that are going to be skipped.
const char * GNUNET_e2s(const struct GNUNET_CRYPTO_EcdhePublicKey *p)
Convert a public key value to a string (for printing debug messages).
size_t GNUNET_hex2b(const char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash to a string (for printing debug messages).
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_log_skip(int n, int check_reset)
Ignore the next n calls to the log function.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash to a string (for printing debug messages).
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
void GNUNET_abort_()
Abort the process, generate a core dump if possible.
void GNUNET_logger_add(GNUNET_Logger logger, void *logger_cls)
Add a custom logger.
void(* GNUNET_Logger)(void *cls, enum GNUNET_ErrorType kind, const char *component, const char *date, const char *message)
User-defined handler for log messages.
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
void GNUNET_logger_remove(GNUNET_Logger logger, void *logger_cls)
Remove a custom logger.
@ GNUNET_ERROR_TYPE_UNSPECIFIED
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INVALID
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_realloc(ptr, size)
Wrapper around realloc.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string(const void *data, size_t size, char *out, size_t out_size)
Convert binary data to ASCII encoding using CrockfordBase32.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
char * GNUNET_STRINGS_filename_expand(const char *fil)
Complete filename (a la shell) from abbrevition.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
long long GNUNET_TIME_get_offset(void)
Get the timestamp offset for this instance.
static unsigned int size
Size of the "table".
Linked list of active loggers.
void * logger_cls
Closure for logger.
struct CustomLogger * next
This is a linked list.
GNUNET_Logger logger
Log function.
Identifier for an asynchronous execution context.
Saved async scope identifier or root scope.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
0-terminated ASCII encoding of a struct GNUNET_HashCode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
uint64_t rel_value_us
The actual value.
A UUID, a 128 bit "random" value.
Represents a single logging definition.
int to_line
Highest line at which this definition matches.
int from_line
Lowest line at which this definition matches.
int force
1 if this definition comes from GNUNET_FORCE_LOG, which means that it overrides any configuration opt...
regex_t file_regex
File name regex.
regex_t function_regex
Function name regex.
int level
Maximal log level allowed for calls that match this definition.
regex_t component_regex
Component name regex.