blob: 76a446b6a8f7770fb9c4163dddcbfe71bc5852bb [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersen3843e961999-11-25 07:30:46 +00002/*
3 * Mini syslogd implementation for busybox
4 *
Eric Andersenc7bda1c2004-03-15 08:29:22 +00005 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
Eric Andersen3843e961999-11-25 07:30:46 +00006 *
Erik Andersenf13df372000-04-18 23:51:51 +00007 * Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
8 *
Glenn L McGrath6ed77592002-12-12 10:54:48 +00009 * "circular buffer" Copyright (C) 2001 by Gennady Feldman <gfeldman@gena01.com>
Mark Whitley6317c4b2001-03-12 22:51:50 +000010 *
Glenn L McGrath6ed77592002-12-12 10:54:48 +000011 * Maintainer: Gennady Feldman <gfeldman@gena01.com> as of Mar 12, 2001
Mark Whitley6bff9cc2001-03-12 23:41:34 +000012 *
Bernhard Reutner-Fischer86f5c992006-01-22 22:55:11 +000013 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Eric Andersen3843e961999-11-25 07:30:46 +000014 */
Eric Andersenb99df0f1999-11-24 09:04:33 +000015
Bernhard Reutner-Fischere15d7572006-06-02 20:56:16 +000016#include "busybox.h"
Eric Andersenb186d981999-12-03 09:19:54 +000017#include <paths.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000018#include <sys/un.h>
Eric Andersenb186d981999-12-03 09:19:54 +000019
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000020/* SYSLOG_NAMES defined to pull some extra junk from syslog.h: */
21/* prioritynames[] and facilitynames[]. uclibc pulls those in _rwdata_! :( */
22
Eric Andersen3843e961999-11-25 07:30:46 +000023#define SYSLOG_NAMES
24#include <sys/syslog.h>
Eric Andersenced2cef2000-07-20 23:41:24 +000025#include <sys/uio.h>
Eric Andersen3843e961999-11-25 07:30:46 +000026
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000027#if ENABLE_FEATURE_REMOTE_LOG
28#include <netinet/in.h>
Denis Vlasenko4998c812007-02-14 20:51:46 +000029#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +000030
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000031#if ENABLE_FEATURE_IPC_SYSLOG
32#include <sys/ipc.h>
33#include <sys/sem.h>
34#include <sys/shm.h>
35#endif
Denis Vlasenko1decd0e2006-09-30 19:17:40 +000036
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000037
38#define DEBUG 0
39
Denis Vlasenko4f93cde2007-03-20 20:03:03 +000040/* MARK code is not very useful, is bloat, and broken:
41 * can deadlock if alarmed to make MARK while writing to IPC buffer
42 * (semaphores are down but do_mark routine tries to down them again) */
43#undef SYSLOGD_MARK
44
45enum { MAX_READ = 256 };
46
47/* Semaphore operation structures */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000048struct shbuf_ds {
Denis Vlasenko4f93cde2007-03-20 20:03:03 +000049 int32_t size; /* size of data written */
50 int32_t head; /* start of message list */
51 int32_t tail; /* end of message list */
52 char data[1]; /* data/messages */
53};
54
55/* Allows us to have smaller initializer. Ugly. */
56#define GLOBALS \
57 const char *logFilePath; \
58 int logFD; \
59 /* interval between marks in seconds */ \
60 /*int markInterval;*/ \
61 /* level of messages to be logged */ \
62 int logLevel; \
63USE_FEATURE_ROTATE_LOGFILE( \
64 /* max size of file before rotation */ \
65 unsigned logFileSize; \
66 /* number of rotated message files */ \
67 unsigned logFileRotate; \
68 unsigned curFileSize; \
69 smallint isRegular; \
70) \
71USE_FEATURE_REMOTE_LOG( \
72 /* udp socket for remote logging */ \
73 int remoteFD; \
74 len_and_sockaddr* remoteAddr; \
75) \
76USE_FEATURE_IPC_SYSLOG( \
77 int shmid; /* ipc shared memory id */ \
78 int s_semid; /* ipc semaphore id */ \
79 int shm_size; \
80 struct sembuf SMwup[1]; \
81 struct sembuf SMwdn[3]; \
82)
83
84struct init_globals {
85 GLOBALS
86};
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000087
88struct globals {
Denis Vlasenko4f93cde2007-03-20 20:03:03 +000089 GLOBALS
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000090#if ENABLE_FEATURE_IPC_SYSLOG
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000091 struct shbuf_ds *shbuf;
92#endif
Denis Vlasenko5e892ba2007-03-15 19:50:46 +000093 time_t last_log_time;
94 /* localhost's name */
95 char localHostName[64];
96
Denis Vlasenko4f93cde2007-03-20 20:03:03 +000097 /* We recv into recvbuf... */
98 char recvbuf[MAX_READ];
99 /* ...then copy to parsebuf, escaping control chars */
100 /* (can grow x2 max) */
101 char parsebuf[MAX_READ*2];
102 /* ...then sprintf into printbuf, adding timestamp (15 chars),
103 * host (64), fac.prio (20) to the message */
104 /* (growth by: 15 + 64 + 20 + delims = ~110) */
105 char printbuf[MAX_READ*2 + 128];
106};
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000107
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000108static const struct init_globals init_data = {
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000109 .logFilePath = "/var/log/messages",
110 .logFD = -1,
111#ifdef SYSLOGD_MARK
112 .markInterval = 20 * 60,
113#endif
114 .logLevel = 8,
115#if ENABLE_FEATURE_ROTATE_LOGFILE
116 .logFileSize = 200 * 1024,
117 .logFileRotate = 1,
118#endif
119#if ENABLE_FEATURE_REMOTE_LOG
120 .remoteFD = -1,
121#endif
122#if ENABLE_FEATURE_IPC_SYSLOG
123 .shmid = -1,
124 .s_semid = -1,
125 .shm_size = ((CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE)*1024), // default shm size
126 .SMwup = { {1, -1, IPC_NOWAIT} },
127 .SMwdn = { {0, 0}, {1, 0}, {1, +1} },
128#endif
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000129};
130
131#define G (*ptr_to_globals)
132
133
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000134/* Options */
Denis Vlasenko14c19402006-09-30 19:20:00 +0000135enum {
136 OPTBIT_mark = 0, // -m
137 OPTBIT_nofork, // -n
138 OPTBIT_outfile, // -O
139 OPTBIT_loglevel, // -l
140 OPTBIT_small, // -S
141 USE_FEATURE_ROTATE_LOGFILE(OPTBIT_filesize ,) // -s
142 USE_FEATURE_ROTATE_LOGFILE(OPTBIT_rotatecnt ,) // -b
143 USE_FEATURE_REMOTE_LOG( OPTBIT_remote ,) // -R
144 USE_FEATURE_REMOTE_LOG( OPTBIT_localtoo ,) // -L
145 USE_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C
146
147 OPT_mark = 1 << OPTBIT_mark ,
148 OPT_nofork = 1 << OPTBIT_nofork ,
149 OPT_outfile = 1 << OPTBIT_outfile ,
150 OPT_loglevel = 1 << OPTBIT_loglevel,
151 OPT_small = 1 << OPTBIT_small ,
152 OPT_filesize = USE_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_filesize )) + 0,
153 OPT_rotatecnt = USE_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotatecnt )) + 0,
154 OPT_remotelog = USE_FEATURE_REMOTE_LOG( (1 << OPTBIT_remote )) + 0,
155 OPT_locallog = USE_FEATURE_REMOTE_LOG( (1 << OPTBIT_localtoo )) + 0,
156 OPT_circularlog = USE_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0,
157};
158#define OPTION_STR "m:nO:l:S" \
159 USE_FEATURE_ROTATE_LOGFILE("s:" ) \
160 USE_FEATURE_ROTATE_LOGFILE("b:" ) \
161 USE_FEATURE_REMOTE_LOG( "R:" ) \
162 USE_FEATURE_REMOTE_LOG( "L" ) \
163 USE_FEATURE_IPC_SYSLOG( "C::")
164#define OPTION_DECL *opt_m, *opt_l \
165 USE_FEATURE_ROTATE_LOGFILE(,*opt_s) \
166 USE_FEATURE_ROTATE_LOGFILE(,*opt_b) \
167 USE_FEATURE_REMOTE_LOG( ,*opt_R) \
168 USE_FEATURE_IPC_SYSLOG( ,*opt_C = NULL)
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000169#define OPTION_PARAM &opt_m, &G.logFilePath, &opt_l \
Denis Vlasenko14c19402006-09-30 19:20:00 +0000170 USE_FEATURE_ROTATE_LOGFILE(,&opt_s) \
171 USE_FEATURE_ROTATE_LOGFILE(,&opt_b) \
172 USE_FEATURE_REMOTE_LOG( ,&opt_R) \
173 USE_FEATURE_IPC_SYSLOG( ,&opt_C)
Eric Andersen871d93c2002-09-17 20:06:29 +0000174
Eric Andersen871d93c2002-09-17 20:06:29 +0000175
Mark Whitley6317c4b2001-03-12 22:51:50 +0000176/* circular buffer variables/structures */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000177#if ENABLE_FEATURE_IPC_SYSLOG
178
Eric Andersend4a5e252003-12-19 11:32:14 +0000179#if CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE < 4
180#error Sorry, you must set the syslogd buffer size to at least 4KB.
181#error Please check CONFIG_FEATURE_IPC_SYSLOG_BUFFER_SIZE
182#endif
183
Mark Whitley6317c4b2001-03-12 22:51:50 +0000184/* our shared key */
Denis Vlasenko14c19402006-09-30 19:20:00 +0000185#define KEY_ID ((long)0x414e4547) /* "GENA" */
Mark Whitley6317c4b2001-03-12 22:51:50 +0000186
"Vladimir N. Oleynik"e4baaa22005-09-22 12:59:26 +0000187static void ipcsyslog_cleanup(void)
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000188{
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000189 if (G.shmid != -1) {
190 shmdt(G.shbuf);
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000191 }
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000192 if (G.shmid != -1) {
193 shmctl(G.shmid, IPC_RMID, NULL);
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000194 }
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000195 if (G.s_semid != -1) {
196 semctl(G.s_semid, 0, IPC_RMID, 0);
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000197 }
Mark Whitley6317c4b2001-03-12 22:51:50 +0000198}
199
"Vladimir N. Oleynik"e4baaa22005-09-22 12:59:26 +0000200static void ipcsyslog_init(void)
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000201{
Denis Vlasenkoa9b60e92007-01-04 17:59:59 +0000202 if (DEBUG)
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000203 printf("shmget(%lx, %d,...)\n", KEY_ID, G.shm_size);
Denis Vlasenkoa9b60e92007-01-04 17:59:59 +0000204
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000205 G.shmid = shmget(KEY_ID, G.shm_size, IPC_CREAT | 1023);
206 if (G.shmid == -1) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000207 bb_perror_msg_and_die("shmget");
208 }
Mark Whitley6317c4b2001-03-12 22:51:50 +0000209
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000210 G.shbuf = shmat(G.shmid, NULL, 0);
211 if (!G.shbuf) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000212 bb_perror_msg_and_die("shmat");
213 }
Mark Whitley6317c4b2001-03-12 22:51:50 +0000214
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000215 G.shbuf->size = G.shm_size - offsetof(struct shbuf_ds, data);
216 G.shbuf->head = G.shbuf->tail = 0;
Mark Whitley6317c4b2001-03-12 22:51:50 +0000217
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000218 // we'll trust the OS to set initial semval to 0 (let's hope)
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000219 G.s_semid = semget(KEY_ID, 2, IPC_CREAT | IPC_EXCL | 1023);
220 if (G.s_semid == -1) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000221 if (errno == EEXIST) {
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000222 G.s_semid = semget(KEY_ID, 2, 0);
223 if (G.s_semid != -1)
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000224 return;
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000225 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000226 bb_perror_msg_and_die("semget");
Mark Whitley6317c4b2001-03-12 22:51:50 +0000227 }
228}
229
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000230/* Write message to shared mem buffer */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000231static void log_to_shmem(const char *msg, int len)
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000232{
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000233 int old_tail, new_tail;
234 char *c;
Mark Whitley6317c4b2001-03-12 22:51:50 +0000235
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000236 if (semop(G.s_semid, G.SMwdn, 3) == -1) {
Bernhard Reutner-Fischerd591a362006-08-20 17:35:13 +0000237 bb_perror_msg_and_die("SMwdn");
238 }
Mark Whitley6317c4b2001-03-12 22:51:50 +0000239
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000240 /* Circular Buffer Algorithm:
Mark Whitley6317c4b2001-03-12 22:51:50 +0000241 * --------------------------
Denis Vlasenko150f4022007-01-13 21:06:21 +0000242 * tail == position where to store next syslog message.
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000243 * head == position of next message to retrieve ("print").
244 * if head == tail, there is no "unprinted" messages left.
245 * head is typically advanced by separate "reader" program,
246 * but if there isn't one, we have to do it ourself.
247 * messages are NUL-separated.
Mark Whitley6317c4b2001-03-12 22:51:50 +0000248 */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000249 len++; /* length with NUL included */
250 again:
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000251 old_tail = G.shbuf->tail;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000252 new_tail = old_tail + len;
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000253 if (new_tail < G.shbuf->size) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000254 /* No need to move head if shbuf->head <= old_tail,
255 * else... */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000256 if (old_tail < G.shbuf->head && G.shbuf->head <= new_tail) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000257 /* ...need to move head forward */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000258 c = memchr(G.shbuf->data + new_tail, '\0',
259 G.shbuf->size - new_tail);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000260 if (!c) /* no NUL ahead of us, wrap around */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000261 c = memchr(G.shbuf->data, '\0', old_tail);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000262 if (!c) { /* still nothing? point to this msg... */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000263 G.shbuf->head = old_tail;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000264 } else {
265 /* convert pointer to offset + skip NUL */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000266 G.shbuf->head = c - G.shbuf->data + 1;
Mark Whitley6317c4b2001-03-12 22:51:50 +0000267 }
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000268 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000269 /* store message, set new tail */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000270 memcpy(G.shbuf->data + old_tail, msg, len);
271 G.shbuf->tail = new_tail;
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000272 } else {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000273 /* we need to break up the message and wrap it around */
274 /* k == available buffer space ahead of old tail */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000275 int k = G.shbuf->size - old_tail - 1;
276 if (G.shbuf->head > old_tail) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000277 /* we are going to overwrite head, need to
278 * move it out of the way */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000279 c = memchr(G.shbuf->data, '\0', old_tail);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000280 if (!c) { /* nothing? point to this msg... */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000281 G.shbuf->head = old_tail;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000282 } else { /* convert pointer to offset + skip NUL */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000283 G.shbuf->head = c - G.shbuf->data + 1;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000284 }
Mark Whitley6317c4b2001-03-12 22:51:50 +0000285 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000286 /* copy what fits to the end of buffer, and repeat */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000287 memcpy(G.shbuf->data + old_tail, msg, k);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000288 msg += k;
289 len -= k;
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000290 G.shbuf->tail = 0;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000291 goto again;
Mark Whitley6317c4b2001-03-12 22:51:50 +0000292 }
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000293 if (semop(G.s_semid, G.SMwup, 1) == -1) {
Bernhard Reutner-Fischerd591a362006-08-20 17:35:13 +0000294 bb_perror_msg_and_die("SMwup");
295 }
Denis Vlasenkoa9b60e92007-01-04 17:59:59 +0000296 if (DEBUG)
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000297 printf("head:%d tail:%d\n", G.shbuf->head, G.shbuf->tail);
Mark Whitley6317c4b2001-03-12 22:51:50 +0000298}
Rob Landley028ba282006-08-28 20:16:42 +0000299#else
300void ipcsyslog_cleanup(void);
301void ipcsyslog_init(void);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000302void log_to_shmem(const char *msg);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000303#endif /* FEATURE_IPC_SYSLOG */
304
305
Erik Andersen983b51b2000-04-04 18:14:25 +0000306/* Print a message to the log file. */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000307static void log_locally(char *msg)
Eric Andersen3843e961999-11-25 07:30:46 +0000308{
Denis Vlasenkob8934972007-01-04 18:02:32 +0000309 struct flock fl;
310 int len = strlen(msg);
Eric Andersen3843e961999-11-25 07:30:46 +0000311
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000312#if ENABLE_FEATURE_IPC_SYSLOG
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000313 if ((option_mask32 & OPT_circularlog) && G.shbuf) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000314 log_to_shmem(msg, len);
315 return;
316 }
Mark Whitley6317c4b2001-03-12 22:51:50 +0000317#endif
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000318 if (G.logFD >= 0) {
Denis Vlasenkob8934972007-01-04 18:02:32 +0000319 time_t cur;
320 time(&cur);
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000321 if (G.last_log_time != cur) {
322 G.last_log_time = cur; /* reopen log file every second */
323 close(G.logFD);
Denis Vlasenkob8934972007-01-04 18:02:32 +0000324 goto reopen;
325 }
326 } else {
Denis Vlasenkob8934972007-01-04 18:02:32 +0000327 reopen:
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000328 G.logFD = device_open(G.logFilePath, O_WRONLY | O_CREAT
Denis Vlasenkobd8f43d2006-09-08 17:31:55 +0000329 | O_NOCTTY | O_APPEND | O_NONBLOCK);
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000330 if (G.logFD < 0) {
Denis Vlasenkob8934972007-01-04 18:02:32 +0000331 /* cannot open logfile? - print to /dev/console then */
332 int fd = device_open(_PATH_CONSOLE, O_WRONLY | O_NOCTTY | O_NONBLOCK);
333 if (fd < 0)
334 fd = 2; /* then stderr, dammit */
335 full_write(fd, msg, len);
336 if (fd != 2)
337 close(fd);
338 return;
339 }
340#if ENABLE_FEATURE_ROTATE_LOGFILE
Denis Vlasenkobae79482007-01-09 23:42:43 +0000341 {
342 struct stat statf;
343
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000344 G.isRegular = (fstat(G.logFD, &statf) == 0 && (statf.st_mode & S_IFREG));
Denis Vlasenkob8934972007-01-04 18:02:32 +0000345 /* bug (mostly harmless): can wrap around if file > 4gb */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000346 G.curFileSize = statf.st_size;
Denis Vlasenkobae79482007-01-09 23:42:43 +0000347 }
Denis Vlasenkob8934972007-01-04 18:02:32 +0000348#endif
349 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000350
Denis Vlasenkob8934972007-01-04 18:02:32 +0000351 fl.l_whence = SEEK_SET;
352 fl.l_start = 0;
353 fl.l_len = 1;
354 fl.l_type = F_WRLCK;
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000355 fcntl(G.logFD, F_SETLKW, &fl);
Bernhard Reutner-Fischerd591a362006-08-20 17:35:13 +0000356
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000357#if ENABLE_FEATURE_ROTATE_LOGFILE
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000358 if (G.logFileSize && G.isRegular && G.curFileSize > G.logFileSize) {
359 if (G.logFileRotate) { /* always 0..99 */
360 int i = strlen(G.logFilePath) + 3 + 1;
Denis Vlasenkob8934972007-01-04 18:02:32 +0000361 char oldFile[i];
362 char newFile[i];
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000363 i = G.logFileRotate - 1;
Denis Vlasenkob8934972007-01-04 18:02:32 +0000364 /* rename: f.8 -> f.9; f.7 -> f.8; ... */
365 while (1) {
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000366 sprintf(newFile, "%s.%d", G.logFilePath, i);
Denis Vlasenkob8934972007-01-04 18:02:32 +0000367 if (i == 0) break;
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000368 sprintf(oldFile, "%s.%d", G.logFilePath, --i);
Denis Vlasenkob8934972007-01-04 18:02:32 +0000369 rename(oldFile, newFile);
Eric Andersen29c77f72003-10-09 09:43:18 +0000370 }
Denis Vlasenkob8934972007-01-04 18:02:32 +0000371 /* newFile == "f.0" now */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000372 rename(G.logFilePath, newFile);
Denis Vlasenkob8934972007-01-04 18:02:32 +0000373 fl.l_type = F_UNLCK;
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000374 fcntl(G.logFD, F_SETLKW, &fl);
375 close(G.logFD);
Denis Vlasenkob8934972007-01-04 18:02:32 +0000376 goto reopen;
Eric Andersen29c77f72003-10-09 09:43:18 +0000377 }
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000378 ftruncate(G.logFD, 0);
Eric Andersen3843e961999-11-25 07:30:46 +0000379 }
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000380 G.curFileSize +=
Denis Vlasenkob8934972007-01-04 18:02:32 +0000381#endif
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000382 full_write(G.logFD, msg, len);
Denis Vlasenkob8934972007-01-04 18:02:32 +0000383 fl.l_type = F_UNLCK;
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000384 fcntl(G.logFD, F_SETLKW, &fl);
Eric Andersenb99df0f1999-11-24 09:04:33 +0000385}
386
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000387static void parse_fac_prio_20(int pri, char *res20)
Eric Andersen3843e961999-11-25 07:30:46 +0000388{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000389 CODE *c_pri, *c_fac;
Eric Andersenb99df0f1999-11-24 09:04:33 +0000390
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000391 if (pri != 0) {
Denis Vlasenko14c19402006-09-30 19:20:00 +0000392 c_fac = facilitynames;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000393 while (c_fac->c_name) {
394 if (c_fac->c_val != (LOG_FAC(pri) << 3)) {
395 c_fac++; continue;
396 }
397 /* facility is found, look for prio */
398 c_pri = prioritynames;
399 while (c_pri->c_name) {
400 if (c_pri->c_val != LOG_PRI(pri)) {
401 c_pri++; continue;
402 }
403 snprintf(res20, 20, "%s.%s",
404 c_fac->c_name, c_pri->c_name);
405 return;
406 }
407 /* prio not found, bail out */
408 break;
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000409 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000410 snprintf(res20, 20, "<%d>", pri);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000411 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000412}
Eric Andersen3843e961999-11-25 07:30:46 +0000413
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000414/* len parameter is used only for "is there a timestamp?" check.
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000415 * NB: some callers cheat and supply 0 when they know
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000416 * that there is no timestamp, short-cutting the test. */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000417static void timestamp_and_log(int pri, char *msg, int len)
418{
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000419 char *timestamp;
420
421 if (len < 16 || msg[3] != ' ' || msg[6] != ' '
422 || msg[9] != ':' || msg[12] != ':' || msg[15] != ' '
423 ) {
Denis Vlasenkobae79482007-01-09 23:42:43 +0000424 time_t now;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000425 time(&now);
426 timestamp = ctime(&now) + 4;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000427 } else {
428 timestamp = msg;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000429 msg += 16;
430 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000431 timestamp[15] = '\0';
Eric Andersen3843e961999-11-25 07:30:46 +0000432
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000433 /* Log message locally (to file or shared mem) */
434 if (!ENABLE_FEATURE_REMOTE_LOG || (option_mask32 & OPT_locallog)) {
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000435 if (LOG_PRI(pri) < G.logLevel) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000436 if (option_mask32 & OPT_small)
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000437 sprintf(G.printbuf, "%s %s\n", timestamp, msg);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000438 else {
439 char res[20];
440 parse_fac_prio_20(pri, res);
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000441 sprintf(G.printbuf, "%s %s %s %s\n", timestamp, G.localHostName, res, msg);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000442 }
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000443 log_locally(G.printbuf);
Eric Andersenbf2b8ae2000-12-08 19:52:01 +0000444 }
445 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000446}
Glenn L McGrath73ebb882004-09-14 18:12:13 +0000447
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000448static void split_escape_and_log(char *tmpbuf, int len)
449{
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000450 char *p = tmpbuf;
451
452 tmpbuf += len;
453 while (p < tmpbuf) {
454 char c;
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000455 char *q = G.parsebuf;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000456 int pri = (LOG_USER | LOG_NOTICE);
457
458 if (*p == '<') {
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000459 /* Parse the magic priority number */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000460 pri = bb_strtou(p + 1, &p, 10);
461 if (*p == '>') p++;
462 if (pri & ~(LOG_FACMASK | LOG_PRIMASK)) {
463 pri = (LOG_USER | LOG_NOTICE);
464 }
Denis Vlasenko1decd0e2006-09-30 19:17:40 +0000465 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000466
467 while ((c = *p++)) {
468 if (c == '\n')
469 c = ' ';
470 if (!(c & ~0x1f)) {
471 *q++ = '^';
472 c += '@'; /* ^@, ^A, ^B... */
473 }
474 *q++ = c;
475 }
476 *q = '\0';
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000477 /* Now log it */
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000478 timestamp_and_log(pri, G.parsebuf, q - G.parsebuf);
Eric Andersen7f94a5c2004-06-22 10:12:59 +0000479 }
Eric Andersen3843e961999-11-25 07:30:46 +0000480}
481
482static void quit_signal(int sig)
483{
Denis Vlasenkoab2aea42007-01-29 22:51:58 +0000484 timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"syslogd exiting", 0);
Denis Vlasenko1c962f22007-01-09 23:44:57 +0000485 puts("syslogd exiting");
Bernhard Reutner-Fischerd591a362006-08-20 17:35:13 +0000486 if (ENABLE_FEATURE_IPC_SYSLOG)
487 ipcsyslog_cleanup();
Denis Vlasenko02be0f52006-09-30 19:21:24 +0000488 exit(1);
Eric Andersen3843e961999-11-25 07:30:46 +0000489}
490
Denis Vlasenko4998c812007-02-14 20:51:46 +0000491#ifdef SYSLOGD_MARK
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000492static void do_mark(int sig)
Eric Andersen3843e961999-11-25 07:30:46 +0000493{
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000494 if (G.markInterval) {
Denis Vlasenkoab2aea42007-01-29 22:51:58 +0000495 timestamp_and_log(LOG_SYSLOG | LOG_INFO, (char*)"-- MARK --", 0);
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000496 alarm(G.markInterval);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000497 }
Eric Andersen3843e961999-11-25 07:30:46 +0000498}
Denis Vlasenko4998c812007-02-14 20:51:46 +0000499#endif
Eric Andersen3843e961999-11-25 07:30:46 +0000500
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000501static void do_syslogd(void) ATTRIBUTE_NORETURN;
502static void do_syslogd(void)
Eric Andersen3843e961999-11-25 07:30:46 +0000503{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000504 struct sockaddr_un sunx;
Erik Andersen983b51b2000-04-04 18:14:25 +0000505 int sock_fd;
Erik Andersenf13df372000-04-18 23:51:51 +0000506 fd_set fds;
Denis Vlasenko6ca04442007-02-11 16:19:28 +0000507 char *dev_log_name;
Erik Andersenf13df372000-04-18 23:51:51 +0000508
Denis Vlasenko8a820b22007-01-06 22:08:53 +0000509 /* Set up signal handlers */
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000510 signal(SIGINT, quit_signal);
511 signal(SIGTERM, quit_signal);
512 signal(SIGQUIT, quit_signal);
513 signal(SIGHUP, SIG_IGN);
514 signal(SIGCHLD, SIG_IGN);
Pavel Roskind39d1202000-09-13 14:14:29 +0000515#ifdef SIGCLD
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000516 signal(SIGCLD, SIG_IGN);
Pavel Roskind39d1202000-09-13 14:14:29 +0000517#endif
Denis Vlasenko4998c812007-02-14 20:51:46 +0000518#ifdef SYSLOGD_MARK
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000519 signal(SIGALRM, do_mark);
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000520 alarm(G.markInterval);
Denis Vlasenko4998c812007-02-14 20:51:46 +0000521#endif
Denis Vlasenko10457b92007-03-27 22:01:31 +0000522 remove_pidfile("/var/run/syslogd.pid");
Eric Andersenb99df0f1999-11-24 09:04:33 +0000523
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000524 memset(&sunx, 0, sizeof(sunx));
Erik Andersen983b51b2000-04-04 18:14:25 +0000525 sunx.sun_family = AF_UNIX;
Denis Vlasenko6ca04442007-02-11 16:19:28 +0000526 strcpy(sunx.sun_path, "/dev/log");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000527
Denis Vlasenko6ca04442007-02-11 16:19:28 +0000528 /* Unlink old /dev/log or object it points to. */
529 /* (if it exists, bind will fail) */
530 logmode = LOGMODE_NONE;
531 dev_log_name = xmalloc_readlink_or_warn("/dev/log");
532 logmode = LOGMODE_STDIO;
533 if (dev_log_name) {
534 int fd = xopen(".", O_NONBLOCK);
535 xchdir("/dev");
536 /* we do not check whether this is a link also */
537 unlink(dev_log_name);
538 fchdir(fd);
539 close(fd);
540 safe_strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path));
541 free(dev_log_name);
542 } else {
543 unlink("/dev/log");
544 }
545
546 sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
547 xbind(sock_fd, (struct sockaddr *) &sunx, sizeof(sunx));
548
549 if (chmod("/dev/log", 0666) < 0) {
550 bb_perror_msg_and_die("cannot set permission on /dev/log");
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000551 }
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000552 if (ENABLE_FEATURE_IPC_SYSLOG && (option_mask32 & OPT_circularlog)) {
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000553 ipcsyslog_init();
Eric Andersenea906502001-04-05 20:55:17 +0000554 }
Eric Andersenea906502001-04-05 20:55:17 +0000555
Denis Vlasenkoab2aea42007-01-29 22:51:58 +0000556 timestamp_and_log(LOG_SYSLOG | LOG_INFO,
557 (char*)"syslogd started: BusyBox v" BB_VER, 0);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000558
Erik Andersen983b51b2000-04-04 18:14:25 +0000559 for (;;) {
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000560 FD_ZERO(&fds);
561 FD_SET(sock_fd, &fds);
Erik Andersenf13df372000-04-18 23:51:51 +0000562
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000563 if (select(sock_fd + 1, &fds, NULL, NULL, NULL) < 0) {
Eric Andersen871d93c2002-09-17 20:06:29 +0000564 if (errno == EINTR) {
Denis Vlasenko8a820b22007-01-06 22:08:53 +0000565 /* alarm may have happened */
Eric Andersen871d93c2002-09-17 20:06:29 +0000566 continue;
567 }
Denis Vlasenko14c19402006-09-30 19:20:00 +0000568 bb_perror_msg_and_die("select");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000569 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000570
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000571 if (FD_ISSET(sock_fd, &fds)) {
572 int i;
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000573 i = recv(sock_fd, G.recvbuf, MAX_READ - 1, 0);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000574 if (i <= 0)
Manuel Novoa III cad53642003-03-19 09:13:01 +0000575 bb_perror_msg_and_die("UNIX socket error");
Denis Vlasenkoa0e2a0a2007-01-04 21:22:11 +0000576 /* TODO: maybe suppress duplicates? */
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000577#if ENABLE_FEATURE_REMOTE_LOG
578 /* We are not modifying log messages in any way before send */
579 /* Remote site cannot trust _us_ anyway and need to do validation again */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000580 if (G.remoteAddr) {
581 if (-1 == G.remoteFD) {
582 G.remoteFD = socket(G.remoteAddr->sa.sa_family, SOCK_DGRAM, 0);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000583 }
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000584 if (-1 != G.remoteFD) {
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000585 /* send message to remote logger, ignore possible error */
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000586 sendto(G.remoteFD, G.recvbuf, i, MSG_DONTWAIT,
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000587 &G.remoteAddr->sa, G.remoteAddr->len);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000588 }
Glenn L McGrath912d8f42002-11-10 22:46:45 +0000589 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000590#endif
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000591 G.recvbuf[i] = '\0';
592 split_escape_and_log(G.recvbuf, i);
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000593 } /* FD_ISSET() */
594 } /* for */
Eric Andersenb99df0f1999-11-24 09:04:33 +0000595}
596
Denis Vlasenko06af2162007-02-03 17:28:39 +0000597int syslogd_main(int argc, char **argv);
Rob Landleydfba7412006-03-06 20:47:33 +0000598int syslogd_main(int argc, char **argv)
Eric Andersen3843e961999-11-25 07:30:46 +0000599{
Denis Vlasenko14c19402006-09-30 19:20:00 +0000600 char OPTION_DECL;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000601 char *p;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000602
Denis Vlasenko4f93cde2007-03-20 20:03:03 +0000603 PTR_TO_GLOBALS = memcpy(xzalloc(sizeof(G)), &init_data, sizeof(init_data));
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000604
Eric Andersen394cf222000-12-11 16:48:50 +0000605 /* do normal option parsing */
Denis Vlasenkoa9b60e92007-01-04 17:59:59 +0000606 opt_complementary = "=0"; /* no non-option params */
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000607 getopt32(argc, argv, OPTION_STR, OPTION_PARAM);
Denis Vlasenko4998c812007-02-14 20:51:46 +0000608#ifdef SYSLOGD_MARK
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000609 if (option_mask32 & OPT_mark) // -m
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000610 G.markInterval = xatou_range(opt_m, 0, INT_MAX/60) * 60;
Denis Vlasenko4998c812007-02-14 20:51:46 +0000611#endif
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000612 //if (option_mask32 & OPT_nofork) // -n
613 //if (option_mask32 & OPT_outfile) // -O
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000614 if (option_mask32 & OPT_loglevel) // -l
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000615 G.logLevel = xatou_range(opt_l, 1, 8);
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000616 //if (option_mask32 & OPT_small) // -S
Denis Vlasenko14c19402006-09-30 19:20:00 +0000617#if ENABLE_FEATURE_ROTATE_LOGFILE
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000618 if (option_mask32 & OPT_filesize) // -s
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000619 G.logFileSize = xatou_range(opt_s, 0, INT_MAX/1024) * 1024;
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000620 if (option_mask32 & OPT_rotatecnt) // -b
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000621 G.logFileRotate = xatou_range(opt_b, 0, 99);
Denis Vlasenko14c19402006-09-30 19:20:00 +0000622#endif
623#if ENABLE_FEATURE_REMOTE_LOG
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000624 if (option_mask32 & OPT_remotelog) { // -R
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000625 G.remoteAddr = xhost2sockaddr(opt_R, 514);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000626 }
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000627 //if (option_mask32 & OPT_locallog) // -L
Denis Vlasenko14c19402006-09-30 19:20:00 +0000628#endif
629#if ENABLE_FEATURE_IPC_SYSLOG
Denis Vlasenko218f2f42007-01-24 22:02:01 +0000630 if (opt_C) // -Cn
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000631 G.shm_size = xatoul_range(opt_C, 4, INT_MAX/1024) * 1024;
Denis Vlasenko14c19402006-09-30 19:20:00 +0000632#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000633
Eric Andersen4ed17822000-12-11 19:28:29 +0000634 /* If they have not specified remote logging, then log locally */
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000635 if (ENABLE_FEATURE_REMOTE_LOG && !(option_mask32 & OPT_remotelog))
636 option_mask32 |= OPT_locallog;
Mark Whitley6317c4b2001-03-12 22:51:50 +0000637
Erik Andersene49d5ec2000-02-08 19:58:47 +0000638 /* Store away localhost's name before the fork */
Denis Vlasenko5e892ba2007-03-15 19:50:46 +0000639 gethostname(G.localHostName, sizeof(G.localHostName));
640 p = strchr(G.localHostName, '.');
Denis Vlasenko14c19402006-09-30 19:20:00 +0000641 if (p) {
Glenn L McGrathfe538ba2003-09-10 23:35:45 +0000642 *p = '\0';
Erik Andersene49d5ec2000-02-08 19:58:47 +0000643 }
644
Denis Vlasenkoc12f5302006-10-06 09:49:47 +0000645 if (!(option_mask32 & OPT_nofork)) {
Denis Vlasenko5a142022007-03-26 13:20:54 +0000646 bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
Eric Andersen35e643b2003-07-28 07:40:39 +0000647 }
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000648 umask(0);
Denis Vlasenko10457b92007-03-27 22:01:31 +0000649 write_pidfile("/var/run/syslogd.pid");
Denis Vlasenkoceab8702007-01-04 17:57:54 +0000650 do_syslogd();
Denis Vlasenko8a820b22007-01-06 22:08:53 +0000651 /* return EXIT_SUCCESS; */
Eric Andersen3843e961999-11-25 07:30:46 +0000652}