Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
1018:133ef0885cce | 1019:f9271a80fedc |
---|---|
31 -l N Log only messages more urgent than prio(default:8 max:8 min:1) | 31 -l N Log only messages more urgent than prio(default:8 max:8 min:1) |
32 -D Drop duplicates | 32 -D Drop duplicates |
33 */ | 33 */ |
34 | 34 |
35 #define FOR_syslogd | 35 #define FOR_syslogd |
36 #define SYSLOG_NAMES | |
36 #include "toys.h" | 37 #include "toys.h" |
37 #include "toynet.h" | 38 #include "toynet.h" |
38 | 39 |
39 GLOBALS( | 40 GLOBALS( |
40 char *socket; | 41 char *socket; |
53 int sd; // socket for logging remote messeges. | 54 int sd; // socket for logging remote messeges. |
54 ) | 55 ) |
55 | 56 |
56 #define flag_get(f,v,d) ((toys.optflags & f) ? v : d) | 57 #define flag_get(f,v,d) ((toys.optflags & f) ? v : d) |
57 #define flag_chk(f) ((toys.optflags & f) ? 1 : 0) | 58 #define flag_chk(f) ((toys.optflags & f) ? 1 : 0) |
58 | |
59 #ifndef SYSLOG_NAMES | |
60 #define INTERNAL_NOPRI 0x10 | |
61 #define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) | |
62 | |
63 typedef struct _code { | |
64 char *c_name; | |
65 int c_val; | |
66 } CODE; | |
67 | |
68 static CODE prioritynames[] = | |
69 { | |
70 { "alert", LOG_ALERT }, | |
71 { "crit", LOG_CRIT }, | |
72 { "debug", LOG_DEBUG }, | |
73 { "emerg", LOG_EMERG }, | |
74 { "err", LOG_ERR }, | |
75 { "error", LOG_ERR }, /* DEPRECATED */ | |
76 { "info", LOG_INFO }, | |
77 { "none", INTERNAL_NOPRI }, /* INTERNAL */ | |
78 { "notice", LOG_NOTICE }, | |
79 { "panic", LOG_EMERG }, /* DEPRECATED */ | |
80 { "warn", LOG_WARNING }, /* DEPRECATED */ | |
81 { "warning", LOG_WARNING }, | |
82 { NULL, -1 } | |
83 }; | |
84 | |
85 static CODE facilitynames[] = | |
86 { | |
87 { "auth", LOG_AUTH }, | |
88 { "authpriv", LOG_AUTHPRIV }, | |
89 { "cron", LOG_CRON }, | |
90 { "daemon", LOG_DAEMON }, | |
91 { "ftp", LOG_FTP }, | |
92 { "kern", LOG_KERN }, | |
93 { "lpr", LOG_LPR }, | |
94 { "mail", LOG_MAIL }, | |
95 { "mark", INTERNAL_MARK }, /* INTERNAL */ | |
96 { "news", LOG_NEWS }, | |
97 { "security", LOG_AUTH }, /* DEPRECATED */ | |
98 { "syslog", LOG_SYSLOG }, | |
99 { "user", LOG_USER }, | |
100 { "uucp", LOG_UUCP }, | |
101 { "local0", LOG_LOCAL0 }, | |
102 { "local1", LOG_LOCAL1 }, | |
103 { "local2", LOG_LOCAL2 }, | |
104 { "local3", LOG_LOCAL3 }, | |
105 { "local4", LOG_LOCAL4 }, | |
106 { "local5", LOG_LOCAL5 }, | |
107 { "local6", LOG_LOCAL6 }, | |
108 { "local7", LOG_LOCAL7 }, | |
109 { NULL, -1 } | |
110 }; | |
111 #endif | |
112 | 59 |
113 | 60 |
114 // Signal handling | 61 // Signal handling |
115 struct fd_pair { int rd; int wr; }; | 62 struct fd_pair { int rd; int wr; }; |
116 static struct fd_pair sigfd; | 63 static struct fd_pair sigfd; |
502 } | 449 } |
503 } | 450 } |
504 return write(tf->logfd, toybuf, len); | 451 return write(tf->logfd, toybuf, len); |
505 } | 452 } |
506 | 453 |
454 // Lookup numerical code from name | |
455 // Only used in logger | |
456 int logger_lookup(int where, char *key) | |
457 { | |
458 CODE *w = ((CODE *[]){facilitynames, prioritynames})[where]; | |
459 | |
460 for (; w->c_name; w++) | |
461 if (!strcasecmp(key, w->c_name)) return w->c_val; | |
462 | |
463 return -1; | |
464 } | |
465 | |
507 //search the given name and return its value | 466 //search the given name and return its value |
508 static char *dec(int val, CODE *clist) | 467 static char *dec(int val, CODE *clist) |
509 { | 468 { |
510 const CODE *c; | 469 const CODE *c; |
511 | 470 |