From 1ed72e0b3a643fa1be6f1efa904965798a575cd1 Mon Sep 17 00:00:00 2001 From: "Andrew J. Schorr" Date: Sat, 28 Apr 2007 22:14:10 +0000 Subject: [logging] Add new "log timestamp precision" command for subsecond timestamps 2007-04-28 Andrew J. Schorr * command.c: (config_write_host) Save "log timestamp precision" if not default value. (show_logging) Show configured timestamp precision. (config_log_timestamp_precision) Enable configuration of timestamp precision. (no_config_log_timestamp_precision) Restore default timestamp precision. (cmd_init) Install new timestamp precision commands. * log.h: (struct zlog) New timestamp_precision field. (quagga_timestamp) New function to generate a timestamp with the desired precision. (struct timestamp_control) Declare a structure for use in avoiding repeated duplicate calls to quagga_timestamp. * log.c: (quagga_timestamp) New function to generate a timestamp of the desired precision. (time_print) Call quagga_timestamp if the time hasn't already been calculated. (vzlog) Initialize a timestamp_control structure and pass it to time_print and vty_log. (zlog_backtrace) Fix 64-bit problem: cannot print size_t with %u. * vty.h: Must now include "log.h". (vty_log) Takes an additional struct timestamp_control argument. * vty.c: (vty_log_out) Use new struct timestamp_control and new quagga_timestamp function to print timestamps of the desired precision. (vty_time_print) Use new quagga_timestamp function. (vty_log) Accept new struct timestamp_control argument and pass it down to vty_log_out. --- lib/log.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 0f058a8b..da8fbea8 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,5 +1,5 @@ /* - * $Id: log.h,v 1.18 2005/05/06 21:25:49 paul Exp $ + * $Id$ * * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro @@ -83,6 +83,7 @@ struct zlog int record_priority; /* should messages logged through stdio include the priority of the message? */ int syslog_options; /* 2nd arg to openlog */ + int timestamp_precision; /* # of digits of subsecond precision */ }; /* Message structure. */ @@ -168,6 +169,23 @@ extern void zlog_backtrace(int priority); that is logged in addition to the current backtrace. */ extern void zlog_backtrace_sigsafe(int priority, void *program_counter); +/* Puts a current timestamp in buf and returns the number of characters + written (not including the terminating NUL). The purpose of + this function is to avoid calls to localtime appearing all over the code. + It caches the most recent localtime result and can therefore + avoid multiple calls within the same second. If buflen is too small, + *buf will be set to '\0', and 0 will be returned. */ +extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */, + char *buf, size_t buflen); + +/* structure useful for avoiding repeated rendering of the same timestamp */ +struct timestamp_control { + size_t len; /* length of rendered timestamp */ + int precision; /* configuration parameter */ + int already_rendered; /* should be initialized to 0 */ + char buf[40]; /* will contain the rendered timestamp */ +}; + /* Defines for use in command construction: */ #define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)" -- cgit v1.2.3 From 11486b5265b2e0e2cf8b140018c47bd9a35cba93 Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Thu, 28 Feb 2008 23:26:02 +0000 Subject: [lib] Fix the struct message LOOKUP function to be more robust 2008-02-28 Paul Jakma * log.c: (mes_lookup) Sowmini Varadhan diagnosed a problem where this function can cause a NULL dereference, on lookups for unknown indices, or messages with NULL strings. Can occur, e.g., debug logging code when processing received messages. Fixed to accept a pointer to a default string to be used if there is no match. * log.h: LOOKUP adjusted to match --- lib/log.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index da8fbea8..7432b25e 100644 --- a/lib/log.h +++ b/lib/log.h @@ -142,10 +142,12 @@ extern int zlog_reset_file (struct zlog *zl); extern int zlog_rotate (struct zlog *); /* For hackey massage lookup and check */ -#define LOOKUP(x, y) mes_lookup(x, x ## _max, y) +#define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)") extern const char *lookup (struct message *, int); -extern const char *mes_lookup (struct message *meslist, int max, int index); +extern const char *mes_lookup (struct message *meslist, + int max, int index, + const char *no_item); extern const char *zlog_priority[]; extern const char *zlog_proto_names[]; -- cgit v1.2.3 From 1423c809cc4ddc2e013ba6264c49a11e5719c6f2 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Thu, 14 Aug 2008 17:59:25 +0100 Subject: [lib] mes_lookup string lookup table argument should be marked const 2008-08-14 Stephen Hemminger * lib/log.{c,h}: struct message argument should point to const * */*.c: adjust to suit, Signed-off-by: Paul Jakma --- lib/log.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 7432b25e..777fd77d 100644 --- a/lib/log.h +++ b/lib/log.h @@ -144,7 +144,7 @@ extern int zlog_rotate (struct zlog *); /* For hackey massage lookup and check */ #define LOOKUP(x, y) mes_lookup(x, x ## _max, y, "(no item found)") -extern const char *lookup (struct message *, int); +extern const char *lookup (const struct message *, int); extern const char *mes_lookup (struct message *meslist, int max, int index, const char *no_item); -- cgit v1.2.3