From 718e3744195351130f4ce7dbe0613f4b3e23df93 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 13 Dec 2002 20:15:29 +0000 Subject: Initial revision --- lib/log.h | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 lib/log.h (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h new file mode 100644 index 00000000..69919b49 --- /dev/null +++ b/lib/log.h @@ -0,0 +1,128 @@ +/* Zebra logging funcions. + * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro + * + * This file is part of GNU Zebra. + * + * GNU Zebra is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * GNU Zebra is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Zebra; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +#ifndef _ZEBRA_LOG_H +#define _ZEBRA_LOG_H + +#include + +#define ZLOG_NOLOG 0x00 +#define ZLOG_FILE 0x01 +#define ZLOG_SYSLOG 0x02 +#define ZLOG_STDOUT 0x04 +#define ZLOG_STDERR 0x08 + +#define ZLOG_NOLOG_INDEX 0 +#define ZLOG_FILE_INDEX 1 +#define ZLOG_SYSLOG_INDEX 2 +#define ZLOG_STDOUT_INDEX 3 +#define ZLOG_STDERR_INDEX 4 +#define ZLOG_MAX_INDEX 5 + +typedef enum +{ + ZLOG_NONE, + ZLOG_DEFAULT, + ZLOG_ZEBRA, + ZLOG_RIP, + ZLOG_BGP, + ZLOG_OSPF, + ZLOG_RIPNG, + ZLOG_OSPF6, + ZLOG_MASC +} zlog_proto_t; + +struct zlog +{ + const char *ident; + zlog_proto_t protocol; + int flags; + FILE *fp; + char *filename; + int syslog; + int stat; + int connected; + int maskpri; /* as per syslog setlogmask */ + int priority; /* as per syslog priority */ + int facility; /* as per syslog facility */ + int record_priority; +}; + +/* Message structure. */ +struct message +{ + int key; + char *str; +}; + +/* Default logging strucutre. */ +extern struct zlog *zlog_default; + +/* Open zlog function */ +struct zlog *openzlog (const char *, int, zlog_proto_t, int, int); + +/* Close zlog function. */ +void closezlog (struct zlog *zl); + +/* GCC have printf type attribute check. */ +#ifdef __GNUC__ +#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) +#else +#define PRINTF_ATTRIBUTE(a,b) +#endif /* __GNUC__ */ + +/* Generic function for zlog. */ +void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); + +/* Handy zlog functions. */ +void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); + +/* For bgpd's peer oriented log. */ +void plog_err (struct zlog *, const char *format, ...); +void plog_warn (struct zlog *, const char *format, ...); +void plog_info (struct zlog *, const char *format, ...); +void plog_notice (struct zlog *, const char *format, ...); +void plog_debug (struct zlog *, const char *format, ...); + +/* Set zlog flags. */ +void zlog_set_flag (struct zlog *zl, int flags); +void zlog_reset_flag (struct zlog *zl, int flags); + +/* Set zlog filename. */ +int zlog_set_file (struct zlog *zl, int flags, char *filename); +int zlog_reset_file (struct zlog *zl); + +/* Rotate log. */ +int zlog_rotate (); + +/* For hackey massage lookup and check */ +#define LOOKUP(x, y) mes_lookup(x, x ## _max, y) + +char *lookup (struct message *, int); +char *mes_lookup (struct message *meslist, int max, int index); + +extern const char *zlog_priority[]; + +#endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From 9e867fe663c4eb43c36f35067c0dd092e8c83c14 Mon Sep 17 00:00:00 2001 From: jardin Date: Tue, 23 Dec 2003 08:56:18 +0000 Subject: Merge isisd into the Quagga's framework: - add privs support - use misc quagga's definitions - make it compile"able" - fix segfault cases related to hostname() - add debug isis xxx command This patch has been approved by Paul Jakma. --- lib/log.h | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 69919b49..8948ea00 100644 --- a/lib/log.h +++ b/lib/log.h @@ -47,6 +47,7 @@ typedef enum ZLOG_OSPF, ZLOG_RIPNG, ZLOG_OSPF6, + ZLOG_ISIS, ZLOG_MASC } zlog_proto_t; -- cgit v1.2.3 From b04c699ecfb4704a67f4583e4ea929a6a3e49856 Mon Sep 17 00:00:00 2001 From: hasso Date: Mon, 4 Oct 2004 19:10:31 +0000 Subject: First small part of lib cleanup. Mainly "constification" of arguments and adding FIXME's. --- 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 8948ea00..defe0641 100644 --- a/lib/log.h +++ b/lib/log.h @@ -71,7 +71,7 @@ struct zlog struct message { int key; - char *str; + const char *str; }; /* Default logging strucutre. */ -- cgit v1.2.3 From 8c328f1106cf0498333c2d8a96940e7b4581e316 Mon Sep 17 00:00:00 2001 From: hasso Date: Tue, 5 Oct 2004 21:01:23 +0000 Subject: Number of warnings is down to 3 again in lib directory. A lot of const's added to strings and a lot of int -> unsigned int changes. --- lib/log.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index defe0641..e2eeb826 100644 --- a/lib/log.h +++ b/lib/log.h @@ -121,8 +121,8 @@ int zlog_rotate (); /* For hackey massage lookup and check */ #define LOOKUP(x, y) mes_lookup(x, x ## _max, y) -char *lookup (struct message *, int); -char *mes_lookup (struct message *meslist, int max, int index); +const char *lookup (struct message *, int); +const char *mes_lookup (struct message *meslist, int max, int index); extern const char *zlog_priority[]; -- cgit v1.2.3 From 9035efaa924c69f4f4fcb1049c7dc4f43b9da980 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 10 Oct 2004 11:56:56 +0000 Subject: 2004-10-10 Paul Jakma * version.h.in: (pid_output*) add const qualifier. * command.h: Change DEFUN func to take const char *[] rather than char **, to begin process of fixing compile warnings in lib/. Nearly all other changes in this commit follow from this change. * buffer.{c,h}: (buffer_write) pointer-arithmetic is gccism, take const void * and cast an automatic const char *p to it. (buffer_putstr) add const * command.c: (zencrypt) const qualifier (cmd_execute_command_real) ditto (cmd_execute_command_strict) ditto (config_log_file) ditto. Fix leak of getcwd() returned string. * memory.{c,h}: Add MTYPE_DISTRIBUTE_IFNAME for struct dist ifname. * distribute.{c,h}: Update with const qualifier. (distribute_free) use MTYPE_DISTRIBUTE_IFNAME (distribute_lookup) Cast to char *, note that it's ok. (distribute_hash_alloc) use MTYPE_DISTRIBUTE_IFNAME. (distribute_get) Cast to char *, note that it's ok. * filter.c: Update with const qualifier. * if.{c,h}: ditto. * if_rmap.{c,h}: ditto. (if_rmap_lookup) Cast to char *, note that it's ok. (if_rmap_get) ditto. * log.{c,h}: Update with const qualifier. * plist.{c,h}: ditto. * routemap.{c,h}: ditto. * smux.{c,h}: ditto. Fix some signed/unsigned comparisons. * sockopt.c: (getsockopt_cmsg_data) add return for error case. * vty.c: Update with const qualifier. --- 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 e2eeb826..9f6ec3be 100644 --- a/lib/log.h +++ b/lib/log.h @@ -112,7 +112,7 @@ void zlog_set_flag (struct zlog *zl, int flags); void zlog_reset_flag (struct zlog *zl, int flags); /* Set zlog filename. */ -int zlog_set_file (struct zlog *zl, int flags, char *filename); +int zlog_set_file (struct zlog *zl, int flags, const char *filename); int zlog_reset_file (struct zlog *zl); /* Rotate log. */ -- cgit v1.2.3 From ca35976927190883368ef3bd32bbf9f174575bd6 Mon Sep 17 00:00:00 2001 From: ajs Date: Fri, 19 Nov 2004 23:40:16 +0000 Subject: 2004-11-19 David Young * log.c: (safe_strerror) New function: safe wrapper for strerror. --- lib/log.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 9f6ec3be..b5dbdfe1 100644 --- a/lib/log.h +++ b/lib/log.h @@ -126,4 +126,7 @@ const char *mes_lookup (struct message *meslist, int max, int index); extern const char *zlog_priority[]; +/* Safe version of strerror -- never returns NULL. */ +extern const char *safe_strerror(int errnum); + #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From d246bd965898f0ba6781f2b2048af9a5eba079d3 Mon Sep 17 00:00:00 2001 From: ajs Date: Tue, 23 Nov 2004 17:35:08 +0000 Subject: 2004-11-23 Andrew J. Schorr * log.c: (vzlog) Take a single va_list argument and use va_copy as necessary for multiple traversals. (zlog) Pass only one va_list to vzlog. (zlog_*,plog_*) Use a macro for boilerplate code; pass only one va_list to vzlog. (zlog_set_file) Remove unused 2nd argument (flags). (zlog_save_cwd,zlog_get_cwd,zlog_free_cwd) Remove unused functions. * log.h: Remove ZLOG_*_INDEX defines (no longer used). Remove unused 2nd argument from zlog_set_file prototype. Fix prototype for zlog_rotate. * command.c: (config_log_file) Remove unused 2nd arg to zlog_set_file. * vty.c: (vty_out) Fix stdarg usage to perform multiple traversals properly. (vty_log) Must use va_copy for multiple traversals of va_list arg. --- lib/log.h | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index b5dbdfe1..e0437603 100644 --- a/lib/log.h +++ b/lib/log.h @@ -30,13 +30,6 @@ #define ZLOG_STDOUT 0x04 #define ZLOG_STDERR 0x08 -#define ZLOG_NOLOG_INDEX 0 -#define ZLOG_FILE_INDEX 1 -#define ZLOG_SYSLOG_INDEX 2 -#define ZLOG_STDOUT_INDEX 3 -#define ZLOG_STDERR_INDEX 4 -#define ZLOG_MAX_INDEX 5 - typedef enum { ZLOG_NONE, @@ -112,11 +105,11 @@ void zlog_set_flag (struct zlog *zl, int flags); void zlog_reset_flag (struct zlog *zl, int flags); /* Set zlog filename. */ -int zlog_set_file (struct zlog *zl, int flags, const char *filename); +int zlog_set_file (struct zlog *zl, const char *filename); int zlog_reset_file (struct zlog *zl); /* Rotate log. */ -int zlog_rotate (); +int zlog_rotate (struct zlog *); /* For hackey massage lookup and check */ #define LOOKUP(x, y) mes_lookup(x, x ## _max, y) -- cgit v1.2.3 From 59a06a915da9129a4e756c2b4d42449aa71a0ee4 Mon Sep 17 00:00:00 2001 From: ajs Date: Tue, 23 Nov 2004 18:19:14 +0000 Subject: 2004-11-23 Andrew J. Schorr * sigevent.c: (signal_init) Set up some default signal handlers so that processes will issue an error message before terminating or dumping core. (trap_default_signals) New function to set up signal handlers for various signals that may kill the process. (exit_handler) Call zlog_signal, then _exit. (core_handler) Call zlog_signal, then abort. * log.h: Declare new function zlog_signal. * log.c: (zlog_signal) New function to log information about a received signal before the process dies. Try to log a backtrace also. (quagga_signal_handler,signal_set) Should be static. --- lib/log.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index e0437603..1fd4fe0c 100644 --- a/lib/log.h +++ b/lib/log.h @@ -122,4 +122,7 @@ extern const char *zlog_priority[]; /* Safe version of strerror -- never returns NULL. */ extern const char *safe_strerror(int errnum); +/* To be called when a fatal signal is caught. */ +extern void zlog_signal(int signo, const char *action); + #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From 063ee52af64472474af2fa4b3cb2ba9ced746b9f Mon Sep 17 00:00:00 2001 From: ajs Date: Fri, 26 Nov 2004 18:11:14 +0000 Subject: 2004-11-26 Andrew J. Schorr * log.c: (zlog_backtrace) New function to log a backtrace. (zlog_backtrace_safe) Log a backtrace in an async-signal-safe way. Unfortunately, this function does not support syslog logging yet. (zlog_signal) Move backtrace code into separate function zlog_backtrace_safe. (_zlog_assert_failed) Call zlog_backtrace before aborting. * log.h: Declare new functions zlog_backtrace and zlog_backtrace_safe. * memory.c: (zerror) Call zlog_backtrace before aborting. --- lib/log.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 1fd4fe0c..0df75e73 100644 --- a/lib/log.h +++ b/lib/log.h @@ -125,4 +125,13 @@ extern const char *safe_strerror(int errnum); /* To be called when a fatal signal is caught. */ extern void zlog_signal(int signo, const char *action); +/* Log a backtrace. */ +extern void zlog_backtrace(int priority); + +/* Log a backtrace, but in an async-signal-safe way. Should not be + called unless the program is about to exit or abort, since it messes + up the state of zlog file pointers. This function needs to be enhanced + to support syslog logging. */ +extern void zlog_backtrace_safe(int priority); + #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From 48d6c69b345096425644b7796a7bc6b36bf0e974 Mon Sep 17 00:00:00 2001 From: ajs Date: Fri, 26 Nov 2004 20:52:59 +0000 Subject: 2004-11-26 Andrew J. Schorr * log.c, log.h, memory.c: Change function name from zlog_backtrace_safe to the more self-explanatory zlog_backtrace_sigsafe. --- 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 0df75e73..17b24cd7 100644 --- a/lib/log.h +++ b/lib/log.h @@ -132,6 +132,6 @@ extern void zlog_backtrace(int priority); called unless the program is about to exit or abort, since it messes up the state of zlog file pointers. This function needs to be enhanced to support syslog logging. */ -extern void zlog_backtrace_safe(int priority); +extern void zlog_backtrace_sigsafe(int priority); #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From 7d149b8e48ef72021aefddf44f400bccaf391870 Mon Sep 17 00:00:00 2001 From: ajs Date: Sun, 28 Nov 2004 23:00:01 +0000 Subject: 2004-11-28 Andrew J. Schorr * log.h: Remove several unused fields from struct zlog. Add comments for other fields, and add one new field syslog_options that is used in the new syslog_sigsafe implementation. * log.c: (syslog_sigsafe) New function to send syslog messages in an async-signal safe way that can be used inside a signal handler. (syslog_connect) New function to connect to syslog daemon inside a signal handler. This function supports only systems where /dev/log is a unix datagram socket (e.g. not Solaris). (zlog_signal) Call syslog_sigsafe if syslog logging is enabled. (zlog_backtrace_sigsafe) Call syslog_sigsafe if syslog logging is enabled. (openzlog) Save syslog_options for use in syslog_sigsafe. (num_append) Fix bug: handle 0 properly. (hex_append) New function to print a u_long in hex format. --- lib/log.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 17b24cd7..54cc2a6c 100644 --- a/lib/log.h +++ b/lib/log.h @@ -46,18 +46,16 @@ typedef enum struct zlog { - const char *ident; + const char *ident; /* daemon name (first arg to openlog) */ zlog_proto_t protocol; - int flags; + int flags; /* mask indicating which destinations to log to */ FILE *fp; char *filename; - int syslog; - int stat; - int connected; - int maskpri; /* as per syslog setlogmask */ - int priority; /* as per syslog priority */ + int maskpri; /* discard messages with priority > maskpri */ int facility; /* as per syslog facility */ - int record_priority; + int record_priority; /* should messages logged through stdio include the + priority of the message? */ + int syslog_options; /* 2nd arg to openlog */ }; /* Message structure. */ -- cgit v1.2.3 From b9c35001dfa81e6cddfac0b36549b1ed4b84b5e7 Mon Sep 17 00:00:00 2001 From: ajs Date: Sun, 28 Nov 2004 23:04:51 +0000 Subject: Fix comment for zlog_backtrace_sigsafe: it now supports syslog logging on systems where /dev/log is a unix datagram socket. --- lib/log.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 54cc2a6c..e596cdd0 100644 --- a/lib/log.h +++ b/lib/log.h @@ -128,8 +128,7 @@ extern void zlog_backtrace(int priority); /* Log a backtrace, but in an async-signal-safe way. Should not be called unless the program is about to exit or abort, since it messes - up the state of zlog file pointers. This function needs to be enhanced - to support syslog logging. */ + up the state of zlog file pointers. */ extern void zlog_backtrace_sigsafe(int priority); #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From 5e76477456ce8bc4a1eeaccb5c5e1d3d99ab1300 Mon Sep 17 00:00:00 2001 From: ajs Date: Fri, 3 Dec 2004 19:03:33 +0000 Subject: 2004-12-03 Andrew J. Schorr * HACKING: Indicate that header files should be consulted for documentation, particularly logging levels in lib/log.h. * log.h: Document appropriate use of syslog logging priorities inside quagga. --- lib/log.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index e596cdd0..26ff902b 100644 --- a/lib/log.h +++ b/lib/log.h @@ -24,6 +24,22 @@ #include +/* Here is some guidance on logging levels to use: + * + * LOG_DEBUG - For all messages that are enabled by optional debugging + * features, typically preceded by "if (IS...DEBUG...)" + * LOG_INFO - Information that may be of interest, but everything seems + * to be working properly. + * LOG_NOTICE - Only for message pertaining to daemon startup or shutdown. + * LOG_WARNING - Warning conditions: unexpected events, but the daemon believes + * it can continue to operate correctly. + * LOG_ERR - Error situations indicating malfunctions. Probably require + * attention. + * + * Note: LOG_CRIT, LOG_ALERT, and LOG_EMERG are currently not used anywhere, + * please use LOG_ERR instead. + */ + #define ZLOG_NOLOG 0x00 #define ZLOG_FILE 0x01 #define ZLOG_SYSLOG 0x02 -- cgit v1.2.3 From 274a4a4447b13f89f8237156a887d05a24a73cc6 Mon Sep 17 00:00:00 2001 From: ajs Date: Tue, 7 Dec 2004 15:39:31 +0000 Subject: 2004-12-07 Andrew J. Schorr * bgp_main.c: (main) The 2nd argument to openzlog has been removed. * isis_main.c: (main) The 2nd argument to openzlog has been removed. * ospf6_main.c: (main) The 2nd argument to openzlog has been removed. Note that stdout logging will no longer be enabled by default when not running as a daemon. * ospf_main.c: (main) The 2nd argument to openzlog has been removed. * rip_main.c: (main) The 2nd argument to openzlog has been removed. * ripng_main.c: (main) The 2nd argument to openzlog has been removed. * main.c: (main) The 2nd argument to openzlog has been removed. So stdout logging will no longer be enabled by default. * irdp_main.c: (irdp_finish) Reduce severity of shutdown message from LOG_WARNING to LOG_INFO. * vtysh.c: Make several functions static instead of global. Added several commands to support destination-specific logging levels. (vtysh_completion) This function is unused, so comment it out. * basic.texi: Document new logging features. Separate basic config commands from basic VTY commands. * log.h: Replace struct zlog flags and maskpri fields with maxlvl array to support individual logging levels for each destination. Remove the 2nd argument to openzlog since the default logging config should be standardized inside the library. Replaced the zlog_set_flag and zlog_reset_flag functions with zlog_set_level. And zlog_set_file now requires an additional log_level argument. Declare zlog_proto_names for use inside command.c in the "show logging" command. Added defines useful for command construction. * log.c: (vzlog) Decide where to send the message based on the individual logging levels configured for each destination. Remove support for ZLOG_STDERR since it was never actually used. Support record-priority for terminal monitors. (zlog_signal,zlog_backtrace_sigsafe) Support destination-specific logging levels. Remove stderr support (was never used). Added support for terminal monitor logging. (_zlog_assert_failed) Increase message severity to LOG_EMERG. (openzlog) Remove 2nd argument since default config should be standardized in library. By default, terminal monitoring is set to debug, and all other logging is disabled. (zlog_set_flag,zlog_reset_flag) Removed. (zlog_set_level) New function to replace zlog_set_flag and zlog_reset_flag. Supports destination-specific logging levels. (zlog_set_file,zlog_reset_file) Support file-specific logging level. (zlog_rotate) Log an error message if fopen fails, and support new file-specific logging level. * command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that command functions will be static instead of global. Remove declarations for config_exit and config_help. Define new macros DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can have deprecated commands in vtysh. Similarly, for completeness, define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED. Also, fix bug in ALIAS_ATTR macro (didn't matter because it was never used). * command.c: Make many functions static instead of global. (facility_name,facility_match,level_match) New functions to support enhanced destination-specific logging levels. (config_write_host) Support new destination-specific logging levels. (config_logmsg) Added new "logmsg" command to help test logging system. (show_logging) Added "show logging" command to show the current configuration of the logging system. (config_log_stdout_level) Support explicit stdout logging level. (no_config_log_stdout) Now takes optional LEVEL arg. (config_log_monitor,config_log_monitor_level,no_config_log_monitor) New commands creating new "log monitor" commands to set terminal monitoring log level. (config_log_file_level) Support explicit file logging level. (config_log_syslog_level) Support explicit syslog logging level. (config_log_facility,no_config_log_facility) Implement new "log facility" command. (cmd_init) Add hooks for new commands: "show logging", "logmsg", "log stdout ", "log monitor", "log monitor ", "no log monitor", "log file ", "no log file ", "log syslog ", "log facility", and "no log facility". * vty.h: Added a "level" argument to vty_log so it can support "log record-priority". Declare new function vty_log_fixed for use in signal handlers. * vty.c: (vty_log,vty_log_out) Added a "level" argument to support "log record-priority" for vty terminal monitors. (vty_down_level) Use config_exit_cmd.func instead of calling config_exit directly (since command functions will now be static instead of global). (vty_log_fixed) New function to send terminal monitor messages from inside a signal handler. --- lib/log.h | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 67 insertions(+), 15 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 26ff902b..1f9f23cd 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,4 +1,7 @@ -/* Zebra logging funcions. +/* + * $Id: log.h,v 1.14 2004/12/07 15:39:32 ajs Exp $ + * + * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro * * This file is part of GNU Zebra. @@ -40,12 +43,6 @@ * please use LOG_ERR instead. */ -#define ZLOG_NOLOG 0x00 -#define ZLOG_FILE 0x01 -#define ZLOG_SYSLOG 0x02 -#define ZLOG_STDOUT 0x04 -#define ZLOG_STDERR 0x08 - typedef enum { ZLOG_NONE, @@ -60,14 +57,28 @@ typedef enum ZLOG_MASC } zlog_proto_t; +/* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent + to that logging destination. */ +#define ZLOG_DISABLED (LOG_EMERG-1) + +typedef enum +{ + ZLOG_DEST_SYSLOG = 0, + ZLOG_DEST_STDOUT, + ZLOG_DEST_MONITOR, + ZLOG_DEST_FILE +} zlog_dest_t; +#define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1) + struct zlog { const char *ident; /* daemon name (first arg to openlog) */ zlog_proto_t protocol; - int flags; /* mask indicating which destinations to log to */ + int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated + logging destination */ + int default_lvl; /* maxlvl to use if none is specified */ FILE *fp; char *filename; - int maskpri; /* discard messages with priority > maskpri */ int facility; /* as per syslog facility */ int record_priority; /* should messages logged through stdio include the priority of the message? */ @@ -85,7 +96,8 @@ struct message extern struct zlog *zlog_default; /* Open zlog function */ -struct zlog *openzlog (const char *, int, zlog_proto_t, int, int); +struct zlog *openzlog (const char *progname, zlog_proto_t protocol, + int syslog_options, int syslog_facility); /* Close zlog function. */ void closezlog (struct zlog *zl); @@ -114,12 +126,15 @@ void plog_info (struct zlog *, const char *format, ...); void plog_notice (struct zlog *, const char *format, ...); void plog_debug (struct zlog *, const char *format, ...); -/* Set zlog flags. */ -void zlog_set_flag (struct zlog *zl, int flags); -void zlog_reset_flag (struct zlog *zl, int flags); +/* Set logging level for the given destination. If the log_level + argument is ZLOG_DISABLED, then the destination is disabled. + This function should not be used for file logging (use zlog_set_file + or zlog_reset_file instead). */ +void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); -/* Set zlog filename. */ -int zlog_set_file (struct zlog *zl, const char *filename); +/* Set logging to the given filename at the specified level. */ +int zlog_set_file (struct zlog *zl, const char *filename, int log_level); +/* Disable file logging. */ int zlog_reset_file (struct zlog *zl); /* Rotate log. */ @@ -132,6 +147,7 @@ const char *lookup (struct message *, int); const char *mes_lookup (struct message *meslist, int max, int index); extern const char *zlog_priority[]; +extern const char *zlog_proto_names[]; /* Safe version of strerror -- never returns NULL. */ extern const char *safe_strerror(int errnum); @@ -147,4 +163,40 @@ extern void zlog_backtrace(int priority); up the state of zlog file pointers. */ extern void zlog_backtrace_sigsafe(int priority); +/* Defines for use in command construction: */ + +#define LOG_LEVELS "(emergencies|alerts|critical|errors|warnings|notifications|informational|debugging)" + +#define LOG_LEVEL_DESC \ + "System is unusable\n" \ + "Immediate action needed\n" \ + "Critical conditions\n" \ + "Error conditions\n" \ + "Warning conditions\n" \ + "Normal but significant conditions\n" \ + "Informational messages\n" \ + "Debugging messages\n" + +#define LOG_FACILITIES "(kern|user|mail|daemon|auth|syslog|lpr|news|uucp|cron|local0|local1|local2|local3|local4|local5|local6|local7)" + +#define LOG_FACILITY_DESC \ + "Kernel\n" \ + "User process\n" \ + "Mail system\n" \ + "System daemons\n" \ + "Authorization system\n" \ + "Syslog itself\n" \ + "Line printer system\n" \ + "USENET news\n" \ + "Unix-to-Unix copy system\n" \ + "Cron/at facility\n" \ + "Local use\n" \ + "Local use\n" \ + "Local use\n" \ + "Local use\n" \ + "Local use\n" \ + "Local use\n" \ + "Local use\n" \ + "Local use\n" + #endif /* _ZEBRA_LOG_H */ -- cgit v1.2.3 From 40abf2392ba9f14935dab556f43e674cb5c47cf3 Mon Sep 17 00:00:00 2001 From: ajs Date: Wed, 12 Jan 2005 17:27:27 +0000 Subject: 2005-01-12 Andrew J. Schorr * configure.ac: Test for header file (for use in signal processing). * sigevent.c: (trap_default_signals) Use the SA_SIGINFO flag to pass additional siginfo_t and ucontext_t arguments to core_handler and exit_handler. (core_handler,exit_handler) Now invoked with 3 arguments (using SA_SIGINFO). Pass additional info to zlog_signal. (program_counter) New function to find program counter in ucontext_t, needs to be enhanced to support more platforms (currently works only on Linux/x86). * log.h: Change the zlog_signal prototype to add new arguments siginfo_t * and program_counter. * log.c: (zlog_signal) Add new arguments siginfo and program_counter. Include si_addr and program counter (if non-NULL) in message. And remove #ifdef HAVE_GLIBC_BACKTRACE around hex_append, since that is now used to render the si_addr and PC pointers. --- lib/log.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 1f9f23cd..b8288298 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,5 +1,5 @@ /* - * $Id: log.h,v 1.14 2004/12/07 15:39:32 ajs Exp $ + * $Id: log.h,v 1.15 2005/01/12 17:27:27 ajs Exp $ * * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro @@ -153,7 +153,8 @@ extern const char *zlog_proto_names[]; extern const char *safe_strerror(int errnum); /* To be called when a fatal signal is caught. */ -extern void zlog_signal(int signo, const char *action); +extern void zlog_signal(int signo, const char *action, + siginfo_t *siginfo, void *program_counter); /* Log a backtrace. */ extern void zlog_backtrace(int priority); -- cgit v1.2.3 From 239c26fdeae4dbccb43da359f9ea034041440831 Mon Sep 17 00:00:00 2001 From: ajs Date: Mon, 17 Jan 2005 15:22:28 +0000 Subject: 2005-01-17 Andrew J. Schorr * log.h: Change prototype for zlog_backtrace_sigsafe to take additional program_counter argument. * log.c: (zlog_backtrace_sigsafe) Add additional program_counter argument. If it is non-NULL, use backtrace_symbols_fd to resolve the address. (zlog_signal) Call zlog_backtrace_sigsafe with additional program_counter argument. [pullup candidate] --- lib/log.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index b8288298..43b5f1c2 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,5 +1,5 @@ /* - * $Id: log.h,v 1.15 2005/01/12 17:27:27 ajs Exp $ + * $Id: log.h,v 1.16 2005/01/17 15:22:28 ajs Exp $ * * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro @@ -161,8 +161,9 @@ extern void zlog_backtrace(int priority); /* Log a backtrace, but in an async-signal-safe way. Should not be called unless the program is about to exit or abort, since it messes - up the state of zlog file pointers. */ -extern void zlog_backtrace_sigsafe(int priority); + up the state of zlog file pointers. If program_counter is non-NULL, + that is logged in addition to the current backtrace. */ +extern void zlog_backtrace_sigsafe(int priority, void *program_counter); /* Defines for use in command construction: */ -- cgit v1.2.3 From 31364274ddd1da6b77dd99e1d5d164b5c643732b Mon Sep 17 00:00:00 2001 From: ajs Date: Tue, 18 Jan 2005 22:18:59 +0000 Subject: 2005-01-18 Andrew J. Schorr * log.h: Test for SA_SIGINFO to see whether zlog_signal takes final two args (siginfo and program_counter). * log.c: (hex_append) Include this function only if SA_SIGINFO or HAVE_GLIBC_BACKTRACE is defined. (zlog_signal) Final two args (siginfo and program_counter) now depend on whether SA_SIGINFO is defined on this platform. * sigevent.c: (program_counter) Do not include this function if SA_SIGINFO is not defined on this platform. (exit_handler,core_handler) Test for SA_SIGINFO to decide whether 2nd & 3rd arguments are present and to decide how to invoke zlog_signal. (trap_default_signals) Test for SA_SIGINFO and invoke sigaction appropriately. --- lib/log.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 43b5f1c2..46c4f11d 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,5 +1,5 @@ /* - * $Id: log.h,v 1.16 2005/01/17 15:22:28 ajs Exp $ + * $Id: log.h,v 1.17 2005/01/18 22:18:59 ajs Exp $ * * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro @@ -153,8 +153,11 @@ extern const char *zlog_proto_names[]; extern const char *safe_strerror(int errnum); /* To be called when a fatal signal is caught. */ -extern void zlog_signal(int signo, const char *action, - siginfo_t *siginfo, void *program_counter); +extern void zlog_signal(int signo, const char *action +#ifdef SA_SIGINFO + , siginfo_t *siginfo, void *program_counter +#endif + ); /* Log a backtrace. */ extern void zlog_backtrace(int priority); -- cgit v1.2.3 From 8cc4198f9fabe5f10f5a773de1503d82f33a01fb Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 6 May 2005 21:25:49 +0000 Subject: 2005-05-06 Paul Jakma * (general) extern and static'ification of functions in code and header. Cleanup any definitions with unspecified arguments. Add casts for callback assignments where the callback is defined, typically, as passing void *, but the function being assigned has some other pointer type defined as its argument, as gcc complains about casts from void * to X* via function arguments. Fix some old K&R style function argument definitions. Add noreturn gcc attribute to some functions, as appropriate. Add unused gcc attribute to some functions (eg ones meant to help while debugging) Add guard defines to headers which were missing them. * command.c: (install_node) add const qualifier, still doesnt shut up the warning though, because of the double pointer. (cmp_node) ditto * keychain.c: (key_str2time) Add GET_LONG_RANGE() macro, derived fromn vty.h ones to fix some of the (long) < 0 warnings. * thread.c: (various) use thread_empty (cpu_record_hash_key) should cast to uintptr_t, a stdint.h type * vty.h: Add VTY_GET_IPV4_ADDRESS and VTY_GET_IPV4_PREFIX so they removed from ospfd/ospf_vty.h * zebra.h: Move definition of ZEBRA_PORT to here, to remove dependence of lib on zebra/zserv.h --- lib/log.h | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 46c4f11d..0f058a8b 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,5 +1,5 @@ /* - * $Id: log.h,v 1.17 2005/01/18 22:18:59 ajs Exp $ + * $Id: log.h,v 1.18 2005/05/06 21:25:49 paul Exp $ * * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro @@ -96,11 +96,11 @@ struct message extern struct zlog *zlog_default; /* Open zlog function */ -struct zlog *openzlog (const char *progname, zlog_proto_t protocol, - int syslog_options, int syslog_facility); +extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol, + int syslog_options, int syslog_facility); /* Close zlog function. */ -void closezlog (struct zlog *zl); +extern void closezlog (struct zlog *zl); /* GCC have printf type attribute check. */ #ifdef __GNUC__ @@ -110,41 +110,41 @@ void closezlog (struct zlog *zl); #endif /* __GNUC__ */ /* Generic function for zlog. */ -void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); +extern void zlog (struct zlog *zl, int priority, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); /* Handy zlog functions. */ -void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); -void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +extern void zlog_notice (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +extern void zlog_debug (const char *format, ...) PRINTF_ATTRIBUTE(1, 2); /* For bgpd's peer oriented log. */ -void plog_err (struct zlog *, const char *format, ...); -void plog_warn (struct zlog *, const char *format, ...); -void plog_info (struct zlog *, const char *format, ...); -void plog_notice (struct zlog *, const char *format, ...); -void plog_debug (struct zlog *, const char *format, ...); +extern void plog_err (struct zlog *, const char *format, ...); +extern void plog_warn (struct zlog *, const char *format, ...); +extern void plog_info (struct zlog *, const char *format, ...); +extern void plog_notice (struct zlog *, const char *format, ...); +extern void plog_debug (struct zlog *, const char *format, ...); /* Set logging level for the given destination. If the log_level argument is ZLOG_DISABLED, then the destination is disabled. This function should not be used for file logging (use zlog_set_file or zlog_reset_file instead). */ -void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); +extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); /* Set logging to the given filename at the specified level. */ -int zlog_set_file (struct zlog *zl, const char *filename, int log_level); +extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level); /* Disable file logging. */ -int zlog_reset_file (struct zlog *zl); +extern int zlog_reset_file (struct zlog *zl); /* Rotate log. */ -int zlog_rotate (struct zlog *); +extern int zlog_rotate (struct zlog *); /* For hackey massage lookup and check */ #define LOOKUP(x, y) mes_lookup(x, x ## _max, y) -const char *lookup (struct message *, int); -const char *mes_lookup (struct message *meslist, int max, int index); +extern const char *lookup (struct message *, int); +extern const char *mes_lookup (struct message *meslist, int max, int index); extern const char *zlog_priority[]; extern const char *zlog_proto_names[]; -- cgit v1.2.3 From 870a1b5e5b7a25411fdb9c66d3a90ff463d8535e Mon Sep 17 00:00:00 2001 From: ajs 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..19451821 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: log.h,v 1.19 2007/04/28 22:14:10 ajs Exp $ * * 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 8bd8d860740dc0eefdc79d8ce26bb38cc780bc5c Mon Sep 17 00:00:00 2001 From: paul 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'lib/log.h') diff --git a/lib/log.h b/lib/log.h index 19451821..691368c0 100644 --- a/lib/log.h +++ b/lib/log.h @@ -1,5 +1,5 @@ /* - * $Id: log.h,v 1.19 2007/04/28 22:14:10 ajs Exp $ + * $Id: log.h,v 1.20 2008/02/28 23:26:02 paul Exp $ * * Zebra logging funcions. * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro @@ -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