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) &&
825 static int have_journald = -1;
828 if (-1 == have_journald)
834 if (NULL !=
getenv (
"JOURNAL_STREAM"))
929 else if (last != last_bulk)
942 _ (
"Message `%.*s' repeated %u times in the last %s\n"),
1007 size = vsnprintf (NULL, 0, message, vacp) + 1;
1015 struct timeval timeofday;
1017 gettimeofday (&timeofday, NULL);
1021 timeofday.tv_sec += offset / 1000LL;
1022 timeofday.tv_usec += (offset % 1000LL) * 1000LL;
1023 if (timeofday.tv_usec > 1000000LL)
1025 timeofday.tv_usec -= 1000000LL;
1031 timeofday.tv_sec += offset / 1000LL;
1032 if (timeofday.tv_usec > -(offset % 1000LL) * 1000LL)
1034 timeofday.tv_usec += (offset % 1000LL) * 1000LL;
1038 timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL;
1042 tmptr = localtime (&timeofday.tv_sec);
1045 strcpy (date,
"localtime error");
1050 if (0 == strftime (date2,
DATE_STR_SIZE,
"%Y-%m-%dT%H:%M:%S.%%06u%z",
1054 if (0 > snprintf (date,
sizeof(date), date2, timeofday.tv_usec))
1058 vsnprintf (buf,
size, message, va);
1059#if ! defined(GNUNET_CULL_LOGGING)
1065 (0 == strncmp (buf, last_bulk,
sizeof(last_bulk))))
1097 va_start (va, message);
1115 const char *message,
1119 char comp_w_pid[128];
1124 va_start (va, message);
1125 GNUNET_snprintf (comp_w_pid,
sizeof(comp_w_pid),
"%s-%d", comp, getpid ());
1126 mylog (kind, comp_w_pid, message, va);
1137 return _ (
"WARNING");
1139 return _ (
"MESSAGE");
1146 return _ (
"INVALID");
1162 ret.encoding[8] =
'\0';
1163 return (
const char *)
ret.encoding;
1183 ret.encoding[8] =
'\0';
1184 return (
const char *)
ret.encoding;
1196 ret.encoding[6] =
'\0';
1197 return (
const char *)
ret.encoding;
1209 ret.encoding[6] =
'\0';
1210 return (
const char *)
ret.encoding;
1222 ret.encoding[6] =
'\0';
1223 return (
const char *)
ret.encoding;
1235 ret.encoding[6] =
'\0';
1236 return (
const char *)
ret.encoding;
1256 return (
const char *) buf;
1276 return (
const char *) buf;
1294 ret.encoding[
sizeof(
ret) - 1] =
'\0';
1295 return (
const char *)
ret.encoding;
1380 GNUNET_MAX ((INET6_ADDRSTRLEN + 8), \
1381 (1 + sizeof(struct sockaddr_un) - sizeof(sa_family_t)))
1385 const struct sockaddr_in *v4;
1386 const struct sockaddr_un *un;
1387 const struct sockaddr_in6 *v6;
1391 return _ (
"unknown address");
1392 switch (addr->sa_family)
1395 if (addrlen !=
sizeof(
struct sockaddr_in))
1396 return "<invalid v4 address>";
1397 v4 = (
const struct sockaddr_in *) addr;
1398 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
1399 if (0 == ntohs (v4->sin_port))
1407 if (addrlen !=
sizeof(
struct sockaddr_in6))
1408 return "<invalid v6 address>";
1409 v6 = (
const struct sockaddr_in6 *) addr;
1411 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
1412 if (0 == ntohs (v6->sin6_port))
1420 if (addrlen <=
sizeof(sa_family_t))
1421 return "<unbound UNIX client>";
1422 un = (
const struct sockaddr_un *) addr;
1424 if (
'\0' == un->sun_path[0])
1426 memset (buf, 0,
sizeof(buf));
1430 (1 == off) ?
"@" :
"",
1431 (
int) (addrlen -
sizeof(sa_family_t) - off),
1432 &un->sun_path[off]);
1436 return _ (
"invalid address");
1443 const char *section,
1448 "Configuration fails to specify option `%s' in section `%s'!\n")
1457 const char *section,
1459 const char *required)
1464 "Configuration specifies invalid value for option `%s' in section `%s': %s\n"),
1528 const char *
line = src;
1535 while (sscanf (
data,
" %02x%n", &read_byte, &off) == 1)
1538 buf[dstlen - 1 - data_len++] = read_byte;
1540 buf[data_len++] = read_byte;
1552 for (i = 0; i < buf_len; i++)
1556 if ((0 != fold) && (i % fold == 0))
1560 printf (
"%02x", ((
unsigned char*) buf)[buf_len - 1 - i]);
1562 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.
void GNUNET_util_cl_fini(void)
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.
void __attribute__((constructor))
Initializer.
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.
enum State state
current state of profiling
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_OS_Process * p
Helper process we started.
static struct GNUNET_SCHEDULER_Task * t
Main task.
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.