diff toys/pending/syslogd.c @ 1019:f9271a80fedc

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.
author Felix Janda <felix.janda@posteo.de>
date Mon, 19 Aug 2013 22:11:22 +0200
parents 8b1814e4c987
children 773e4862e790
line wrap: on
line diff
--- a/toys/pending/syslogd.c	Mon Aug 19 04:23:16 2013 -0500
+++ b/toys/pending/syslogd.c	Mon Aug 19 22:11:22 2013 +0200
@@ -33,6 +33,7 @@
 */
 
 #define FOR_syslogd
+#define SYSLOG_NAMES
 #include "toys.h"
 #include "toynet.h"
 
@@ -56,60 +57,6 @@
 #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 @@
   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)
 {