From b85120bcb3af24cc35b97cf1fe0a96e54f3cbb6e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 8 May 2017 03:06:07 +0200 Subject: [PATCH] lib: detangle protocol name/instance from logging Signed-off-by: David Lamparter --- lib/filter.c | 3 ++- lib/libfrr.c | 10 ++++++++++ lib/libfrr.h | 3 +++ lib/log.c | 6 ------ lib/log.h | 2 -- lib/plist.c | 3 ++- lib/routemap.c | 17 ++++------------- lib/vty.c | 3 ++- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/lib/filter.c b/lib/filter.c index 93aac31b4f..01301de4b9 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -28,6 +28,7 @@ #include "buffer.h" #include "log.h" #include "routemap.h" +#include "libfrr.h" DEFINE_MTYPE_STATIC(LIB, ACCESS_LIST, "Access List") DEFINE_MTYPE_STATIC(LIB, ACCESS_LIST_STR, "Access List Str") @@ -1696,7 +1697,7 @@ filter_show (struct vty *vty, const char *name, afi_t afi) return 0; /* Print the name of the protocol */ - vty_out(vty, "%s:%s", zlog_protoname(), VTY_NEWLINE); + vty_out(vty, "%s:%s", frr_protoname, VTY_NEWLINE); for (access = master->num.head; access; access = access->next) { diff --git a/lib/libfrr.c b/lib/libfrr.c index 16681fe578..ff4160a243 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -36,6 +36,9 @@ const char frr_sysconfdir[] = SYSCONFDIR; const char frr_vtydir[] = DAEMON_VTY_DIR; const char frr_moduledir[] = MODULE_PATH; +char frr_protoname[] = "NONE"; +char frr_protonameinst[] = "NONE"; + char config_default[256]; static char pidfile_default[256]; static char vtypath_default[256]; @@ -164,6 +167,9 @@ void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv) frr_sysconfdir, di->name); snprintf(pidfile_default, sizeof(pidfile_default), "%s/%s.pid", frr_vtydir, di->name); + + strlcpy(frr_protoname, di->logname, sizeof(frr_protoname)); + strlcpy(frr_protonameinst, di->logname, sizeof(frr_protonameinst)); } void frr_opt_add(const char *optstr, const struct option *longopts, @@ -337,6 +343,10 @@ struct thread_master *frr_init(void) srandom(time(NULL)); + if (di->instance) + snprintf(frr_protonameinst, sizeof(frr_protonameinst), + "%s[%u]", di->logname, di->instance); + openzlog (di->progname, di->logname, di->instance, LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); #if defined(HAVE_CUMULUS) diff --git a/lib/libfrr.h b/lib/libfrr.h index 6bd92d8bea..832ff4486e 100644 --- a/lib/libfrr.h +++ b/lib/libfrr.h @@ -110,4 +110,7 @@ extern const char frr_sysconfdir[]; extern const char frr_vtydir[]; extern const char frr_moduledir[]; +extern char frr_protoname[]; +extern char frr_protonameinst[]; + #endif /* _ZEBRA_FRR_H */ diff --git a/lib/log.c b/lib/log.c index 111b98758d..219b384c4d 100644 --- a/lib/log.c +++ b/lib/log.c @@ -763,12 +763,6 @@ 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 f6c94ba604..a45486275c 100644 --- a/lib/log.h +++ b/lib/log.h @@ -69,8 +69,6 @@ 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))) diff --git a/lib/plist.c b/lib/plist.c index 8091429e31..d9bdeab6b6 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -29,6 +29,7 @@ #include "log.h" #include "routemap.h" #include "lib/json.h" +#include "libfrr.h" #include "plist_int.h" @@ -1174,7 +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 */ - vty_out(vty, "%s: ", zlog_protoname()); + vty_out(vty, "%s: ", frr_protoname); if (dtype == normal_display) { diff --git a/lib/routemap.c b/lib/routemap.c index 44b3c2bf9f..ed79beb1e7 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -28,8 +28,8 @@ #include "routemap.h" #include "command.h" #include "log.h" -#include "log_int.h" #include "hash.h" +#include "libfrr.h" DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map") DEFINE_MTYPE( LIB, ROUTE_MAP_NAME, "Route map name") @@ -989,14 +989,7 @@ vty_show_route_map_entry (struct vty *vty, struct route_map *map) struct route_map_index *index; struct route_map_rule *rule; - /* Print the name of the protocol */ - if (zlog_default) - { - vty_out (vty, "%s", zlog_protoname()); - if (zlog_default->instance) - vty_out (vty, " %d", zlog_default->instance); - } - vty_out (vty, ":%s", VTY_NEWLINE); + vty_out (vty, "%s:%s", frr_protonameinst, VTY_NEWLINE); for (index = map->head; index; index = index->next) { @@ -1052,10 +1045,8 @@ vty_show_route_map (struct vty *vty, const char *name) } else { - 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); + vty_out (vty, "%s: 'route-map %s' not found%s", frr_protonameinst, + name, VTY_NEWLINE); return CMD_SUCCESS; } } diff --git a/lib/vty.c b/lib/vty.c index 51e56fc1ae..e27f8d74ba 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -34,6 +34,7 @@ #include "vty.h" #include "privs.h" #include "network.h" +#include "libfrr.h" #include #include @@ -456,7 +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 */ - protocolname = zlog_protoname(); + protocolname = frr_protoname; #ifdef CONSUMED_TIME_CHECK GETRUSAGE(&after); -- 2.39.5