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/logger.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/logger.c')
-rw-r--r-- | toys/pending/logger.c | 38 |
1 files changed, 5 insertions, 33 deletions
diff --git a/toys/pending/logger.c b/toys/pending/logger.c index 87e204d2..d94e6f88 100644 --- a/toys/pending/logger.c +++ b/toys/pending/logger.c @@ -8,51 +8,23 @@ USE_LOGGER(NEWTOY(logger, "st:p:", TOYFLAG_USR|TOYFLAG_BIN)) config LOGGER bool "logger" + depends on SYSLOGD default n help - usage: hello [-s] [-t tag] [-p [facility.]priority] [message] + usage: logger [-s] [-t tag] [-p [facility.]priority] [message] Log message (or stdin) to syslog. */ #define FOR_logger #include "toys.h" -#include <syslog.h> GLOBALS( char *priority_arg; char *ident; ) -struct mapping { - char *key; - int value; -}; - -static struct mapping facilities[] = { - {"user", LOG_USER}, {"main", LOG_MAIL}, {"news", LOG_NEWS}, - {"uucp", LOG_UUCP}, {"daemon", LOG_DAEMON}, {"auth", LOG_AUTH}, - {"cron", LOG_CRON}, {"lpr", LOG_LPR}, {"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, 0} -}; - -static struct mapping priorities[] = { - {"emerg", LOG_EMERG}, {"alert", LOG_ALERT}, {"crit", LOG_CRIT}, - {"err", LOG_ERR}, {"warning", LOG_WARNING}, {"notice", LOG_NOTICE}, - {"info", LOG_INFO}, {"debug", LOG_DEBUG}, - {NULL, 0} -}; - -static int lookup(struct mapping *where, char *key) -{ - for (; where->key; where++) - if (!strcasecmp(key, where->key)) return where->value; - - return -1; -} +extern int logger_lookup(int where, char *key); void logger_main(void) { @@ -64,12 +36,12 @@ void logger_main(void) if (sep) { *sep = '\0'; - if ((facility = lookup(facilities, TT.priority_arg)) == -1) + if ((facility = logger_lookup(0, TT.priority_arg)) == -1) error_exit("bad facility: %s", TT.priority_arg); TT.priority_arg = sep+1; } - if ((priority = lookup(priorities, TT.priority_arg)) == -1) + if ((priority = logger_lookup(1, TT.priority_arg)) == -1) error_exit("bad priority: %s", TT.priority_arg); } |