From 4f04a76b717fc4881a547f582a02a4d06d356c47 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 13 Nov 2016 16:02:23 +0900 Subject: *: add frr_init() infrastructure Start centralising startup & option parsing into the library. FRR_DAEMON_INFO is a bit weird, but it will become useful later (e.g. for killing the ZLOG_* enum, and having the daemon name available) Signed-off-by: David Lamparter --- lib/command.c | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/command.c') diff --git a/lib/command.c b/lib/command.c index 50976f2010..d87381f1ef 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2726,7 +2726,6 @@ cmd_init (int terminal) vrf_install_commands (); } - srandom(time(NULL)); #ifdef DEV_BUILD grammar_sandbox_init(); -- cgit v1.2.3 From bb85d700d564ef836af88c9d17190c2c39b93e21 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 23 Feb 2016 11:59:36 +0100 Subject: lib: ditch struct zlog * argument on zlog/vzlog() It's completely useless... Signed-off-by: David Lamparter --- bgpd/rfapi/rfapi_vty.c | 2 +- ldpd/log.c | 2 +- lib/command.c | 2 +- lib/log.c | 27 ++++++++++++--------------- lib/log.h | 8 +++----- zebra/zebra_rib.c | 2 +- 6 files changed, 19 insertions(+), 24 deletions(-) (limited to 'lib/command.c') diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 1f3066b5c5..8095999163 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -352,7 +352,7 @@ rfapiDebugPrintf (void *dummy, const char *format, ...) { va_list args; va_start (args, format); - vzlog (NULL, LOG_DEBUG, format, args); + vzlog (LOG_DEBUG, format, args); va_end (args); return 0; } diff --git a/ldpd/log.c b/ldpd/log.c index b30604db0d..3bad86499d 100644 --- a/ldpd/log.c +++ b/ldpd/log.c @@ -59,7 +59,7 @@ vlog(int pri, const char *fmt, va_list ap) ldpe_imsg_compose_parent(IMSG_LOG, pri, buf, strlen(buf) + 1); break; case PROC_MAIN: - vzlog(NULL, pri, fmt, ap); + vzlog(pri, fmt, ap); break; } } diff --git a/lib/command.c b/lib/command.c index d87381f1ef..10d36370d1 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2163,7 +2163,7 @@ DEFUN (config_logmsg, if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED) return CMD_ERR_NO_MATCH; - zlog(NULL, level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : "")); + zlog(level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : "")); if (message) XFREE(MTYPE_TMP, message); diff --git a/lib/log.c b/lib/log.c index 5821965478..60eeede7bf 100644 --- a/lib/log.c +++ b/lib/log.c @@ -185,16 +185,13 @@ time_print(FILE *fp, struct timestamp_control *ctl) /* va_list version of zlog. */ void -vzlog (struct zlog *zl, int priority, const char *format, va_list args) +vzlog (int priority, const char *format, va_list args) { char proto_str[32]; int original_errno = errno; struct timestamp_control tsctl; tsctl.already_rendered = 0; - - /* If zlog is not specified, use default one. */ - if (zl == NULL) - zl = zlog_default; + struct zlog *zl = zlog_default; /* When zlog_default is also NULL, use stderr for logging. */ if (zl == NULL) @@ -639,7 +636,7 @@ void zlog_backtrace(int priority) { #ifndef HAVE_GLIBC_BACKTRACE - zlog(NULL, priority, "No backtrace available on this platform."); + zlog(priority, "No backtrace available on this platform."); #else void *array[20]; int size, i; @@ -653,29 +650,29 @@ zlog_backtrace(int priority) size, (unsigned long)(array_size(array))); return; } - zlog(NULL, priority, "Backtrace for %d stack frames:", size); + zlog(priority, "Backtrace for %d stack frames:", size); if (!(strings = backtrace_symbols(array, size))) { zlog_err("Cannot get backtrace symbols (out of memory?)"); for (i = 0; i < size; i++) - zlog(NULL, priority, "[bt %d] %p",i,array[i]); + zlog(priority, "[bt %d] %p",i,array[i]); } else { for (i = 0; i < size; i++) - zlog(NULL, priority, "[bt %d] %s",i,strings[i]); + zlog(priority, "[bt %d] %s",i,strings[i]); free(strings); } #endif /* HAVE_GLIBC_BACKTRACE */ } void -zlog (struct zlog *zl, int priority, const char *format, ...) +zlog (int priority, const char *format, ...) { va_list args; va_start(args, format); - vzlog (zl, priority, format, args); + vzlog (priority, format, args); va_end (args); } @@ -685,7 +682,7 @@ FUNCNAME(const char *format, ...) \ { \ va_list args; \ va_start(args, format); \ - vzlog (NULL, PRIORITY, format, args); \ + vzlog (PRIORITY, format, args); \ va_end(args); \ } @@ -704,11 +701,11 @@ ZLOG_FUNC(zlog_debug, LOG_DEBUG) void zlog_thread_info (int log_level) { if (thread_current) - zlog(NULL, log_level, "Current thread function %s, scheduled from " + zlog(log_level, "Current thread function %s, scheduled from " "file %s, line %u", thread_current->funcname, thread_current->schedfrom, thread_current->schedfrom_line); else - zlog(NULL, log_level, "Current thread not known/applicable"); + zlog(log_level, "Current thread not known/applicable"); } void @@ -720,7 +717,7 @@ _zlog_assert_failed (const char *assertion, const char *file, ((logfile_fd = open_crashlog()) >= 0) && ((zlog_default->fp = fdopen(logfile_fd, "w")) != NULL)) zlog_default->maxlvl[ZLOG_DEST_FILE] = LOG_ERR; - zlog(NULL, LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s", + zlog(LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s", assertion,file,line,(function ? function : "?")); zlog_backtrace(LOG_CRIT); zlog_thread_info(LOG_CRIT); diff --git a/lib/log.h b/lib/log.h index 00c996c5be..d0f8c0c3ac 100644 --- a/lib/log.h +++ b/lib/log.h @@ -119,19 +119,17 @@ extern void closezlog (struct zlog *zl); #endif /* __GNUC__ */ /* Generic function for zlog. */ -extern void zlog (struct zlog *zl, int priority, const char *format, ...) - PRINTF_ATTRIBUTE(3, 4); +extern void zlog (int priority, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); /* Handy zlog functions. */ -extern void vzlog (struct zlog *zl, int priority, const char *format, va_list args); +extern void vzlog (int priority, const char *format, va_list args); 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); -extern void vzlog (struct zlog *, int , const char *, va_list ); - extern void zlog_thread_info (int log_level); /* Set logging level for the given destination. If the log_level diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 56a5f8e582..2dba64c5bd 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -111,7 +111,7 @@ _rnode_zlog(const char *_func, vrf_id_t vrf_id, struct route_node *rn, int prior snprintf(buf, sizeof(buf), "{(route_node *) NULL}"); } - zlog (NULL, priority, "%s: %d:%s: %s", _func, vrf_id, buf, msgbuf); + zlog (priority, "%s: %d:%s: %s", _func, vrf_id, buf, msgbuf); } #define rnode_debug(node, vrf_id, ...) \ -- cgit v1.2.3 From bf1013e6c4e05ba48e5b35192000123becdf426d Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 23 Feb 2016 12:38:23 +0100 Subject: lib: simplify protocol/log naming The protocols enum serves no purpose other than adding potential for bugs and making it complicated to add a new protocol... nuke. Signed-off-by: David Lamparter --- bgpd/bgp_main.c | 3 +-- ldpd/ldpd.c | 4 ++-- lib/command.c | 2 +- lib/filter.c | 2 +- lib/grammar_sandbox_main.c | 2 +- lib/libfrr.c | 2 +- lib/libfrr.h | 4 ++-- lib/log.c | 43 +++++++++++-------------------------------- lib/log.h | 31 ++++--------------------------- lib/plist.c | 2 +- lib/routemap.c | 4 ++-- lib/vty.c | 4 ++-- ospf6d/ospf6_main.c | 3 +-- tests/lib/cli/common_cli.c | 6 +++--- tests/lib/test_segv.c | 3 +-- tests/lib/test_sig.c | 5 ++--- zebra/main.c | 3 +-- zebra/test_main.c | 3 +-- 18 files changed, 38 insertions(+), 88 deletions(-) (limited to 'lib/command.c') diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index ba95a56074..b2b7eec3a3 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -240,8 +240,7 @@ bgp_exit (int status) if (bm->master) thread_master_free (bm->master); - if (zlog_default) - closezlog (zlog_default); + closezlog (); memset (bm, 0, sizeof (*bm)); diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 205449db3e..dc263875e2 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -254,7 +254,7 @@ main(int argc, char *argv[]) exit(1); } - zlog_default = openzlog(ldpd_di.progname, ZLOG_LDP, 0, + openzlog(ldpd_di.progname, "LDP", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); if (lflag) @@ -407,7 +407,7 @@ ldpd_shutdown(void) ldp_zebra_destroy(); zprivs_terminate(&ldpd_privs); thread_master_free(master); - closezlog(zlog_default); + closezlog(); exit(0); } diff --git a/lib/command.c b/lib/command.c index 10d36370d1..843529b36f 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2214,7 +2214,7 @@ DEFUN (show_logging, vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "Protocol name: %s%s", - zlog_proto_names[zl->protocol], VTY_NEWLINE); + zl->protoname, VTY_NEWLINE); vty_out (vty, "Record priority: %s%s", (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE); vty_out (vty, "Timestamp precision: %d%s", diff --git a/lib/filter.c b/lib/filter.c index 2b9ba87137..58138b2978 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -1699,7 +1699,7 @@ filter_show (struct vty *vty, const char *name, afi_t afi) /* Print the name of the protocol */ if (zlog_default) vty_out (vty, "%s:%s", - zlog_proto_names[zlog_default->protocol], VTY_NEWLINE); + zlog_default->protoname, VTY_NEWLINE); for (access = master->num.head; access; access = access->next) { diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c index 5deef406c1..fa925c4647 100644 --- a/lib/grammar_sandbox_main.c +++ b/lib/grammar_sandbox_main.c @@ -40,7 +40,7 @@ int main(int argc, char **argv) master = thread_master_create (); - zlog_default = openzlog ("grammar_sandbox", ZLOG_NONE, 0, + openzlog ("grammar_sandbox", "NONE", 0, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); diff --git a/lib/libfrr.c b/lib/libfrr.c index 570d9724d7..f9ac3158a3 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -300,7 +300,7 @@ struct thread_master *frr_init(void) srandom(time(NULL)); - zlog_default = openzlog (di->progname, di->log_id, di->instance, + openzlog (di->progname, di->logname, di->instance, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); #if defined(HAVE_CUMULUS) zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); diff --git a/lib/libfrr.h b/lib/libfrr.h index ae4a5176a3..d37f406f5b 100644 --- a/lib/libfrr.h +++ b/lib/libfrr.h @@ -38,7 +38,7 @@ struct frr_daemon_info { const char *progname; const char *name; - zlog_proto_t log_id; + const char *logname; unsigned short instance; char *vty_addr; @@ -73,7 +73,7 @@ struct frr_daemon_info { #define FRR_DAEMON_INFO(execname, constname, ...) \ static struct frr_daemon_info execname ##_di = { \ .name = # execname, \ - .log_id = ZLOG_ ## constname, \ + .logname = # constname, \ __VA_ARGS__ \ }; diff --git a/lib/log.c b/lib/log.c index 60eeede7bf..8986a8ada7 100644 --- a/lib/log.c +++ b/lib/log.c @@ -42,29 +42,6 @@ static int logfile_fd = -1; /* Used in signal handler. */ struct zlog *zlog_default = NULL; -/* - * This must be kept in the same order as the - * zlog_proto_t enum - */ -const char *zlog_proto_names[] = -{ - "NONE", - "DEFAULT", - "ZEBRA", - "RIP", - "BGP", - "OSPF", - "RIPNG", - "OSPF6", - "LDP", - "ISIS", - "PIM", - "NHRP", - "RFP", - "WATCHFRR", - NULL, -}; - const char *zlog_priority[] = { "emergencies", @@ -219,9 +196,9 @@ vzlog (int priority, const char *format, va_list args) } if (zl->instance) - sprintf (proto_str, "%s[%d]: ", zlog_proto_names[zl->protocol], zl->instance); + sprintf (proto_str, "%s[%d]: ", zl->protoname, zl->instance); else - sprintf (proto_str, "%s: ", zlog_proto_names[zl->protocol]); + sprintf (proto_str, "%s: ", zl->protoname); /* File output. */ if ((priority <= zl->maxlvl[ZLOG_DEST_FILE]) && zl->fp) @@ -453,7 +430,7 @@ zlog_signal(int signo, const char *action time(&now); if (zlog_default) { - s = str_append(LOC,zlog_proto_names[zlog_default->protocol]); + s = str_append(LOC,zlog_default->protoname); *s++ = ':'; *s++ = ' '; msgstart = s; @@ -735,8 +712,8 @@ memory_oom (size_t size, const char *name) } /* Open log stream */ -struct zlog * -openzlog (const char *progname, zlog_proto_t protocol, u_short instance, +void +openzlog (const char *progname, const char *protoname, u_short instance, int syslog_flags, int syslog_facility) { struct zlog *zl; @@ -745,7 +722,7 @@ openzlog (const char *progname, zlog_proto_t protocol, u_short instance, zl = XCALLOC(MTYPE_ZLOG, sizeof (struct zlog)); zl->ident = progname; - zl->protocol = protocol; + zl->protoname = protoname; zl->instance = instance; zl->facility = syslog_facility; zl->syslog_options = syslog_flags; @@ -757,13 +734,14 @@ openzlog (const char *progname, zlog_proto_t protocol, u_short instance, zl->default_lvl = LOG_DEBUG; openlog (progname, syslog_flags, zl->facility); - - return zl; + zlog_default = zl; } void -closezlog (struct zlog *zl) +closezlog (void) { + struct zlog *zl = zlog_default; + closelog(); if (zl->fp != NULL) @@ -773,6 +751,7 @@ closezlog (struct zlog *zl) XFREE(MTYPE_ZLOG, zl->filename); XFREE (MTYPE_ZLOG, zl); + zlog_default = NULL; } /* Called from command.c. */ diff --git a/lib/log.h b/lib/log.h index d0f8c0c3ac..3d887fdbbb 100644 --- a/lib/log.h +++ b/lib/log.h @@ -42,28 +42,6 @@ * please use LOG_ERR instead. */ -/* - * This must be kept in the same order as - * zlog_proto_names[] - */ -typedef enum -{ - ZLOG_NONE, - ZLOG_DEFAULT, - ZLOG_ZEBRA, - ZLOG_RIP, - ZLOG_BGP, - ZLOG_OSPF, - ZLOG_RIPNG, - ZLOG_OSPF6, - ZLOG_LDP, - ZLOG_ISIS, - ZLOG_PIM, - ZLOG_NHRP, - ZLOG_RFP, - ZLOG_WATCHFRR, -} 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) @@ -80,7 +58,7 @@ typedef enum struct zlog { const char *ident; /* daemon name (first arg to openlog) */ - zlog_proto_t protocol; + const char *protoname; u_short instance; int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated logging destination */ @@ -105,11 +83,11 @@ struct message extern struct zlog *zlog_default; /* Open zlog function */ -extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol, - u_short instance, int syslog_options, int syslog_facility); +extern void openzlog (const char *progname, const char *protoname, + u_short instance, int syslog_options, int syslog_facility); /* Close zlog function. */ -extern void closezlog (struct zlog *zl); +extern void closezlog (void); /* GCC have printf type attribute check. */ #ifdef __GNUC__ @@ -156,7 +134,6 @@ extern const char *mes_lookup (const struct message *meslist, const char *no_item, const char *mesname); 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); diff --git a/lib/plist.c b/lib/plist.c index 3ed5c8fc5c..37320c45d3 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -1176,7 +1176,7 @@ vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist, /* Print the name of the protocol */ if (zlog_default) - vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]); + vty_out (vty, "%s: ", zlog_default->protoname); if (dtype == normal_display) { diff --git a/lib/routemap.c b/lib/routemap.c index 78d4285243..b1a4c9fdef 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -991,7 +991,7 @@ vty_show_route_map_entry (struct vty *vty, struct route_map *map) /* Print the name of the protocol */ if (zlog_default) { - vty_out (vty, "%s", zlog_proto_names[zlog_default->protocol]); + vty_out (vty, "%s", zlog_default->protoname); if (zlog_default->instance) vty_out (vty, " %d", zlog_default->instance); } @@ -1052,7 +1052,7 @@ vty_show_route_map (struct vty *vty, const char *name) else { if (zlog_default) - vty_out (vty, "%s", zlog_proto_names[zlog_default->protocol]); + vty_out (vty, "%s", zlog_default->protoname); if (zlog_default && zlog_default->instance) vty_out (vty, " %d", zlog_default->instance); vty_out (vty, ": 'route-map %s' not found%s", name, VTY_NEWLINE); diff --git a/lib/vty.c b/lib/vty.c index 042c30757c..6501ca5cd8 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -458,9 +458,9 @@ vty_command (struct vty *vty, char *buf) /* Get the name of the protocol if any */ if (zlog_default) - protocolname = zlog_proto_names[zlog_default->protocol]; + protocolname = zlog_default->protoname; else - protocolname = zlog_proto_names[ZLOG_NONE]; + protocolname = "NONE"; #ifdef CONSUMED_TIME_CHECK GETRUSAGE(&after); diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 6c994189ee..b4d2cbe8d3 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -116,8 +116,7 @@ ospf6_exit (int status) if (master) thread_master_free (master); - if (zlog_default) - closezlog (zlog_default); + closezlog (); exit (status); } diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index 104352f516..5176df189e 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -52,7 +52,7 @@ static void vty_do_exit(void) cmd_terminate (); vty_terminate (); thread_master_free (master); - closezlog (zlog_default); + closezlog (); log_memstats_stderr ("testcli"); exit (0); @@ -70,8 +70,8 @@ main (int argc, char **argv) /* master init. */ master = thread_master_create (); - zlog_default = openzlog ("common-cli", ZLOG_NONE, 0, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); + openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, + LOG_DAEMON); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG); diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c index 1810c5f4b2..aa806c77c2 100644 --- a/tests/lib/test_segv.c +++ b/tests/lib/test_segv.c @@ -49,8 +49,7 @@ main (void) master = thread_master_create (); signal_init (master, array_size(sigs), sigs); - zlog_default = openzlog("testsegv", ZLOG_NONE, 0, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); + openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); diff --git a/tests/lib/test_sig.c b/tests/lib/test_sig.c index 4a04240303..641156808a 100644 --- a/tests/lib/test_sig.c +++ b/tests/lib/test_sig.c @@ -64,9 +64,8 @@ main (void) { master = thread_master_create (); signal_init (master, array_size(sigs), sigs); - - zlog_default = openzlog("testsig", ZLOG_NONE, 0, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); + + openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); diff --git a/zebra/main.c b/zebra/main.c index 7177fe329f..e951ca6941 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -168,8 +168,7 @@ sigint (void) work_queue_free (zebrad.lsp_process_q); meta_queue_free (zebrad.mq); thread_master_free (zebrad.master); - if (zlog_default) - closezlog (zlog_default); + closezlog (); exit (0); } diff --git a/zebra/test_main.c b/zebra/test_main.c index 43149318d1..2996b45464 100644 --- a/zebra/test_main.c +++ b/zebra/test_main.c @@ -222,8 +222,7 @@ main (int argc, char **argv) /* preserve my name */ progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); - zlog_default = openzlog (progname, ZLOG_ZEBRA, 0, - LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); + openzlog(progname, "ZEBRA", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); while (1) { -- cgit v1.2.3 From dd8376febd9523cf0e7263b9e5100f8af718d2b5 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 23 Feb 2016 12:49:45 +0100 Subject: lib: remove remaining struct zlog * args These don't serve any purpose either. Signed-off-by: David Lamparter --- bgpd/bgp_main.c | 2 +- bgpd/rfapi/rfapi_vty.c | 2 +- isisd/isis_main.c | 2 +- ldpd/ldpd.c | 2 +- lib/command.c | 22 +++++++++++----------- lib/grammar_sandbox_main.c | 6 +++--- lib/log.c | 33 +++++++++++---------------------- lib/log.h | 11 +++++------ nhrpd/nhrp_main.c | 4 ++-- ospf6d/ospf6_main.c | 2 +- ospfd/ospf_main.c | 2 +- pimd/pim_signals.c | 2 +- ripd/rip_main.c | 2 +- ripngd/ripng_main.c | 2 +- tests/lib/cli/common_cli.c | 6 +++--- tests/lib/test_segv.c | 6 +++--- tests/lib/test_sig.c | 8 ++++---- watchfrr/watchfrr.c | 6 +++--- zebra/main.c | 2 +- zebra/test_main.c | 2 +- 20 files changed, 56 insertions(+), 68 deletions(-) (limited to 'lib/command.c') diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index b2b7eec3a3..5bf200727a 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -163,7 +163,7 @@ sigint (void) void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } /* diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 8095999163..956005a1bf 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -411,7 +411,7 @@ rfapiStream2Vty ( *fp = (int (*)(void *, const char *,...)) rfapiDebugPrintf; *outstream = NULL; *vty_newline = str_vty_newline (*vty); - return (vzlog_test (NULL, LOG_DEBUG)); + return (vzlog_test (LOG_DEBUG)); } if (((uintptr_t) stream == (uintptr_t) 1) || diff --git a/isisd/isis_main.c b/isisd/isis_main.c index 8c48c7e27c..a6ad424ace 100644 --- a/isisd/isis_main.c +++ b/isisd/isis_main.c @@ -155,7 +155,7 @@ void sigusr1 (void) { zlog_debug ("SIGUSR1 received"); - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t isisd_signals[] = diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index dc263875e2..98ea5ca53e 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -141,7 +141,7 @@ sigint(void) static void sigusr1(void) { - zlog_rotate(NULL); + zlog_rotate(); } static struct quagga_signal_t ldp_signals[] = diff --git a/lib/command.c b/lib/command.c index 843529b36f..597e5a06c8 100644 --- a/lib/command.c +++ b/lib/command.c @@ -2234,14 +2234,14 @@ DEFUN (config_log_stdout, if (argc == idx_log_level) { - zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_default->default_lvl); + zlog_set_level (ZLOG_DEST_STDOUT, zlog_default->default_lvl); return CMD_SUCCESS; } int level; if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED) return CMD_ERR_NO_MATCH; - zlog_set_level (NULL, ZLOG_DEST_STDOUT, level); + zlog_set_level (ZLOG_DEST_STDOUT, level); return CMD_SUCCESS; } @@ -2253,7 +2253,7 @@ DEFUN (no_config_log_stdout, "Cancel logging to stdout\n" LOG_LEVEL_DESC) { - zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED); + zlog_set_level (ZLOG_DEST_STDOUT, ZLOG_DISABLED); return CMD_SUCCESS; } @@ -2268,14 +2268,14 @@ DEFUN (config_log_monitor, if (argc == idx_log_level) { - zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_default->default_lvl); + zlog_set_level (ZLOG_DEST_MONITOR, zlog_default->default_lvl); return CMD_SUCCESS; } int level; if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED) return CMD_ERR_NO_MATCH; - zlog_set_level (NULL, ZLOG_DEST_MONITOR, level); + zlog_set_level (ZLOG_DEST_MONITOR, level); return CMD_SUCCESS; } @@ -2287,7 +2287,7 @@ DEFUN (no_config_log_monitor, "Disable terminal line (monitor) logging\n" LOG_LEVEL_DESC) { - zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); + zlog_set_level (ZLOG_DEST_MONITOR, ZLOG_DISABLED); return CMD_SUCCESS; } @@ -2322,7 +2322,7 @@ set_log_file(struct vty *vty, const char *fname, int loglevel) else fullpath = fname; - ret = zlog_set_file (NULL, fullpath, loglevel); + ret = zlog_set_file (fullpath, loglevel); if (p) XFREE (MTYPE_TMP, p); @@ -2376,7 +2376,7 @@ DEFUN (no_config_log_file, "Logging file name\n" "Logging level\n") { - zlog_reset_file (NULL); + zlog_reset_file (); if (host.logfile) XFREE (MTYPE_HOST, host.logfile); @@ -2399,12 +2399,12 @@ DEFUN (config_log_syslog, int level; if ((level = level_match (argv[idx_log_levels]->arg)) == ZLOG_DISABLED) return CMD_ERR_NO_MATCH; - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, level); + zlog_set_level (ZLOG_DEST_SYSLOG, level); return CMD_SUCCESS; } else { - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); + zlog_set_level (ZLOG_DEST_SYSLOG, zlog_default->default_lvl); return CMD_SUCCESS; } } @@ -2418,7 +2418,7 @@ DEFUN (no_config_log_syslog, LOG_FACILITY_DESC LOG_LEVEL_DESC) { - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); + zlog_set_level (ZLOG_DEST_SYSLOG, ZLOG_DISABLED); return CMD_SUCCESS; } diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c index fa925c4647..681d4da440 100644 --- a/lib/grammar_sandbox_main.c +++ b/lib/grammar_sandbox_main.c @@ -42,9 +42,9 @@ int main(int argc, char **argv) openzlog ("grammar_sandbox", "NONE", 0, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); - zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); - zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); + zlog_set_level (ZLOG_DEST_SYSLOG, ZLOG_DISABLED); + zlog_set_level (ZLOG_DEST_STDOUT, LOG_DEBUG); + zlog_set_level (ZLOG_DEST_MONITOR, ZLOG_DISABLED); /* Library inits. */ cmd_init (1); diff --git a/lib/log.c b/lib/log.c index 8986a8ada7..bf4d3726d3 100644 --- a/lib/log.c +++ b/lib/log.c @@ -239,11 +239,9 @@ vzlog (int priority, const char *format, va_list args) } int -vzlog_test (struct zlog *zl, int priority) +vzlog_test (int priority) { - /* If zlog is not specified, use default one. */ - if (zl == NULL) - zl = zlog_default; + struct zlog *zl = zlog_default; /* When zlog_default is also NULL, use stderr for logging. */ if (zl == NULL) @@ -756,26 +754,20 @@ closezlog (void) /* Called from command.c. */ void -zlog_set_level (struct zlog *zl, zlog_dest_t dest, int log_level) +zlog_set_level (zlog_dest_t dest, int log_level) { - if (zl == NULL) - zl = zlog_default; - - zl->maxlvl[dest] = log_level; + zlog_default->maxlvl[dest] = log_level; } int -zlog_set_file (struct zlog *zl, const char *filename, int log_level) +zlog_set_file (const char *filename, int log_level) { + struct zlog *zl = zlog_default; FILE *fp; mode_t oldumask; /* There is opend file. */ - zlog_reset_file (zl); - - /* Set default zl. */ - if (zl == NULL) - zl = zlog_default; + zlog_reset_file (); /* Open file. */ oldumask = umask (0777 & ~LOGFILE_MASK); @@ -795,10 +787,9 @@ zlog_set_file (struct zlog *zl, const char *filename, int log_level) /* Reset opend file. */ int -zlog_reset_file (struct zlog *zl) +zlog_reset_file (void) { - if (zl == NULL) - zl = zlog_default; + struct zlog *zl = zlog_default; if (zl->fp) fclose (zl->fp); @@ -815,13 +806,11 @@ zlog_reset_file (struct zlog *zl) /* Reopen log file. */ int -zlog_rotate (struct zlog *zl) +zlog_rotate (void) { + struct zlog *zl = zlog_default; int level; - if (zl == NULL) - zl = zlog_default; - if (zl->fp) fclose (zl->fp); zl->fp = NULL; diff --git a/lib/log.h b/lib/log.h index 3d887fdbbb..889a462fe0 100644 --- a/lib/log.h +++ b/lib/log.h @@ -114,15 +114,15 @@ extern void zlog_thread_info (int 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). */ -extern void zlog_set_level (struct zlog *zl, zlog_dest_t, int log_level); +extern void zlog_set_level (zlog_dest_t, int log_level); /* Set logging to the given filename at the specified level. */ -extern int zlog_set_file (struct zlog *zl, const char *filename, int log_level); +extern int zlog_set_file (const char *filename, int log_level); /* Disable file logging. */ -extern int zlog_reset_file (struct zlog *zl); +extern int zlog_reset_file (void); /* Rotate log. */ -extern int zlog_rotate (struct zlog *); +extern int zlog_rotate (void); /* For hackey message lookup and check */ #define LOOKUP_DEF(x, y, def) mes_lookup(x, x ## _max, y, def, #x) @@ -168,8 +168,7 @@ extern void zlog_hexdump(const void *mem, unsigned int len); extern const char *zlog_sanitize(char *buf, size_t bufsz, const void *in, size_t inlen); -extern int -vzlog_test (struct zlog *zl, int priority); +extern int vzlog_test (int priority); /* structure useful for avoiding repeated rendering of the same timestamp */ struct timestamp_control { diff --git a/nhrpd/nhrp_main.c b/nhrpd/nhrp_main.c index 9633999855..2f6ee1c04f 100644 --- a/nhrpd/nhrp_main.c +++ b/nhrpd/nhrp_main.c @@ -77,7 +77,7 @@ static void parse_arguments(int argc, char **argv) static void nhrp_sigusr1(void) { - zlog_rotate(NULL); + zlog_rotate(); } static void nhrp_request_stop(void) @@ -99,7 +99,7 @@ static void nhrp_request_stop(void) debugf(NHRP_DEBUG_COMMON, "Done."); - closezlog(zlog_default); + closezlog(); exit(0); } diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index b4d2cbe8d3..54ae4645ad 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -150,7 +150,7 @@ static void sigusr1 (void) { zlog_info ("SIGUSR1 received"); - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t ospf6_signals[] = diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c index 022bb2669f..fd17458d32 100644 --- a/ospfd/ospf_main.c +++ b/ospfd/ospf_main.c @@ -127,7 +127,7 @@ sigint (void) static void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t ospf_signals[] = diff --git a/pimd/pim_signals.c b/pimd/pim_signals.c index 11360e00cb..053ef6a67b 100644 --- a/pimd/pim_signals.c +++ b/pimd/pim_signals.c @@ -55,7 +55,7 @@ static void pim_sigterm() static void pim_sigusr1() { - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t pimd_signals[] = diff --git a/ripd/rip_main.c b/ripd/rip_main.c index a9382d942f..62ea6dd078 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -108,7 +108,7 @@ sigint (void) static void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } static struct quagga_signal_t ripd_signals[] = diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c index c24ca28c36..9d97df5c41 100644 --- a/ripngd/ripng_main.c +++ b/ripngd/ripng_main.c @@ -111,7 +111,7 @@ sigint (void) static void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t ripng_signals[] = diff --git a/tests/lib/cli/common_cli.c b/tests/lib/cli/common_cli.c index 5176df189e..56db460438 100644 --- a/tests/lib/cli/common_cli.c +++ b/tests/lib/cli/common_cli.c @@ -72,9 +72,9 @@ main (int argc, char **argv) openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); - zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED); - zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG); + zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); + zlog_set_level(ZLOG_DEST_STDOUT, ZLOG_DISABLED); + zlog_set_level(ZLOG_DEST_MONITOR, LOG_DEBUG); /* Library inits. */ cmd_init (1); diff --git a/tests/lib/test_segv.c b/tests/lib/test_segv.c index aa806c77c2..dfc9d5f482 100644 --- a/tests/lib/test_segv.c +++ b/tests/lib/test_segv.c @@ -50,9 +50,9 @@ main (void) signal_init (master, array_size(sigs), sigs); openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); - zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); - zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); + zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); + zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); + zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); thread_execute (master, threadfunc, 0, 0); diff --git a/tests/lib/test_sig.c b/tests/lib/test_sig.c index 641156808a..10bce2303e 100644 --- a/tests/lib/test_sig.c +++ b/tests/lib/test_sig.c @@ -66,10 +66,10 @@ main (void) signal_init (master, array_size(sigs), sigs); openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON); - zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); - zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); - zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); - + zlog_set_level(ZLOG_DEST_SYSLOG, ZLOG_DISABLED); + zlog_set_level(ZLOG_DEST_STDOUT, LOG_DEBUG); + zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); + while (thread_fetch (master, &t)) thread_call (&t); diff --git a/watchfrr/watchfrr.c b/watchfrr/watchfrr.c index 3bf2783ee1..413a631005 100644 --- a/watchfrr/watchfrr.c +++ b/watchfrr/watchfrr.c @@ -1274,16 +1274,16 @@ int main(int argc, char **argv) master = frr_init(); - zlog_set_level(NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); + zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED); if (watchfrr_di.daemon_mode) { - zlog_set_level(NULL, ZLOG_DEST_SYSLOG, MIN(gs.loglevel, LOG_DEBUG)); + zlog_set_level(ZLOG_DEST_SYSLOG, MIN(gs.loglevel, LOG_DEBUG)); if (daemon (0, 0) < 0) { fprintf(stderr, "Watchquagga daemon failed: %s", strerror(errno)); exit (1); } } else - zlog_set_level(NULL, ZLOG_DEST_STDOUT, MIN(gs.loglevel, LOG_DEBUG)); + zlog_set_level(ZLOG_DEST_STDOUT, MIN(gs.loglevel, LOG_DEBUG)); watchfrr_vty_init(); diff --git a/zebra/main.c b/zebra/main.c index e951ca6941..bbfae3bb5b 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -177,7 +177,7 @@ sigint (void) static void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t zebra_signals[] = diff --git a/zebra/test_main.c b/zebra/test_main.c index 2996b45464..a80b4c87c4 100644 --- a/zebra/test_main.c +++ b/zebra/test_main.c @@ -181,7 +181,7 @@ sigint (void) static void sigusr1 (void) { - zlog_rotate (NULL); + zlog_rotate(); } struct quagga_signal_t zebra_signals[] = -- cgit v1.2.3 From deaa50db471e75ed20313b63c667b123e8c52724 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Tue, 23 Feb 2016 13:01:47 +0100 Subject: lib: hide away logging internals ... no need to have struct zlog generally-exposed. A few files get to include log_int.h because they use zlog/vzlog. Signed-off-by: David Lamparter --- bgpd/bgp_updgrp.h | 1 - bgpd/rfapi/rfapi_vty.c | 1 + ldpd/log.c | 1 + lib/Makefile.am | 3 ++- lib/command.c | 1 + lib/filter.c | 4 +--- lib/log.c | 7 +++++++ lib/log.h | 29 ++----------------------- lib/log_int.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/plist.c | 3 +-- lib/routemap.c | 6 +++--- lib/vty.c | 5 +---- zebra/zebra_rib.c | 1 + 13 files changed, 78 insertions(+), 41 deletions(-) create mode 100644 lib/log_int.h (limited to 'lib/command.c') diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index 6ab384369c..8f3e27bc84 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -249,7 +249,6 @@ struct update_subgroup u_int32_t merge_checks_triggered; uint64_t id; - struct zlog *log; u_int16_t sflags; diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 956005a1bf..c52026e8ef 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -29,6 +29,7 @@ #include "lib/memory.h" #include "lib/routemap.h" #include "lib/log.h" +#include "lib/log_int.h" #include "lib/linklist.h" #include "lib/command.h" diff --git a/ldpd/log.c b/ldpd/log.c index 3bad86499d..407668bb03 100644 --- a/ldpd/log.c +++ b/ldpd/log.c @@ -24,6 +24,7 @@ #include "log.h" #include +#include #include "mpls.h" static const char * const procnames[] = { diff --git a/lib/Makefile.am b/lib/Makefile.am index b9f318cedc..1a8c7af42b 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -58,7 +58,8 @@ pkginclude_HEADERS = \ # end noinst_HEADERS = \ - plist_int.h + plist_int.h \ + log_int.h noinst_PROGRAMS = grammar_sandbox diff --git a/lib/command.c b/lib/command.c index 597e5a06c8..bfff581d9b 100644 --- a/lib/command.c +++ b/lib/command.c @@ -30,6 +30,7 @@ #include "memory.h" #include "log.h" +#include "log_int.h" #include #include "thread.h" #include "vector.h" diff --git a/lib/filter.c b/lib/filter.c index 58138b2978..fd73d4de73 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -1697,9 +1697,7 @@ filter_show (struct vty *vty, const char *name, afi_t afi) return 0; /* Print the name of the protocol */ - if (zlog_default) - vty_out (vty, "%s:%s", - zlog_default->protoname, VTY_NEWLINE); + vty_out(vty, "%s:%s", zlog_protoname(), VTY_NEWLINE); for (access = master->num.head; access; access = access->next) { diff --git a/lib/log.c b/lib/log.c index bf4d3726d3..0fd9621f37 100644 --- a/lib/log.c +++ b/lib/log.c @@ -26,6 +26,7 @@ #include "zclient.h" #include "log.h" +#include "log_int.h" #include "memory.h" #include "command.h" #ifndef SUNOS_5 @@ -752,6 +753,12 @@ closezlog (void) zlog_default = NULL; } +const char * +zlog_protoname (void) +{ + return zlog_default ? zlog_default->protoname : "NONE"; +} + /* Called from command.c. */ void zlog_set_level (zlog_dest_t dest, int log_level) diff --git a/lib/log.h b/lib/log.h index 889a462fe0..8a65bbbf51 100644 --- a/lib/log.h +++ b/lib/log.h @@ -55,23 +55,6 @@ typedef enum } zlog_dest_t; #define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1) -struct zlog -{ - const char *ident; /* daemon name (first arg to openlog) */ - const char *protoname; - u_short instance; - 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 facility; /* as per syslog facility */ - 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. */ struct message { @@ -79,9 +62,6 @@ struct message const char *str; }; -/* Default logging strucutre. */ -extern struct zlog *zlog_default; - /* Open zlog function */ extern void openzlog (const char *progname, const char *protoname, u_short instance, int syslog_options, int syslog_facility); @@ -89,6 +69,8 @@ extern void openzlog (const char *progname, const char *protoname, /* Close zlog function. */ extern void closezlog (void); +extern const char *zlog_protoname (void); + /* GCC have printf type attribute check. */ #ifdef __GNUC__ #define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b))) @@ -96,12 +78,7 @@ extern void closezlog (void); #define PRINTF_ATTRIBUTE(a,b) #endif /* __GNUC__ */ -/* Generic function for zlog. */ -extern void zlog (int priority, const char *format, ...) - PRINTF_ATTRIBUTE(2, 3); - /* Handy zlog functions. */ -extern void vzlog (int priority, const char *format, va_list args); 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); @@ -133,8 +110,6 @@ extern const char *mes_lookup (const struct message *meslist, int max, int index, const char *no_item, const char *mesname); -extern const char *zlog_priority[]; - /* Safe version of strerror -- never returns NULL. */ extern const char *safe_strerror(int errnum); diff --git a/lib/log_int.h b/lib/log_int.h new file mode 100644 index 0000000000..c21d723ac6 --- /dev/null +++ b/lib/log_int.h @@ -0,0 +1,57 @@ +/* + * 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_PRIVATE_H +#define _ZEBRA_LOG_PRIVATE_H + +#include "log.h" + +struct zlog +{ + const char *ident; /* daemon name (first arg to openlog) */ + const char *protoname; + u_short instance; + 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 facility; /* as per syslog facility */ + 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 */ +}; + +/* Default logging strucutre. */ +extern struct zlog *zlog_default; + +extern const char *zlog_priority[]; + +/* Generic function for zlog. */ +extern void vzlog (int priority, const char *format, va_list args); +extern void zlog (int priority, const char *format, ...) + PRINTF_ATTRIBUTE(2, 3); + +#endif /* _ZEBRA_LOG_PRIVATE_H */ + + diff --git a/lib/plist.c b/lib/plist.c index 37320c45d3..3714969696 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -1175,8 +1175,7 @@ vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist, struct prefix_list_entry *pentry; /* Print the name of the protocol */ - if (zlog_default) - vty_out (vty, "%s: ", zlog_default->protoname); + vty_out(vty, "%s: ", zlog_protoname()); if (dtype == normal_display) { diff --git a/lib/routemap.c b/lib/routemap.c index b1a4c9fdef..1647ac3668 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -28,6 +28,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA #include "routemap.h" #include "command.h" #include "log.h" +#include "log_int.h" #include "hash.h" DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map") @@ -991,7 +992,7 @@ vty_show_route_map_entry (struct vty *vty, struct route_map *map) /* Print the name of the protocol */ if (zlog_default) { - vty_out (vty, "%s", zlog_default->protoname); + vty_out (vty, "%s", zlog_protoname()); if (zlog_default->instance) vty_out (vty, " %d", zlog_default->instance); } @@ -1051,8 +1052,7 @@ vty_show_route_map (struct vty *vty, const char *name) } else { - if (zlog_default) - vty_out (vty, "%s", zlog_default->protoname); + vty_out (vty, "%s", zlog_protoname()); if (zlog_default && zlog_default->instance) vty_out (vty, " %d", zlog_default->instance); vty_out (vty, ": 'route-map %s' not found%s", name, VTY_NEWLINE); diff --git a/lib/vty.c b/lib/vty.c index 6501ca5cd8..4d34fead8b 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -457,10 +457,7 @@ vty_command (struct vty *vty, char *buf) ret = cmd_execute_command (vline, vty, NULL, 0); /* Get the name of the protocol if any */ - if (zlog_default) - protocolname = zlog_default->protoname; - else - protocolname = "NONE"; + protocolname = zlog_protoname(); #ifdef CONSUMED_TIME_CHECK GETRUSAGE(&after); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 2dba64c5bd..f9734fdf7d 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -28,6 +28,7 @@ #include "zebra_memory.h" #include "command.h" #include "log.h" +#include "log_int.h" #include "sockunion.h" #include "linklist.h" #include "thread.h" -- cgit v1.2.3