]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: detangle protocol name/instance from logging
authorDavid Lamparter <equinox@opensourcerouting.org>
Mon, 8 May 2017 01:06:07 +0000 (03:06 +0200)
committerQuentin Young <qlyoung@users.noreply.github.com>
Thu, 18 May 2017 18:07:28 +0000 (14:07 -0400)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/filter.c
lib/libfrr.c
lib/libfrr.h
lib/log.c
lib/log.h
lib/plist.c
lib/routemap.c
lib/vty.c

index 93aac31b4f0462ada919675a8fae3c6f7de97d7d..01301de4b9fe67c151fa7a7954881e3cdbf85b86 100644 (file)
@@ -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)
     {
index 16681fe578535c2420bb7eb90ad3c3ed101ca857..ff4160a243fc5545a02533f9472eca93cfa519ee 100644 (file)
@@ -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)
index 6bd92d8beae7f29fec37371bd759aac0d1691c08..832ff4486e1b11004e1ca292dc744d901e854e6b 100644 (file)
@@ -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 */
index 111b98758d5bca1228ab56ad056e9dbe2005e1c0..219b384c4d8e1cb9736c2d94f8d107989c9f1003 100644 (file)
--- 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)
index f6c94ba6045673aa418c833978c9fb9d291cb676..a45486275c6fab413b806260d7a64c8155484249 100644 (file)
--- 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)))
index 8091429e31095a0337e4a124625a5f0a3d4d5cd7..d9bdeab6b6c95335dce6ab6c491455e1ae0832d4 100644 (file)
@@ -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)
     {
index 44b3c2bf9f511c0e39e94aac8a3e09d7fb14560d..ed79beb1e7484f165b300598e88766f3b2eda44f 100644 (file)
@@ -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;
         }
     }
index 51e56fc1ae66c3ac2e441a6d257136509d222b70..e27f8d74badb3dbabf430ef9438a45fd6b7e0375 100644 (file)
--- 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 <arpa/telnet.h>
 #include <termios.h>
@@ -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);