mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 14:29:47 +00:00
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:
parent
bb85d700d5
commit
bf1013e6c4
@ -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));
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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__ \
|
||||
};
|
||||
|
||||
|
43
lib/log.c
43
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. */
|
||||
|
31
lib/log.h
31
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);
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -116,8 +116,7 @@ ospf6_exit (int status)
|
||||
if (master)
|
||||
thread_master_free (master);
|
||||
|
||||
if (zlog_default)
|
||||
closezlog (zlog_default);
|
||||
closezlog ();
|
||||
|
||||
exit (status);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user