blob: 004e6ab1d452bc7c3da02a320d17ee9d98c3ddd0 [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 *
Erik Andersen61677fe2000-04-13 01:18:56 +00005 * Copyright (C) 1999,2000 by Lineo, inc.
Eric Andersen3843e961999-11-25 07:30:46 +00006 * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
7 *
Erik Andersenf13df372000-04-18 23:51:51 +00008 * Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
9 *
Eric Andersen3843e961999-11-25 07:30:46 +000010 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
Eric Andersenb99df0f1999-11-24 09:04:33 +000025
Eric Andersen3843e961999-11-25 07:30:46 +000026#include "internal.h"
Eric Andersen3843e961999-11-25 07:30:46 +000027#include <ctype.h>
Eric Andersenb186d981999-12-03 09:19:54 +000028#include <errno.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000029#include <fcntl.h>
30#include <netdb.h>
Eric Andersenb186d981999-12-03 09:19:54 +000031#include <paths.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000032#include <signal.h>
33#include <stdarg.h>
34#include <stdio.h>
35#include <sys/klog.h>
36#include <sys/socket.h>
37#include <sys/stat.h>
38#include <sys/types.h>
39#include <sys/un.h>
40#include <time.h>
41#include <unistd.h>
Eric Andersenb186d981999-12-03 09:19:54 +000042
43#define ksyslog klogctl
44extern int ksyslog(int type, char *buf, int len);
Eric Andersenb99df0f1999-11-24 09:04:33 +000045
46
Eric Andersen3843e961999-11-25 07:30:46 +000047/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
48#define SYSLOG_NAMES
49#include <sys/syslog.h>
50
51/* Path for the file where all log messages are written */
Erik Andersen983b51b2000-04-04 18:14:25 +000052#define __LOG_FILE "/var/log/messages"
Eric Andersen3843e961999-11-25 07:30:46 +000053
Erik Andersen983b51b2000-04-04 18:14:25 +000054/* Path to the unix socket */
55char lfile[PATH_MAX] = "";
Eric Andersen3843e961999-11-25 07:30:46 +000056
Erik Andersene49d5ec2000-02-08 19:58:47 +000057static char *logFilePath = __LOG_FILE;
58
Eric Andersen3843e961999-11-25 07:30:46 +000059/* interval between marks in seconds */
Erik Andersene49d5ec2000-02-08 19:58:47 +000060static int MarkInterval = 20 * 60;
61
Eric Andersen3843e961999-11-25 07:30:46 +000062/* localhost's name */
63static char LocalHostName[32];
64
65static const char syslogd_usage[] =
Erik Andersene49d5ec2000-02-08 19:58:47 +000066 "syslogd [OPTION]...\n\n"
67 "Linux system and kernel (provides klogd) logging utility.\n"
68 "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n"
69 "Options:\n"
70 "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n"
71 "\t-n\tDo not fork into the background (for when run by init)\n"
Eric Andersen2cb55071999-12-10 08:25:07 +000072#ifdef BB_KLOGD
Erik Andersene49d5ec2000-02-08 19:58:47 +000073 "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n"
Eric Andersen2cb55071999-12-10 08:25:07 +000074#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +000075 "\t-O\tSpecify an alternate log file. default=/var/log/messages\n";
Eric Andersen3843e961999-11-25 07:30:46 +000076
Erik Andersenc053e412000-03-21 01:31:24 +000077/* Note: There is also a function called "message()" in init.c */
Erik Andersen983b51b2000-04-04 18:14:25 +000078/* Print a message to the log file. */
Erik Andersenf13df372000-04-18 23:51:51 +000079static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
80static void message (char *fmt, ...)
Eric Andersen3843e961999-11-25 07:30:46 +000081{
Erik Andersene49d5ec2000-02-08 19:58:47 +000082 int fd;
Erik Andersene3ed1562000-04-19 18:52:56 +000083 struct flock fl;
Erik Andersene49d5ec2000-02-08 19:58:47 +000084 va_list arguments;
Eric Andersen3843e961999-11-25 07:30:46 +000085
Erik Andersene3ed1562000-04-19 18:52:56 +000086 fl.l_whence = SEEK_SET;
87 fl.l_start = 0;
88 fl.l_len = 1;
89
Erik Andersenf13df372000-04-18 23:51:51 +000090 if ((fd = device_open (logFilePath,
91 O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND |
92 O_NONBLOCK)) >= 0) {
Erik Andersene3ed1562000-04-19 18:52:56 +000093 fl.l_type = F_WRLCK;
94 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +000095 va_start (arguments, fmt);
96 vdprintf (fd, fmt, arguments);
97 va_end (arguments);
Erik Andersene3ed1562000-04-19 18:52:56 +000098 fl.l_type = F_UNLCK;
99 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +0000100 close (fd);
Eric Andersen3843e961999-11-25 07:30:46 +0000101 } else {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000102 /* Always send console messages to /dev/console so people will see them. */
Erik Andersenf13df372000-04-18 23:51:51 +0000103 if ((fd = device_open (_PATH_CONSOLE,
104 O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) {
105 va_start (arguments, fmt);
106 vdprintf (fd, fmt, arguments);
107 va_end (arguments);
108 close (fd);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000109 } else {
Erik Andersenf13df372000-04-18 23:51:51 +0000110 fprintf (stderr, "Bummer, can't print: ");
111 va_start (arguments, fmt);
112 vfprintf (stderr, fmt, arguments);
113 fflush (stderr);
114 va_end (arguments);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000115 }
Eric Andersen3843e961999-11-25 07:30:46 +0000116 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000117}
118
Erik Andersenf13df372000-04-18 23:51:51 +0000119static void logMessage (int pri, char *msg)
Eric Andersen3843e961999-11-25 07:30:46 +0000120{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000121 time_t now;
122 char *timestamp;
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000123 static char res[20] = "";
Erik Andersene49d5ec2000-02-08 19:58:47 +0000124 CODE *c_pri, *c_fac;
Eric Andersenb99df0f1999-11-24 09:04:33 +0000125
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000126 if (pri != 0) {
127 for (c_fac = facilitynames;
128 c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++);
129 for (c_pri = prioritynames;
130 c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++);
131 if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0')
132 snprintf(res, sizeof(res), "<%d>", pri);
133 else
134 snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name);
135 }
Eric Andersen3843e961999-11-25 07:30:46 +0000136
Erik Andersene49d5ec2000-02-08 19:58:47 +0000137 if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' ||
138 msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') {
139 time(&now);
140 timestamp = ctime(&now) + 4;
141 timestamp[15] = '\0';
142 } else {
143 timestamp = msg;
144 timestamp[15] = '\0';
145 msg += 16;
146 }
Eric Andersen3843e961999-11-25 07:30:46 +0000147
Erik Andersene49d5ec2000-02-08 19:58:47 +0000148 /* todo: supress duplicates */
Eric Andersen3843e961999-11-25 07:30:46 +0000149
Erik Andersene49d5ec2000-02-08 19:58:47 +0000150 /* now spew out the message to wherever it is supposed to go */
151 message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
Eric Andersen3843e961999-11-25 07:30:46 +0000152}
153
154static void quit_signal(int sig)
155{
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000156 logMessage(0, "System log daemon exiting.");
Erik Andersen983b51b2000-04-04 18:14:25 +0000157 unlink(lfile);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000158 exit(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000159}
160
Eric Andersen3843e961999-11-25 07:30:46 +0000161static void domark(int sig)
162{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000163 if (MarkInterval > 0) {
164 logMessage(LOG_SYSLOG | LOG_INFO, "-- MARK --");
165 alarm(MarkInterval);
166 }
Eric Andersen3843e961999-11-25 07:30:46 +0000167}
168
Erik Andersen983b51b2000-04-04 18:14:25 +0000169static void doSyslogd (void) __attribute__ ((noreturn));
170static void doSyslogd (void)
Eric Andersen3843e961999-11-25 07:30:46 +0000171{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000172 struct sockaddr_un sunx;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000173 size_t addrLength;
Erik Andersenf13df372000-04-18 23:51:51 +0000174
Erik Andersen983b51b2000-04-04 18:14:25 +0000175 int sock_fd;
Erik Andersenf13df372000-04-18 23:51:51 +0000176 fd_set fds;
177
Erik Andersen983b51b2000-04-04 18:14:25 +0000178 char lfile[PATH_MAX];
Eric Andersenb99df0f1999-11-24 09:04:33 +0000179
Erik Andersenf13df372000-04-18 23:51:51 +0000180 /* Set up signal handlers. */
Erik Andersen983b51b2000-04-04 18:14:25 +0000181 signal (SIGINT, quit_signal);
182 signal (SIGTERM, quit_signal);
183 signal (SIGQUIT, quit_signal);
184 signal (SIGHUP, SIG_IGN);
Erik Andersene3ed1562000-04-19 18:52:56 +0000185 signal (SIGCLD, SIG_IGN);
Erik Andersen983b51b2000-04-04 18:14:25 +0000186 signal (SIGALRM, domark);
187 alarm (MarkInterval);
Eric Andersenb99df0f1999-11-24 09:04:33 +0000188
Erik Andersenf13df372000-04-18 23:51:51 +0000189 /* Create the syslog file so realpath() can work. */
190 close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
191 if (realpath (_PATH_LOG, lfile) == NULL)
192 fatalError ("Could not resolv path to " _PATH_LOG ": %s", strerror (errno));
Eric Andersen14ec6cf1999-12-05 22:17:02 +0000193
Erik Andersen983b51b2000-04-04 18:14:25 +0000194 unlink (lfile);
195
Erik Andersenf13df372000-04-18 23:51:51 +0000196 memset (&sunx, 0, sizeof (sunx));
Erik Andersen983b51b2000-04-04 18:14:25 +0000197 sunx.sun_family = AF_UNIX;
Erik Andersenf13df372000-04-18 23:51:51 +0000198 strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
199 if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
200 fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s", strerror (errno));
Eric Andersenb99df0f1999-11-24 09:04:33 +0000201
Erik Andersen983b51b2000-04-04 18:14:25 +0000202 addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
Erik Andersenf13df372000-04-18 23:51:51 +0000203 if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
204 fatalError ("Could not connect to socket " _PATH_LOG ": %s", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000205
Erik Andersenf13df372000-04-18 23:51:51 +0000206 if (chmod (lfile, 0666) < 0)
207 fatalError ("Could not set permission on " _PATH_LOG ": %s", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000208
Erik Andersenf13df372000-04-18 23:51:51 +0000209 FD_ZERO (&fds);
210 FD_SET (sock_fd, &fds);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000211
Erik Andersen983b51b2000-04-04 18:14:25 +0000212 logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000213
Erik Andersen983b51b2000-04-04 18:14:25 +0000214 for (;;) {
Erik Andersenf13df372000-04-18 23:51:51 +0000215
216 fd_set readfds;
217 int n_ready;
218 int fd;
219
220 memcpy (&readfds, &fds, sizeof (fds));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000221
Erik Andersen983b51b2000-04-04 18:14:25 +0000222 if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
223 if (errno == EINTR) continue; /* alarm may have happened. */
Erik Andersenf13df372000-04-18 23:51:51 +0000224 fatalError ("select error: %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000225 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000226
Erik Andersenf13df372000-04-18 23:51:51 +0000227 for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000228 if (FD_ISSET (fd, &readfds)) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000229
Erik Andersenf13df372000-04-18 23:51:51 +0000230 --n_ready;
Erik Andersene3ed1562000-04-19 18:52:56 +0000231
Erik Andersen983b51b2000-04-04 18:14:25 +0000232 if (fd == sock_fd) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000233
234 int conn;
235 pid_t pid;
236
Erik Andersenf13df372000-04-18 23:51:51 +0000237 if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) {
238 fatalError ("accept error: %s\n", strerror (errno));
Erik Andersen983b51b2000-04-04 18:14:25 +0000239 }
Erik Andersena6c75222000-04-18 00:00:52 +0000240
Erik Andersene3ed1562000-04-19 18:52:56 +0000241 pid = fork();
Erik Andersen983b51b2000-04-04 18:14:25 +0000242
Erik Andersene3ed1562000-04-19 18:52:56 +0000243 if (pid < 0) {
244 perror ("syslogd: fork");
245 close (conn);
246 continue;
Erik Andersen983b51b2000-04-04 18:14:25 +0000247 }
Erik Andersene3ed1562000-04-19 18:52:56 +0000248
249 if (pid > 0) {
250
251# define BUFSIZE 1023
252 char buf[ BUFSIZE + 1 ];
253 int n_read;
254
255 while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
256
257 int pri = (LOG_USER | LOG_NOTICE);
258 char line[ BUFSIZE + 1 ];
259 unsigned char c;
260
261 char *p = buf, *q = line;
262
263 buf[ n_read - 1 ] = '\0';
264
265 while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
266 if (c == '<') {
267 /* Parse the magic priority number. */
268 pri = 0;
269 while (isdigit (*(++p))) {
270 pri = 10 * pri + (*p - '0');
271 }
272 if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
273 pri = (LOG_USER | LOG_NOTICE);
274 } else if (c == '\n') {
275 *q++ = ' ';
276 } else if (iscntrl (c) && (c < 0177)) {
277 *q++ = '^';
278 *q++ = c ^ 0100;
279 } else {
280 *q++ = c;
281 }
282 p++;
283 }
284 *q = '\0';
285 /* Now log it */
286 logMessage (pri, line);
287 }
288 exit (0);
289 }
290 close (conn);
Erik Andersen983b51b2000-04-04 18:14:25 +0000291 }
292 }
293 }
294 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000295}
296
Eric Andersen2cb55071999-12-10 08:25:07 +0000297#ifdef BB_KLOGD
298
Eric Andersenb186d981999-12-03 09:19:54 +0000299static void klogd_signal(int sig)
300{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000301 ksyslog(7, NULL, 0);
302 ksyslog(0, 0, 0);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000303 logMessage(0, "Kernel log daemon exiting.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000304 exit(TRUE);
Eric Andersenb186d981999-12-03 09:19:54 +0000305}
306
Erik Andersen983b51b2000-04-04 18:14:25 +0000307static void doKlogd (void) __attribute__ ((noreturn));
308static void doKlogd (void)
Eric Andersenb186d981999-12-03 09:19:54 +0000309{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000310 int priority = LOG_INFO;
311 char log_buffer[4096];
312 char *logp;
Eric Andersenb186d981999-12-03 09:19:54 +0000313
Erik Andersene49d5ec2000-02-08 19:58:47 +0000314 /* Set up sig handlers */
315 signal(SIGINT, klogd_signal);
316 signal(SIGKILL, klogd_signal);
317 signal(SIGTERM, klogd_signal);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000318 signal(SIGHUP, SIG_IGN);
319 logMessage(0, "klogd started: "
Erik Andersene49d5ec2000-02-08 19:58:47 +0000320 "BusyBox v" BB_VER " (" BB_BT ")");
Eric Andersenb186d981999-12-03 09:19:54 +0000321
Erik Andersene49d5ec2000-02-08 19:58:47 +0000322 ksyslog(1, NULL, 0);
Eric Andersen0ecb54a1999-12-05 23:24:55 +0000323
Erik Andersene49d5ec2000-02-08 19:58:47 +0000324 while (1) {
325 /* Use kernel syscalls */
326 memset(log_buffer, '\0', sizeof(log_buffer));
327 if (ksyslog(2, log_buffer, sizeof(log_buffer)) < 0) {
328 char message[80];
329
330 if (errno == EINTR)
331 continue;
332 snprintf(message, 79, "klogd: Error return from sys_sycall: " \
333 "%d - %s.\n", errno, strerror(errno));
334 logMessage(LOG_SYSLOG | LOG_ERR, message);
335 exit(1);
336 }
337 logp = log_buffer;
338 if (*log_buffer == '<') {
339 switch (*(log_buffer + 1)) {
340 case '0':
341 priority = LOG_EMERG;
342 break;
343 case '1':
344 priority = LOG_ALERT;
345 break;
346 case '2':
347 priority = LOG_CRIT;
348 break;
349 case '3':
350 priority = LOG_ERR;
351 break;
352 case '4':
353 priority = LOG_WARNING;
354 break;
355 case '5':
356 priority = LOG_NOTICE;
357 break;
358 case '6':
359 priority = LOG_INFO;
360 break;
361 case '7':
362 default:
363 priority = LOG_DEBUG;
364 }
365 logp += 3;
366 }
367 logMessage(LOG_KERN | priority, logp);
Eric Andersenb186d981999-12-03 09:19:54 +0000368 }
Eric Andersenb186d981999-12-03 09:19:54 +0000369
370}
371
Eric Andersen2cb55071999-12-10 08:25:07 +0000372#endif
Eric Andersenb99df0f1999-11-24 09:04:33 +0000373
Erik Andersen983b51b2000-04-04 18:14:25 +0000374static void daemon_init (char **argv, char *dz, void fn (void))
375{
376 setsid();
377 chdir ("/");
378 strncpy(argv[0], dz, strlen(argv[0]));
379 fn();
380 exit(0);
381}
382
Eric Andersen3843e961999-11-25 07:30:46 +0000383extern int syslogd_main(int argc, char **argv)
384{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000385 int pid, klogd_pid;
386 int doFork = TRUE;
387
Eric Andersen2cb55071999-12-10 08:25:07 +0000388#ifdef BB_KLOGD
Erik Andersene49d5ec2000-02-08 19:58:47 +0000389 int startKlogd = TRUE;
Eric Andersen2cb55071999-12-10 08:25:07 +0000390#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000391 int stopDoingThat = FALSE;
392 char *p;
393 char **argv1 = argv;
394
395 while (--argc > 0 && **(++argv1) == '-') {
396 stopDoingThat = FALSE;
397 while (stopDoingThat == FALSE && *(++(*argv1))) {
398 switch (**argv1) {
399 case 'm':
400 if (--argc == 0) {
401 usage(syslogd_usage);
402 }
403 MarkInterval = atoi(*(++argv1)) * 60;
404 break;
405 case 'n':
406 doFork = FALSE;
407 break;
408#ifdef BB_KLOGD
409 case 'K':
410 startKlogd = FALSE;
411 break;
412#endif
413 case 'O':
414 if (--argc == 0) {
415 usage(syslogd_usage);
416 }
417 logFilePath = *(++argv1);
418 stopDoingThat = TRUE;
419 break;
420 default:
421 usage(syslogd_usage);
422 }
Eric Andersen3843e961999-11-25 07:30:46 +0000423 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000424 }
425
426 /* Store away localhost's name before the fork */
427 gethostname(LocalHostName, sizeof(LocalHostName));
428 if ((p = strchr(LocalHostName, '.'))) {
429 *p++ = '\0';
430 }
431
Erik Andersen983b51b2000-04-04 18:14:25 +0000432 umask(0);
433
Erik Andersene2729152000-02-18 21:34:17 +0000434#ifdef BB_KLOGD
435 /* Start up the klogd process */
436 if (startKlogd == TRUE) {
437 klogd_pid = fork();
438 if (klogd_pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000439 daemon_init (argv, "klogd", doKlogd);
Erik Andersene2729152000-02-18 21:34:17 +0000440 }
441 }
442#endif
443
Erik Andersene49d5ec2000-02-08 19:58:47 +0000444 if (doFork == TRUE) {
445 pid = fork();
446 if (pid < 0)
447 exit(pid);
448 else if (pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000449 daemon_init (argv, "syslogd", doSyslogd);
Eric Andersen3843e961999-11-25 07:30:46 +0000450 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000451 } else {
452 doSyslogd();
Eric Andersen3843e961999-11-25 07:30:46 +0000453 }
Eric Andersenb186d981999-12-03 09:19:54 +0000454
Erik Andersene49d5ec2000-02-08 19:58:47 +0000455 exit(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000456}
Erik Andersen983b51b2000-04-04 18:14:25 +0000457
458/*
Erik Andersene3ed1562000-04-19 18:52:56 +0000459Local Variables
460c-file-style: "linux"
461c-basic-offset: 4
462tab-width: 4
463End:
464*/