diff options
author | Felix Janda <felix.janda@posteo.de> | 2013-08-19 22:11:22 +0200 |
---|---|---|
committer | Felix Janda <felix.janda@posteo.de> | 2013-08-19 22:11:22 +0200 |
commit | 276a99f9fe7c2819ea61accfcb35088707882b58 (patch) | |
tree | 5c31d8ef983d48e66d7945bed1aad0866cd89b8f /toys/pending/syslogd.c | |
parent | 205b496e42ceb72bf0755fec4f4675a467c401e1 (diff) | |
download | toybox-276a99f9fe7c2819ea61accfcb35088707882b58.tar.gz |
In logger and syslogd remove duplicated definitions of facilities and priorities
In syslogd.c get the definitions from <syslog.h>. 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.
Diffstat (limited to 'toys/pending/syslogd.c')
-rw-r--r-- | toys/pending/syslogd.c | 67 |
1 files changed, 13 insertions, 54 deletions
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) { |