annotate toys/pending/syslogd.c @ 1025:f19286ac3e7f draft

syslogd: cleanup - simplify resolveconfig() -> now logger_lookup is also used in syslogd.c - inline addrfds - small cosmetical changes in parse_config_file()
author Felix Janda <felix.janda at posteo.de>
date Fri, 23 Aug 2013 22:19:55 +0200
parents 63b8e54d2c6f
children 09cc81f6e411
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* syslogd.c - a system logging utility.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
2 *
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright 2013 Madhur Verma <mad.flexi@gmail.com>
997
8b1814e4c987 Ashwini Sharma said that Kyungwan Han should be in the contact info for the commands he sent recently.
Rob Landley <rob@landley.net>
parents: 995
diff changeset
4 * Copyright 2013 Kyungwan Han <asura321@gmail.com>
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 *
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 * No Standard
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
7
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
8 USE_SYSLOGD(NEWTOY(syslogd,">0l#<1>8=8R:b#<0>99=1s#<0=200m#<0>71582787=20O:p:f:a:nSKLD", TOYFLAG_SBIN|TOYFLAG_STAYROOT))
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
9
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
10 config SYSLOGD
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
11 bool "syslogd"
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
12 default n
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
13 help
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
14 Usage: syslogd [-a socket] [-O logfile] [-f config file] [-m interval]
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
15 [-p socket] [-s SIZE] [-b N] [-R HOST] [-l N] [-nSLKD]
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
16
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
17 System logging utility
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
18
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
19 -a Extra unix socket for listen
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 -O FILE Default log file <DEFAULT: /var/log/messages>
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
21 -f FILE Config file <DEFAULT: /etc/syslog.conf>
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 -p Alternative unix domain socket <DEFAULT : /dev/log>
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 -n Avoid auto-backgrounding.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 -S Smaller output
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 -m MARK interval <DEFAULT: 20 minutes> (RANGE: 0 to 71582787)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
26 -R HOST Log to IP or hostname on PORT (default PORT=514/UDP)"
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 -L Log locally and via network (default is network only if -R)"
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 -s SIZE Max size (KB) before rotation (default:200KB, 0=off)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 -b N rotated logs to keep (default:1, max=99, 0=purge)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 -K Log to kernel printk buffer (use dmesg to read it)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
31 -l N Log only messages more urgent than prio(default:8 max:8 min:1)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 -D Drop duplicates
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
34
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
35 #define FOR_syslogd
1019
f9271a80fedc In logger and syslogd remove duplicated definitions of facilities and priorities
Felix Janda <felix.janda@posteo.de>
parents: 997
diff changeset
36 #define SYSLOG_NAMES
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 #include "toys.h"
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 #include "toynet.h"
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
39
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 GLOBALS(
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 char *socket;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 char *config_file;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
43 char *unix_socket;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 char *logfile;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 long interval;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
46 long rot_size;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 long rot_count;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
48 char *remote_log;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 long log_prio;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
50
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
51 struct arg_list *lsocks; // list of listen sockets
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 struct arg_list *lfiles; // list of write logfiles
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 fd_set rfds; // fds for reading
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
54 int sd; // socket for logging remote messeges.
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
55 int sigfd[2];
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
56 )
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
57
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
58
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 // UNIX Sockets for listening
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
60 struct unsocks {
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 char *path;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 struct sockaddr_un sdu;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
63 int sd;
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
64 };
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
65
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
66 // Log file entry to log into.
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
67 struct logfile {
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
68 char *filename;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
69 char *config;
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
70 int isNetwork;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
71 uint32_t facility[8];
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
72 uint8_t level[LOG_NFACILITIES];
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
73 int logfd;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
74 struct sockaddr_in saddr;
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
75 };
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
76
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
77 // Lookup numerical code from name
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
78 // Also used in logger
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
79 int logger_lookup(int where, char *key)
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
80 {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
81 CODE *w = ((CODE *[]){facilitynames, prioritynames})[where];
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
82
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
83 for (; w->c_name; w++)
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
84 if (!strcasecmp(key, w->c_name)) return w->c_val;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
85
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
86 return -1;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
87 }
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
88
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
89 //search the given name and return its value
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
90 static char *dec(int val, CODE *clist)
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
91 {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
92 for (; clist->c_name; clist++)
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
93 if (val == clist->c_val) return clist->c_name;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
94 return itoa(val);
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
95 }
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
96
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
97 // Adds opened socks to rfds for select()
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
98 static int addrfds(void)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
99 {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
100 struct unsocks *sock;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
101 int ret = 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
102 struct arg_list *node = TT.lsocks;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
103 FD_ZERO(&TT.rfds);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
104
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
105 while (node) {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
106 sock = (struct unsocks*) node->arg;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
107 if (sock->sd > 2) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
108 FD_SET(sock->sd, &TT.rfds);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
109 ret = sock->sd;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
110 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
111 node = node->next;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
112 }
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
113 FD_SET(TT.sigfd[0], &TT.rfds);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
114 return (TT.sigfd[0] > ret) ? TT.sigfd[0] : ret;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
115 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
116
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
117 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
118 * initializes unsock_t structure
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
119 * and opens socket for reading
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
120 * and adds to global lsock list.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
121 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
122 static int open_unix_socks(void)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
123 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
124 struct arg_list *node;
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
125 struct unsocks *sock;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
126 int ret = 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
127
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
128 for(node = TT.lsocks; node; node = node->next) {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
129 sock = (struct unsocks*) node->arg;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
130 sock->sdu.sun_family = AF_UNIX;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
131 strcpy(sock->sdu.sun_path, sock->path);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
132 sock->sd = socket(AF_UNIX, SOCK_DGRAM, 0);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
133 if (sock->sd < 0) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
134 perror_msg("OPEN SOCKS : failed");
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
135 continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
136 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
137 unlink(sock->sdu.sun_path);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
138 if (bind(sock->sd, (struct sockaddr *) &sock->sdu, sizeof(sock->sdu))) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
139 perror_msg("BIND SOCKS : failed sock : %s", sock->sdu.sun_path);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
140 close(sock->sd);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
141 continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
142 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
143 chmod(sock->path, 0777);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
144 ret++;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
145 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
146 return ret;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
147 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
148
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
149 // Returns node having filename
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
150 static struct arg_list *get_file_node(char *filename, struct arg_list *list)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
151 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
152 while (list) {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
153 if (!strcmp(((struct logfile*) list->arg)->filename, filename)) return list;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
154 list = list->next;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
155 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
156 return list;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
157 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
158
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
159 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
160 * recurses the logfile list and resolves config
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
161 * for evry file and updates facilty and log level bits.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
162 */
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
163 static int resolve_config(struct logfile *file)
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
164 {
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
165 char *tk, *tmp = xstrdup(file->config);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
166
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
167 for (tk = strtok(tmp, "; \0"); tk; tk = strtok(NULL, "; \0")) {
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
168 char *fac = tk, *lvl;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
169 int i = 0;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
170 unsigned facval = 0;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
171 uint8_t set, levval, bits = 0;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
172
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
173 tk = strchr(fac, '.');
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
174 if (!tk) return -1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
175 *tk = '\0';
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
176 lvl = tk + 1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
177
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
178 for (;;) {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
179 char *nfac = strchr(fac, ',');
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
180
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
181 if (nfac) *nfac = '\0';
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
182 if (*fac == '*') {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
183 facval = 0xFFFFFFFF;
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
184 if (fac[1]) return -1;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
185 } else {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
186 if ((i = logger_lookup(0, fac)) == -1) return -1;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
187 facval |= (1 << LOG_FAC(i));
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
188 }
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
189 if (nfac) fac = nfac + 1;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
190 else break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
191 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
192
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
193 levval = 0;
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
194 for (tk = "!=*"; tk; tk++, bits <<= 1) {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
195 if (*lvl == *tk) {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
196 bits++;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
197 lvl++;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
198 }
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
199 }
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
200 if (bits & 1) levval = 0xff;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
201 if (lvl) {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
202 if ((i = logger_lookup(1, lvl)) == -1) return -1;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
203 levval |= (bits & 2) ? LOG_MASK(i) : LOG_UPTO(i);
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
204 if (bits & 4) levval = ~levval;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
205 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
206
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
207 for (i = 0, set = levval; set; set >>= 1, i++)
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
208 if (set & 0x1) file->facility[i] |= facval;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
209 for (i = 0; i < LOG_NFACILITIES; facval >>= 1, i++)
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
210 if (facval & 0x1) file->level[i] |= levval;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
211 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
212 free(tmp);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
213
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
214 return 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
215 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
216
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
217 // Parse config file and update the log file list.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
218 static int parse_config_file(void)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
219 {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
220 struct logfile *file;
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
221 FILE *fp;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
222 char *confline = NULL, *tk = NULL, *tokens[2] = {NULL, NULL};
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
223 int len, tcount, lineno = 0;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
224 size_t linelen;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
225 struct arg_list *node;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
226 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
227 * if -K then open only /dev/kmsg
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
228 * all other log files are neglected
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
229 * thus no need to open config either.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
230 */
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
231 if (toys.optflags & FLAG_K) {
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
232 node = xzalloc(sizeof(struct arg_list));
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
233 file = xzalloc(sizeof(struct logfile));
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
234 file->filename = "/dev/kmsg";
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
235 file->config = "*.*";
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
236 memset(file->level, 0xFF, sizeof(file->level));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
237 memset(file->facility, 0xFFFFFFFF, sizeof(file->facility));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
238 node->arg = (char*) file;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
239 TT.lfiles = node;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
240 return 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
241 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
242 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
243 * if -R then add remote host to log list
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
244 * if -L is not provided all other log
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
245 * files are neglected thus no need to
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
246 * open config either so just return.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
247 */
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
248 if (toys.optflags & FLAG_R) {
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
249 node = xzalloc(sizeof(struct arg_list));
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
250 file = xzalloc(sizeof(struct logfile));
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
251 file->filename = xmsprintf("@%s",TT.remote_log);
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
252 file->isNetwork = 1;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
253 file->config = "*.*";
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
254 memset(file->level, 0xFF, sizeof(file->level));
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
255 memset(file->facility, 0xFFFFFFFF, sizeof(file->facility));
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
256 node->arg = (char*) file;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
257 TT.lfiles = node;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
258 if (!(toys.optflags & FLAG_L)) return 0;
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
259 }
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
260 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
261 * Read config file and add logfiles to the list
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
262 * with their configuration.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
263 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
264 fp = fopen(TT.config_file, "r");
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
265 if (!fp && (toys.optflags & FLAG_f))
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
266 perror_exit("can't open '%s'", TT.config_file);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
267
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
268 for (len = 0, linelen = 0; fp;) {
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
269 len = getline(&confline, &linelen, fp);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
270 if (len <= 0) break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
271 lineno++;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
272 for (; *confline == ' '; confline++, len--) ;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
273 if ((confline[0] == '#') || (confline[0] == '\n')) continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
274 for (tcount = 0, tk = strtok(confline, " \t"); tk && (tcount < 2); tk =
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
275 strtok(NULL, " \t"), tcount++) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
276 if (tcount == 2) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
277 error_msg("error in '%s' at line %d", TT.config_file, lineno);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
278 return -1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
279 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
280 tokens[tcount] = xstrdup(tk);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
281 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
282 if (tcount <= 1 || tcount > 2) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
283 if (tokens[0]) free(tokens[0]);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
284 error_msg("bad line %d: 1 tokens found, 2 needed", lineno);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
285 return -1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
286 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
287 tk = (tokens[1] + (strlen(tokens[1]) - 1));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
288 if (*tk == '\n') *tk = '\0';
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
289 if (*tokens[1] == '\0') {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
290 error_msg("bad line %d: 1 tokens found, 2 needed", lineno);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
291 return -1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
292 }
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
293 if (*tokens[1] != '*') {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
294 node = get_file_node(tokens[1], TT.lfiles);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
295 if (!node) {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
296 node = xzalloc(sizeof(struct arg_list));
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
297 file = xzalloc(sizeof(struct logfile));
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
298 file->config = xstrdup(tokens[0]);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
299 if (resolve_config(file)==-1) {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
300 error_msg("error in '%s' at line %d", TT.config_file, lineno);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
301 return -1;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
302 }
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
303 file->filename = xstrdup(tokens[1]);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
304 if (*file->filename == '@') file->isNetwork = 1;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
305 node->arg = (char*) file;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
306 node->next = TT.lfiles;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
307 TT.lfiles = node;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
308 } else {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
309 file = (struct logfile*) node->arg;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
310 int rel = strlen(file->config) + strlen(tokens[0]) + 2;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
311 file->config = xrealloc(file->config, rel);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
312 sprintf(file->config, "%s;%s", file->config, tokens[0]);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
313 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
314 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
315 if (tokens[0]) free(tokens[0]);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
316 if (tokens[1]) free(tokens[1]);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
317 free(confline);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
318 confline = NULL;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
319 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
320 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
321 * Can't open config file or support is not enabled
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
322 * adding default logfile to the head of list.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
323 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
324 if (!fp){
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
325 node = xzalloc(sizeof(struct arg_list));
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
326 file = xzalloc(sizeof(struct logfile));
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
327 file->filename = (toys.optflags & FLAG_O) ?
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
328 TT.logfile : "/var/log/messages"; //DEFLOGFILE
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
329 file->config = "*.*";
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
330 memset(file->level, 0xFF, sizeof(file->level));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
331 memset(file->facility, 0xFFFFFFFF, sizeof(file->facility));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
332 node->arg = (char*) file;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
333 node->next = TT.lfiles;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
334 TT.lfiles = node;
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
335 } else fclose(fp);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
336 return 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
337 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
338
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
339 // open every log file in list.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
340 static void open_logfiles(void)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
341 {
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
342 struct arg_list *node;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
343
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
344 for (node = TT.lfiles; node; node = node->next) {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
345 struct logfile *tfd = (struct logfile*) node->arg;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
346 char *p, *tmpfile;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
347 long port = 514;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
348
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
349 if (tfd->isNetwork) {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
350 struct addrinfo *info, rp;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
351
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
352 tmpfile = xstrdup(tfd->filename + 1);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
353 if ((p = strchr(tmpfile, ':'))) {
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
354 char *endptr;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
355
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
356 *p = '\0';
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
357 port = strtol(++p, &endptr, 10);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
358 if (*endptr || endptr == p || port < 0 || port > 65535)
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
359 error_exit("bad port in %s", tfd->filename);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
360 }
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
361 memset(&rp, 0, sizeof(rp));
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
362 rp.ai_family = AF_INET;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
363 rp.ai_socktype = SOCK_DGRAM;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
364 rp.ai_protocol = IPPROTO_UDP;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
365
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
366 if (getaddrinfo(tmpfile, NULL, &rp, &info) || !info)
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
367 perror_exit("BAD ADDRESS: can't find : %s ", tmpfile);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
368 ((struct sockaddr_in*)info->ai_addr)->sin_port = htons(port);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
369 memcpy(&tfd->saddr, info->ai_addr, info->ai_addrlen);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
370 freeaddrinfo(info);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
371
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
372 tfd->logfd = xsocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
373 free(tmpfile);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
374 } else tfd->logfd = open(tfd->filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
375 if (tfd->logfd < 0) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
376 tfd->filename = "/dev/console";
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
377 tfd->logfd = open(tfd->filename, O_APPEND);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
378 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
379 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
380 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
381
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
382 //write to file with rotation
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
383 static int write_rotate(struct logfile *tf, int len)
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
384 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
385 int size, isreg;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
386 struct stat statf;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
387 isreg = (!fstat(tf->logfd, &statf) && S_ISREG(statf.st_mode));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
388 size = statf.st_size;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
389
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
390 if ((toys.optflags & FLAG_s) || (toys.optflags & FLAG_b)) {
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
391 if (TT.rot_size && isreg && (size + len) > (TT.rot_size*1024)) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
392 if (TT.rot_count) { /* always 0..99 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
393 int i = strlen(tf->filename) + 3 + 1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
394 char old_file[i];
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
395 char new_file[i];
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
396 i = TT.rot_count - 1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
397 while (1) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
398 sprintf(new_file, "%s.%d", tf->filename, i);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
399 if (!i) break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
400 sprintf(old_file, "%s.%d", tf->filename, --i);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
401 rename(old_file, new_file);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
402 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
403 rename(tf->filename, new_file);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
404 unlink(tf->filename);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
405 close(tf->logfd);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
406 tf->logfd = open(tf->filename, O_CREAT | O_WRONLY | O_APPEND, 0666);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
407 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
408 ftruncate(tf->logfd, 0);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
409 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
410 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
411 return write(tf->logfd, toybuf, len);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
412 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
413
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
414 //Parse messege and write to file.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
415 static void logmsg(char *msg, int len)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
416 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
417 time_t now;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
418 char *p, *ts, *lvlstr, *facstr;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
419 struct utsname uts;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
420 int pri = 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
421 struct arg_list *lnode = TT.lfiles;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
422
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
423 char *omsg = msg;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
424 int olen = len, fac, lvl;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
425
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
426 if (*msg == '<') { // Extract the priority no.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
427 pri = (int) strtoul(msg + 1, &p, 10);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
428 if (*p == '>') msg = p + 1;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
429 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
430 /* Jan 18 00:11:22 msg...
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
431 * 01234567890123456
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
432 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
433 if (len < 16 || msg[3] != ' ' || msg[6] != ' ' || msg[9] != ':'
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
434 || msg[12] != ':' || msg[15] != ' ') {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
435 time(&now);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
436 ts = ctime(&now) + 4; /* skip day of week */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
437 } else {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
438 now = 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
439 ts = msg;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
440 msg += 16;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
441 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
442 ts[15] = '\0';
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
443 fac = LOG_FAC(pri);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
444 lvl = LOG_PRI(pri);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
445
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
446 if (toys.optflags & FLAG_K) len = sprintf(toybuf, "<%d> %s\n", pri, msg);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
447 else {
1025
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
448 facstr = dec(LOG_FAC(pri), facilitynames);
f19286ac3e7f syslogd: cleanup
Felix Janda <felix.janda at posteo.de>
parents: 1024
diff changeset
449 lvlstr = dec(LOG_PRI(pri), prioritynames);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
450
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
451 p = "local";
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
452 if (!uname(&uts)) p = uts.nodename;
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
453 if (toys.optflags & FLAG_S) len = sprintf(toybuf, "%s %s\n", ts, msg);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
454 else len = sprintf(toybuf, "%s %s %s.%s %s\n", ts, p, facstr, lvlstr, msg);
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
455 }
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
456 if (lvl >= TT.log_prio) return;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
457
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
458 while (lnode) {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
459 struct logfile *tf = (struct logfile*) lnode->arg;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
460 if (tf->logfd > 0) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
461 if ((tf->facility[lvl] & (1 << fac)) && (tf->level[fac] & (1<<lvl))) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
462 int wlen;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
463 if (tf->isNetwork)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
464 wlen = sendto(tf->logfd, omsg, olen, 0, (struct sockaddr*)&tf->saddr, sizeof(tf->saddr));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
465 else wlen = write_rotate(tf, len);
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
466 if (wlen < 0) perror_msg("write failed file : %s ", tf->filename + tf->isNetwork);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
467 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
468 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
469 lnode = lnode->next;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
470 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
471 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
472
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
473 /*
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
474 * closes all read and write fds
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
475 * and frees all nodes and lists
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
476 */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
477 static void cleanup(void)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
478 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
479 struct arg_list *fnode;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
480 while (TT.lsocks) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
481 fnode = TT.lsocks;
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
482 if (((struct unsocks*) fnode->arg)->sd >= 0)
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
483 close(((struct unsocks*) fnode->arg)->sd);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
484 free(fnode->arg);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
485 TT.lsocks = fnode->next;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
486 free(fnode);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
487 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
488 unlink("/dev/log");
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
489
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
490 while (TT.lfiles) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
491 fnode = TT.lfiles;
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
492 if (((struct logfile*) fnode->arg)->logfd >= 0)
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
493 close(((struct logfile*) fnode->arg)->logfd);
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
494 free(fnode->arg);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
495 TT.lfiles = fnode->next;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
496 free(fnode);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
497 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
498 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
499
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
500 static void signal_handler(int sig)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
501 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
502 unsigned char ch = sig;
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
503 if (write(TT.sigfd[1], &ch, 1) != 1) error_msg("can't send signal");
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
504 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
505
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
506 void syslogd_main(void)
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
507 {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
508 struct unsocks *tsd;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
509 int maxfd, retval, last_len=0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
510 struct timeval tv;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
511 struct arg_list *node;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
512 char *temp, *buffer = (toybuf +2048), *last_buf = (toybuf + 3072); //these two buffs are of 1K each
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
513
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
514 if ((toys.optflags & FLAG_p) && (strlen(TT.unix_socket) > 108))
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
515 error_exit("Socket path should not be more than 108");
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
516
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
517 TT.config_file = (toys.optflags & FLAG_f) ?
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
518 TT.config_file : "/etc/syslog.conf"; //DEFCONFFILE
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
519 init_jumpin:
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
520 TT.lsocks = xzalloc(sizeof(struct arg_list));
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
521 tsd = xzalloc(sizeof(struct unsocks));
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
522
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
523 tsd->path = (toys.optflags & FLAG_p) ? TT.unix_socket : "/dev/log"; // DEFLOGSOCK
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
524 TT.lsocks->arg = (char*) tsd;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
525
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
526 if (toys.optflags & FLAG_a) {
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
527 for (temp = strtok(TT.socket, ":"); temp; temp = strtok(NULL, ":")) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
528 struct arg_list *ltemp = xzalloc(sizeof(struct arg_list));
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
529 if (strlen(temp) > 107) temp[108] = '\0';
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
530 tsd = xzalloc(sizeof(struct unsocks));
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
531 tsd->path = temp;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
532 ltemp->arg = (char*) tsd;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
533 ltemp->next = TT.lsocks;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
534 TT.lsocks = ltemp;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
535 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
536 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
537 if (!open_unix_socks()) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
538 error_msg("Can't open single socket for listenning.");
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
539 goto clean_and_exit;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
540 }
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
541
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
542 // Setup signals
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
543 if (pipe(TT.sigfd) < 0) error_exit("pipe failed\n");
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
544
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
545 fcntl(TT.sigfd[1] , F_SETFD, FD_CLOEXEC);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
546 fcntl(TT.sigfd[0] , F_SETFD, FD_CLOEXEC);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
547 int flags = fcntl(TT.sigfd[1], F_GETFL);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
548 fcntl(TT.sigfd[1], F_SETFL, flags | O_NONBLOCK);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
549 signal(SIGHUP, signal_handler);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
550 signal(SIGTERM, signal_handler);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
551 signal(SIGINT, signal_handler);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
552 signal(SIGQUIT, signal_handler);
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
553
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
554 if (parse_config_file() == -1) goto clean_and_exit;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
555 open_logfiles();
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
556 if (!(toys.optflags & FLAG_n)) {
995
893c86bbe452 Add daemonize function to lib for klogd and syslogd
Felix Janda <felix.janda@posteo.de>
parents: 960
diff changeset
557 //don't daemonize again if SIGHUP received.
893c86bbe452 Add daemonize function to lib for klogd and syslogd
Felix Janda <felix.janda@posteo.de>
parents: 960
diff changeset
558 toys.optflags |= FLAG_n;
893c86bbe452 Add daemonize function to lib for klogd and syslogd
Felix Janda <felix.janda@posteo.de>
parents: 960
diff changeset
559 }
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
560 {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
561 int pid_fd = open("/var/run/syslogd.pid", O_CREAT | O_WRONLY | O_TRUNC, 0666);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
562 if (pid_fd > 0) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
563 unsigned pid = getpid();
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
564 int len = sprintf(toybuf, "%u\n", pid);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
565 write(pid_fd, toybuf, len);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
566 close(pid_fd);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
567 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
568 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
569
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
570 logmsg("<46>Toybox: syslogd started", 27); //27 : the length of message
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
571 for (;;) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
572 maxfd = addrfds();
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
573 tv.tv_usec = 0;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
574 tv.tv_sec = TT.interval*60;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
575
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
576 retval = select(maxfd + 1, &TT.rfds, NULL, NULL, (TT.interval)?&tv:NULL);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
577 if (retval < 0) { /* Some error. */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
578 if (errno == EINTR) continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
579 perror_msg("Error in select ");
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
580 continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
581 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
582 if (!retval) { /* Timed out */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
583 logmsg("<46>-- MARK --", 14);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
584 continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
585 }
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
586 if (FD_ISSET(TT.sigfd[0], &TT.rfds)) { /* May be a signal */
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
587 unsigned char sig;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
588
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
589 if (read(TT.sigfd[0], &sig, 1) != 1) {
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
590 error_msg("signal read failed.\n");
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
591 continue;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
592 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
593 switch(sig) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
594 case SIGTERM: /* FALLTHROUGH */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
595 case SIGINT: /* FALLTHROUGH */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
596 case SIGQUIT:
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
597 logmsg("<46>syslogd exiting", 19);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
598 if (CFG_TOYBOX_FREE ) cleanup();
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
599 signal(sig, SIG_DFL);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
600 sigset_t ss;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
601 sigemptyset(&ss);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
602 sigaddset(&ss, sig);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
603 sigprocmask(SIG_UNBLOCK, &ss, NULL);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
604 raise(sig);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
605 _exit(1); /* Should not reach it */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
606 break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
607 case SIGHUP:
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
608 logmsg("<46>syslogd exiting", 19);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
609 cleanup(); //cleanup is done, as we restart syslog.
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
610 goto init_jumpin;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
611 default: break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
612 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
613 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
614 if (retval > 0) { /* Some activity on listen sockets. */
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
615 node = TT.lsocks;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
616 while (node) {
1021
773e4862e790 syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1019
diff changeset
617 int sd = ((struct unsocks*) node->arg)->sd;
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
618 if (FD_ISSET(sd, &TT.rfds)) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
619 int len = read(sd, buffer, 1023); //buffer is of 1K, hence readingonly 1023 bytes, 1 for NUL
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
620 if (len > 0) {
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
621 buffer[len] = '\0';
1024
63b8e54d2c6f syslogd: cleanup
Felix Janda <felix.janda@posteo.de>
parents: 1021
diff changeset
622 if((toys.optflags & FLAG_D) && (len == last_len))
960
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
623 if (!memcmp(last_buf, buffer, len)) break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
624
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
625 memcpy(last_buf, buffer, len);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
626 last_len = len;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
627 logmsg(buffer, len);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
628 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
629 break;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
630 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
631 node = node->next;
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
632 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
633 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
634 }
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
635 clean_and_exit:
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
636 logmsg("<46>syslogd exiting", 19);
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
637 if (CFG_TOYBOX_FREE ) cleanup();
c0627c163893 syslogd by Madhur Verma.
Rob Landley <rob@landley.net>
parents:
diff changeset
638 }