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 <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2016-02-23 12:38:23 +01:00 committed by David Lamparter
parent bb85d700d5
commit bf1013e6c4
18 changed files with 38 additions and 88 deletions

View File

@ -240,8 +240,7 @@ bgp_exit (int status)
if (bm->master) if (bm->master)
thread_master_free (bm->master); thread_master_free (bm->master);
if (zlog_default) closezlog ();
closezlog (zlog_default);
memset (bm, 0, sizeof (*bm)); memset (bm, 0, sizeof (*bm));

View File

@ -254,7 +254,7 @@ main(int argc, char *argv[])
exit(1); 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); LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
if (lflag) if (lflag)
@ -407,7 +407,7 @@ ldpd_shutdown(void)
ldp_zebra_destroy(); ldp_zebra_destroy();
zprivs_terminate(&ldpd_privs); zprivs_terminate(&ldpd_privs);
thread_master_free(master); thread_master_free(master);
closezlog(zlog_default); closezlog();
exit(0); exit(0);
} }

View File

@ -2214,7 +2214,7 @@ DEFUN (show_logging,
vty_out (vty, "%s", VTY_NEWLINE); vty_out (vty, "%s", VTY_NEWLINE);
vty_out (vty, "Protocol name: %s%s", 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", vty_out (vty, "Record priority: %s%s",
(zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE); (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE);
vty_out (vty, "Timestamp precision: %d%s", vty_out (vty, "Timestamp precision: %d%s",

View File

@ -1699,7 +1699,7 @@ filter_show (struct vty *vty, const char *name, afi_t afi)
/* Print the name of the protocol */ /* Print the name of the protocol */
if (zlog_default) if (zlog_default)
vty_out (vty, "%s:%s", 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) for (access = master->num.head; access; access = access->next)
{ {

View File

@ -40,7 +40,7 @@ int main(int argc, char **argv)
master = thread_master_create (); 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); LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG);

View File

@ -300,7 +300,7 @@ struct thread_master *frr_init(void)
srandom(time(NULL)); 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); LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
#if defined(HAVE_CUMULUS) #if defined(HAVE_CUMULUS)
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);

View File

@ -38,7 +38,7 @@ struct frr_daemon_info {
const char *progname; const char *progname;
const char *name; const char *name;
zlog_proto_t log_id; const char *logname;
unsigned short instance; unsigned short instance;
char *vty_addr; char *vty_addr;
@ -73,7 +73,7 @@ struct frr_daemon_info {
#define FRR_DAEMON_INFO(execname, constname, ...) \ #define FRR_DAEMON_INFO(execname, constname, ...) \
static struct frr_daemon_info execname ##_di = { \ static struct frr_daemon_info execname ##_di = { \
.name = # execname, \ .name = # execname, \
.log_id = ZLOG_ ## constname, \ .logname = # constname, \
__VA_ARGS__ \ __VA_ARGS__ \
}; };

View File

@ -42,29 +42,6 @@ static int logfile_fd = -1; /* Used in signal handler. */
struct zlog *zlog_default = NULL; 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[] = const char *zlog_priority[] =
{ {
"emergencies", "emergencies",
@ -219,9 +196,9 @@ vzlog (int priority, const char *format, va_list args)
} }
if (zl->instance) 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 else
sprintf (proto_str, "%s: ", zlog_proto_names[zl->protocol]); sprintf (proto_str, "%s: ", zl->protoname);
/* File output. */ /* File output. */
if ((priority <= zl->maxlvl[ZLOG_DEST_FILE]) && zl->fp) if ((priority <= zl->maxlvl[ZLOG_DEST_FILE]) && zl->fp)
@ -453,7 +430,7 @@ zlog_signal(int signo, const char *action
time(&now); time(&now);
if (zlog_default) if (zlog_default)
{ {
s = str_append(LOC,zlog_proto_names[zlog_default->protocol]); s = str_append(LOC,zlog_default->protoname);
*s++ = ':'; *s++ = ':';
*s++ = ' '; *s++ = ' ';
msgstart = s; msgstart = s;
@ -735,8 +712,8 @@ memory_oom (size_t size, const char *name)
} }
/* Open log stream */ /* Open log stream */
struct zlog * void
openzlog (const char *progname, zlog_proto_t protocol, u_short instance, openzlog (const char *progname, const char *protoname, u_short instance,
int syslog_flags, int syslog_facility) int syslog_flags, int syslog_facility)
{ {
struct zlog *zl; 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 = XCALLOC(MTYPE_ZLOG, sizeof (struct zlog));
zl->ident = progname; zl->ident = progname;
zl->protocol = protocol; zl->protoname = protoname;
zl->instance = instance; zl->instance = instance;
zl->facility = syslog_facility; zl->facility = syslog_facility;
zl->syslog_options = syslog_flags; 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; zl->default_lvl = LOG_DEBUG;
openlog (progname, syslog_flags, zl->facility); openlog (progname, syslog_flags, zl->facility);
zlog_default = zl;
return zl;
} }
void void
closezlog (struct zlog *zl) closezlog (void)
{ {
struct zlog *zl = zlog_default;
closelog(); closelog();
if (zl->fp != NULL) if (zl->fp != NULL)
@ -773,6 +751,7 @@ closezlog (struct zlog *zl)
XFREE(MTYPE_ZLOG, zl->filename); XFREE(MTYPE_ZLOG, zl->filename);
XFREE (MTYPE_ZLOG, zl); XFREE (MTYPE_ZLOG, zl);
zlog_default = NULL;
} }
/* Called from command.c. */ /* Called from command.c. */

View File

@ -42,28 +42,6 @@
* please use LOG_ERR instead. * 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 /* If maxlvl is set to ZLOG_DISABLED, then no messages will be sent
to that logging destination. */ to that logging destination. */
#define ZLOG_DISABLED (LOG_EMERG-1) #define ZLOG_DISABLED (LOG_EMERG-1)
@ -80,7 +58,7 @@ typedef enum
struct zlog struct zlog
{ {
const char *ident; /* daemon name (first arg to openlog) */ const char *ident; /* daemon name (first arg to openlog) */
zlog_proto_t protocol; const char *protoname;
u_short instance; u_short instance;
int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated
logging destination */ logging destination */
@ -105,11 +83,11 @@ struct message
extern struct zlog *zlog_default; extern struct zlog *zlog_default;
/* Open zlog function */ /* Open zlog function */
extern struct zlog *openzlog (const char *progname, zlog_proto_t protocol, extern void openzlog (const char *progname, const char *protoname,
u_short instance, int syslog_options, int syslog_facility); u_short instance, int syslog_options, int syslog_facility);
/* Close zlog function. */ /* Close zlog function. */
extern void closezlog (struct zlog *zl); extern void closezlog (void);
/* GCC have printf type attribute check. */ /* GCC have printf type attribute check. */
#ifdef __GNUC__ #ifdef __GNUC__
@ -156,7 +134,6 @@ extern const char *mes_lookup (const struct message *meslist,
const char *no_item, const char *mesname); const char *no_item, const char *mesname);
extern const char *zlog_priority[]; extern const char *zlog_priority[];
extern const char *zlog_proto_names[];
/* Safe version of strerror -- never returns NULL. */ /* Safe version of strerror -- never returns NULL. */
extern const char *safe_strerror(int errnum); extern const char *safe_strerror(int errnum);

View File

@ -1176,7 +1176,7 @@ vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
/* Print the name of the protocol */ /* Print the name of the protocol */
if (zlog_default) if (zlog_default)
vty_out (vty, "%s: ", zlog_proto_names[zlog_default->protocol]); vty_out (vty, "%s: ", zlog_default->protoname);
if (dtype == normal_display) if (dtype == normal_display)
{ {

View File

@ -991,7 +991,7 @@ vty_show_route_map_entry (struct vty *vty, struct route_map *map)
/* Print the name of the protocol */ /* Print the name of the protocol */
if (zlog_default) if (zlog_default)
{ {
vty_out (vty, "%s", zlog_proto_names[zlog_default->protocol]); vty_out (vty, "%s", zlog_default->protoname);
if (zlog_default->instance) if (zlog_default->instance)
vty_out (vty, " %d", 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 else
{ {
if (zlog_default) 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) if (zlog_default && zlog_default->instance)
vty_out (vty, " %d", 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, ": 'route-map %s' not found%s", name, VTY_NEWLINE);

View File

@ -458,9 +458,9 @@ vty_command (struct vty *vty, char *buf)
/* Get the name of the protocol if any */ /* Get the name of the protocol if any */
if (zlog_default) if (zlog_default)
protocolname = zlog_proto_names[zlog_default->protocol]; protocolname = zlog_default->protoname;
else else
protocolname = zlog_proto_names[ZLOG_NONE]; protocolname = "NONE";
#ifdef CONSUMED_TIME_CHECK #ifdef CONSUMED_TIME_CHECK
GETRUSAGE(&after); GETRUSAGE(&after);

View File

@ -116,8 +116,7 @@ ospf6_exit (int status)
if (master) if (master)
thread_master_free (master); thread_master_free (master);
if (zlog_default) closezlog ();
closezlog (zlog_default);
exit (status); exit (status);
} }

View File

@ -52,7 +52,7 @@ static void vty_do_exit(void)
cmd_terminate (); cmd_terminate ();
vty_terminate (); vty_terminate ();
thread_master_free (master); thread_master_free (master);
closezlog (zlog_default); closezlog ();
log_memstats_stderr ("testcli"); log_memstats_stderr ("testcli");
exit (0); exit (0);
@ -70,8 +70,8 @@ main (int argc, char **argv)
/* master init. */ /* master init. */
master = thread_master_create (); master = thread_master_create ();
zlog_default = openzlog ("common-cli", ZLOG_NONE, 0, openzlog("common-cli", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID,
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON); LOG_DAEMON);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_MONITOR, LOG_DEBUG);

View File

@ -49,8 +49,7 @@ main (void)
master = thread_master_create (); master = thread_master_create ();
signal_init (master, array_size(sigs), sigs); signal_init (master, array_size(sigs), sigs);
zlog_default = openzlog("testsegv", ZLOG_NONE, 0, openzlog("testsegv", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG);
zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);

View File

@ -65,8 +65,7 @@ main (void)
master = thread_master_create (); master = thread_master_create ();
signal_init (master, array_size(sigs), sigs); signal_init (master, array_size(sigs), sigs);
zlog_default = openzlog("testsig", ZLOG_NONE, 0, openzlog("testsig", "NONE", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG); zlog_set_level (NULL, ZLOG_DEST_STDOUT, LOG_DEBUG);
zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED); zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);

View File

@ -168,8 +168,7 @@ sigint (void)
work_queue_free (zebrad.lsp_process_q); work_queue_free (zebrad.lsp_process_q);
meta_queue_free (zebrad.mq); meta_queue_free (zebrad.mq);
thread_master_free (zebrad.master); thread_master_free (zebrad.master);
if (zlog_default) closezlog ();
closezlog (zlog_default);
exit (0); exit (0);
} }

View File

@ -222,8 +222,7 @@ main (int argc, char **argv)
/* preserve my name */ /* preserve my name */
progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]); progname = ((p = strrchr (argv[0], '/')) ? ++p : argv[0]);
zlog_default = openzlog (progname, ZLOG_ZEBRA, 0, openzlog(progname, "ZEBRA", 0, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
LOG_CONS|LOG_NDELAY|LOG_PID, LOG_DAEMON);
while (1) while (1)
{ {