From 276a99f9fe7c2819ea61accfcb35088707882b58 Mon Sep 17 00:00:00 2001 From: Felix Janda Date: Mon, 19 Aug 2013 22:11:22 +0200 Subject: In logger and syslogd remove duplicated definitions of facilities and priorities In syslogd.c get the definitions from . For logger.c we can't do this as well since it causes multiply defined symbols. Instead we define a non-static lookup function in syslog.c for logger. --- toys/pending/syslogd.c | 67 ++++++++++---------------------------------------- 1 file changed, 13 insertions(+), 54 deletions(-) (limited to 'toys/pending/syslogd.c') diff --git a/toys/pending/syslogd.c b/toys/pending/syslogd.c index 8cabcc81..4cce1c5f 100644 --- a/toys/pending/syslogd.c +++ b/toys/pending/syslogd.c @@ -33,6 +33,7 @@ config SYSLOGD */ #define FOR_syslogd +#define SYSLOG_NAMES #include "toys.h" #include "toynet.h" @@ -56,60 +57,6 @@ GLOBALS( #define flag_get(f,v,d) ((toys.optflags & f) ? v : d) #define flag_chk(f) ((toys.optflags & f) ? 1 : 0) -#ifndef SYSLOG_NAMES -#define INTERNAL_NOPRI 0x10 -#define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) - -typedef struct _code { - char *c_name; - int c_val; -} CODE; - -static CODE prioritynames[] = -{ - { "alert", LOG_ALERT }, - { "crit", LOG_CRIT }, - { "debug", LOG_DEBUG }, - { "emerg", LOG_EMERG }, - { "err", LOG_ERR }, - { "error", LOG_ERR }, /* DEPRECATED */ - { "info", LOG_INFO }, - { "none", INTERNAL_NOPRI }, /* INTERNAL */ - { "notice", LOG_NOTICE }, - { "panic", LOG_EMERG }, /* DEPRECATED */ - { "warn", LOG_WARNING }, /* DEPRECATED */ - { "warning", LOG_WARNING }, - { NULL, -1 } -}; - -static CODE facilitynames[] = -{ - { "auth", LOG_AUTH }, - { "authpriv", LOG_AUTHPRIV }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "kern", LOG_KERN }, - { "lpr", LOG_LPR }, - { "mail", LOG_MAIL }, - { "mark", INTERNAL_MARK }, /* INTERNAL */ - { "news", LOG_NEWS }, - { "security", LOG_AUTH }, /* DEPRECATED */ - { "syslog", LOG_SYSLOG }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, - { NULL, -1 } -}; -#endif - // Signal handling struct fd_pair { int rd; int wr; }; @@ -504,6 +451,18 @@ static int write_rotate( logfile_t *tf, int len) return write(tf->logfd, toybuf, len); } +// Lookup numerical code from name +// Only used in logger +int logger_lookup(int where, char *key) +{ + CODE *w = ((CODE *[]){facilitynames, prioritynames})[where]; + + for (; w->c_name; w++) + if (!strcasecmp(key, w->c_name)) return w->c_val; + + return -1; +} + //search the given name and return its value static char *dec(int val, CODE *clist) { -- cgit v1.2.3