blob: d2fbc3d876eb8ce3e7759903ce497614b5f41361 [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 Andersen67e32302000-06-19 17:48:02 +000027#include <stdio.h>
28#include <stdlib.h>
Eric Andersen3843e961999-11-25 07:30:46 +000029#include <ctype.h>
Eric Andersenb186d981999-12-03 09:19:54 +000030#include <errno.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000031#include <fcntl.h>
32#include <netdb.h>
Eric Andersenb186d981999-12-03 09:19:54 +000033#include <paths.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000034#include <signal.h>
35#include <stdarg.h>
Eric Andersen67e32302000-06-19 17:48:02 +000036#include <time.h>
37#include <unistd.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000038#include <sys/socket.h>
39#include <sys/stat.h>
40#include <sys/types.h>
41#include <sys/un.h>
Erik Andersen7d6ba572000-04-19 20:02:50 +000042#include <sys/param.h>
Eric Andersen67e32302000-06-19 17:48:02 +000043#include <linux/unistd.h>
Eric Andersenb186d981999-12-03 09:19:54 +000044
Eric Andersen67e32302000-06-19 17:48:02 +000045#ifndef socklen_t
46typedef unsigned int socklen_t;
47#endif
48
49#if __GNU_LIBRARY__ < 5
50
51#ifndef __alpha__
52# define __NR_klogctl __NR_syslog
53static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
54#else /* __alpha__ */
55#define klogctl syslog
56#endif
57
58#else
59# include <sys/klog.h>
60#endif
61
Eric Andersenb99df0f1999-11-24 09:04:33 +000062
63
Eric Andersen3843e961999-11-25 07:30:46 +000064/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
65#define SYSLOG_NAMES
66#include <sys/syslog.h>
67
68/* Path for the file where all log messages are written */
Erik Andersen983b51b2000-04-04 18:14:25 +000069#define __LOG_FILE "/var/log/messages"
Eric Andersen3843e961999-11-25 07:30:46 +000070
Erik Andersen983b51b2000-04-04 18:14:25 +000071/* Path to the unix socket */
Erik Andersen4f3f7572000-04-28 00:18:56 +000072char lfile[BUFSIZ] = "";
Eric Andersen3843e961999-11-25 07:30:46 +000073
Erik Andersene49d5ec2000-02-08 19:58:47 +000074static char *logFilePath = __LOG_FILE;
75
Eric Andersen3843e961999-11-25 07:30:46 +000076/* interval between marks in seconds */
Erik Andersene49d5ec2000-02-08 19:58:47 +000077static int MarkInterval = 20 * 60;
78
Eric Andersen3843e961999-11-25 07:30:46 +000079/* localhost's name */
80static char LocalHostName[32];
81
82static const char syslogd_usage[] =
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000083 "syslogd [OPTION]...\n"
84#ifndef BB_FEATURE_TRIVIAL_HELP
85 "\nLinux system and kernel (provides klogd) logging utility.\n"
Erik Andersene49d5ec2000-02-08 19:58:47 +000086 "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n"
87 "Options:\n"
Pavel Roskinda10ec02000-06-07 21:08:25 +000088 "\t-m NUM\t\tInterval between MARK lines (default=20min, 0=off)\n"
89 "\t-n\t\tRun as a foreground process\n"
Eric Andersen2cb55071999-12-10 08:25:07 +000090#ifdef BB_KLOGD
Pavel Roskinda10ec02000-06-07 21:08:25 +000091 "\t-K\t\tDo not start up the klogd process\n"
Eric Andersen2cb55071999-12-10 08:25:07 +000092#endif
Pavel Roskinda10ec02000-06-07 21:08:25 +000093 "\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n"
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000094#endif
95 ;
Eric Andersen3843e961999-11-25 07:30:46 +000096
Erik Andersenc053e412000-03-21 01:31:24 +000097/* Note: There is also a function called "message()" in init.c */
Erik Andersen983b51b2000-04-04 18:14:25 +000098/* Print a message to the log file. */
Erik Andersenf13df372000-04-18 23:51:51 +000099static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
100static void message (char *fmt, ...)
Eric Andersen3843e961999-11-25 07:30:46 +0000101{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000102 int fd;
Erik Andersene3ed1562000-04-19 18:52:56 +0000103 struct flock fl;
Erik Andersene49d5ec2000-02-08 19:58:47 +0000104 va_list arguments;
Eric Andersen3843e961999-11-25 07:30:46 +0000105
Erik Andersene3ed1562000-04-19 18:52:56 +0000106 fl.l_whence = SEEK_SET;
107 fl.l_start = 0;
108 fl.l_len = 1;
109
Erik Andersenf13df372000-04-18 23:51:51 +0000110 if ((fd = device_open (logFilePath,
111 O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND |
112 O_NONBLOCK)) >= 0) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000113 fl.l_type = F_WRLCK;
114 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +0000115 va_start (arguments, fmt);
116 vdprintf (fd, fmt, arguments);
117 va_end (arguments);
Erik Andersene3ed1562000-04-19 18:52:56 +0000118 fl.l_type = F_UNLCK;
119 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +0000120 close (fd);
Eric Andersen3843e961999-11-25 07:30:46 +0000121 } else {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000122 /* Always send console messages to /dev/console so people will see them. */
Erik Andersenf13df372000-04-18 23:51:51 +0000123 if ((fd = device_open (_PATH_CONSOLE,
124 O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) {
125 va_start (arguments, fmt);
126 vdprintf (fd, fmt, arguments);
127 va_end (arguments);
128 close (fd);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000129 } else {
Erik Andersenf13df372000-04-18 23:51:51 +0000130 fprintf (stderr, "Bummer, can't print: ");
131 va_start (arguments, fmt);
132 vfprintf (stderr, fmt, arguments);
133 fflush (stderr);
134 va_end (arguments);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000135 }
Eric Andersen3843e961999-11-25 07:30:46 +0000136 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000137}
138
Erik Andersenf13df372000-04-18 23:51:51 +0000139static void logMessage (int pri, char *msg)
Eric Andersen3843e961999-11-25 07:30:46 +0000140{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000141 time_t now;
142 char *timestamp;
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000143 static char res[20] = "";
Erik Andersene49d5ec2000-02-08 19:58:47 +0000144 CODE *c_pri, *c_fac;
Eric Andersenb99df0f1999-11-24 09:04:33 +0000145
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000146 if (pri != 0) {
147 for (c_fac = facilitynames;
148 c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++);
149 for (c_pri = prioritynames;
150 c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++);
151 if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0')
152 snprintf(res, sizeof(res), "<%d>", pri);
153 else
154 snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name);
155 }
Eric Andersen3843e961999-11-25 07:30:46 +0000156
Erik Andersene49d5ec2000-02-08 19:58:47 +0000157 if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' ||
158 msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') {
159 time(&now);
160 timestamp = ctime(&now) + 4;
161 timestamp[15] = '\0';
162 } else {
163 timestamp = msg;
164 timestamp[15] = '\0';
165 msg += 16;
166 }
Eric Andersen3843e961999-11-25 07:30:46 +0000167
Erik Andersene49d5ec2000-02-08 19:58:47 +0000168 /* todo: supress duplicates */
Eric Andersen3843e961999-11-25 07:30:46 +0000169
Erik Andersene49d5ec2000-02-08 19:58:47 +0000170 /* now spew out the message to wherever it is supposed to go */
171 message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
Eric Andersen3843e961999-11-25 07:30:46 +0000172}
173
174static void quit_signal(int sig)
175{
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000176 logMessage(0, "System log daemon exiting.");
Erik Andersen983b51b2000-04-04 18:14:25 +0000177 unlink(lfile);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000178 exit(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000179}
180
Eric Andersen3843e961999-11-25 07:30:46 +0000181static void domark(int sig)
182{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000183 if (MarkInterval > 0) {
184 logMessage(LOG_SYSLOG | LOG_INFO, "-- MARK --");
185 alarm(MarkInterval);
186 }
Eric Andersen3843e961999-11-25 07:30:46 +0000187}
188
Pavel Roskinda10ec02000-06-07 21:08:25 +0000189#define BUFSIZE 1023
Eric Andersen67e32302000-06-19 17:48:02 +0000190static int serveConnection (int conn)
Pavel Roskinda10ec02000-06-07 21:08:25 +0000191{
192 char buf[ BUFSIZE + 1 ];
193 int n_read;
194
195 while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
196
197 int pri = (LOG_USER | LOG_NOTICE);
198 char line[ BUFSIZE + 1 ];
199 unsigned char c;
200
201 char *p = buf, *q = line;
202
203 buf[ n_read - 1 ] = '\0';
204
205 while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
206 if (c == '<') {
207 /* Parse the magic priority number. */
208 pri = 0;
209 while (isdigit (*(++p))) {
210 pri = 10 * pri + (*p - '0');
211 }
212 if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
213 pri = (LOG_USER | LOG_NOTICE);
214 } else if (c == '\n') {
215 *q++ = ' ';
216 } else if (iscntrl (c) && (c < 0177)) {
217 *q++ = '^';
218 *q++ = c ^ 0100;
219 } else {
220 *q++ = c;
221 }
222 p++;
223 }
224 *q = '\0';
225 /* Now log it */
226 logMessage (pri, line);
227 }
Eric Andersen67e32302000-06-19 17:48:02 +0000228 return (0);
Pavel Roskinda10ec02000-06-07 21:08:25 +0000229}
230
Erik Andersen983b51b2000-04-04 18:14:25 +0000231static void doSyslogd (void) __attribute__ ((noreturn));
232static void doSyslogd (void)
Eric Andersen3843e961999-11-25 07:30:46 +0000233{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000234 struct sockaddr_un sunx;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000235 socklen_t addrLength;
236
Erik Andersenf13df372000-04-18 23:51:51 +0000237
Erik Andersen983b51b2000-04-04 18:14:25 +0000238 int sock_fd;
Erik Andersenf13df372000-04-18 23:51:51 +0000239 fd_set fds;
240
Erik Andersen4f3f7572000-04-28 00:18:56 +0000241 char lfile[BUFSIZ];
Eric Andersenb99df0f1999-11-24 09:04:33 +0000242
Erik Andersenf13df372000-04-18 23:51:51 +0000243 /* Set up signal handlers. */
Erik Andersen983b51b2000-04-04 18:14:25 +0000244 signal (SIGINT, quit_signal);
245 signal (SIGTERM, quit_signal);
246 signal (SIGQUIT, quit_signal);
247 signal (SIGHUP, SIG_IGN);
Erik Andersene3ed1562000-04-19 18:52:56 +0000248 signal (SIGCLD, SIG_IGN);
Erik Andersen983b51b2000-04-04 18:14:25 +0000249 signal (SIGALRM, domark);
250 alarm (MarkInterval);
Eric Andersenb99df0f1999-11-24 09:04:33 +0000251
Erik Andersenf13df372000-04-18 23:51:51 +0000252 /* Create the syslog file so realpath() can work. */
253 close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
254 if (realpath (_PATH_LOG, lfile) == NULL)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000255 fatalError ("Could not resolv path to " _PATH_LOG ": %s\n", strerror (errno));
Eric Andersen14ec6cf1999-12-05 22:17:02 +0000256
Erik Andersen983b51b2000-04-04 18:14:25 +0000257 unlink (lfile);
258
Erik Andersenf13df372000-04-18 23:51:51 +0000259 memset (&sunx, 0, sizeof (sunx));
Erik Andersen983b51b2000-04-04 18:14:25 +0000260 sunx.sun_family = AF_UNIX;
Erik Andersenf13df372000-04-18 23:51:51 +0000261 strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
262 if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000263 fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s\n", strerror (errno));
Eric Andersenb99df0f1999-11-24 09:04:33 +0000264
Erik Andersen983b51b2000-04-04 18:14:25 +0000265 addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
Erik Andersenf13df372000-04-18 23:51:51 +0000266 if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
Eric Andersen86ab8a32000-06-02 03:21:42 +0000267 fatalError ("Could not connect to socket " _PATH_LOG ": %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000268
Erik Andersenf13df372000-04-18 23:51:51 +0000269 if (chmod (lfile, 0666) < 0)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000270 fatalError ("Could not set permission on " _PATH_LOG ": %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000271
Erik Andersenf13df372000-04-18 23:51:51 +0000272 FD_ZERO (&fds);
273 FD_SET (sock_fd, &fds);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000274
Erik Andersen983b51b2000-04-04 18:14:25 +0000275 logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000276
Erik Andersen983b51b2000-04-04 18:14:25 +0000277 for (;;) {
Erik Andersenf13df372000-04-18 23:51:51 +0000278
279 fd_set readfds;
280 int n_ready;
281 int fd;
282
283 memcpy (&readfds, &fds, sizeof (fds));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000284
Erik Andersen983b51b2000-04-04 18:14:25 +0000285 if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
286 if (errno == EINTR) continue; /* alarm may have happened. */
Erik Andersenf13df372000-04-18 23:51:51 +0000287 fatalError ("select error: %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000288 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000289
Erik Andersenf13df372000-04-18 23:51:51 +0000290 for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000291 if (FD_ISSET (fd, &readfds)) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000292
Erik Andersenf13df372000-04-18 23:51:51 +0000293 --n_ready;
Erik Andersene3ed1562000-04-19 18:52:56 +0000294
Erik Andersen983b51b2000-04-04 18:14:25 +0000295 if (fd == sock_fd) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000296
297 int conn;
298 pid_t pid;
299
Erik Andersenf13df372000-04-18 23:51:51 +0000300 if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) {
301 fatalError ("accept error: %s\n", strerror (errno));
Erik Andersen983b51b2000-04-04 18:14:25 +0000302 }
Erik Andersena6c75222000-04-18 00:00:52 +0000303
Erik Andersene3ed1562000-04-19 18:52:56 +0000304 pid = fork();
Erik Andersen983b51b2000-04-04 18:14:25 +0000305
Erik Andersene3ed1562000-04-19 18:52:56 +0000306 if (pid < 0) {
307 perror ("syslogd: fork");
308 close (conn);
309 continue;
Erik Andersen983b51b2000-04-04 18:14:25 +0000310 }
Erik Andersene3ed1562000-04-19 18:52:56 +0000311
Pavel Roskinda10ec02000-06-07 21:08:25 +0000312 if (pid == 0)
313 serveConnection (conn);
Erik Andersene3ed1562000-04-19 18:52:56 +0000314 close (conn);
Erik Andersen983b51b2000-04-04 18:14:25 +0000315 }
316 }
317 }
318 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000319}
320
Eric Andersen2cb55071999-12-10 08:25:07 +0000321#ifdef BB_KLOGD
322
Eric Andersenb186d981999-12-03 09:19:54 +0000323static void klogd_signal(int sig)
324{
Eric Andersen67e32302000-06-19 17:48:02 +0000325 klogctl(7, NULL, 0);
326 klogctl(0, 0, 0);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000327 logMessage(0, "Kernel log daemon exiting.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000328 exit(TRUE);
Eric Andersenb186d981999-12-03 09:19:54 +0000329}
330
Erik Andersen983b51b2000-04-04 18:14:25 +0000331static void doKlogd (void) __attribute__ ((noreturn));
332static void doKlogd (void)
Eric Andersenb186d981999-12-03 09:19:54 +0000333{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000334 int priority = LOG_INFO;
335 char log_buffer[4096];
336 char *logp;
Eric Andersenb186d981999-12-03 09:19:54 +0000337
Erik Andersene49d5ec2000-02-08 19:58:47 +0000338 /* Set up sig handlers */
339 signal(SIGINT, klogd_signal);
340 signal(SIGKILL, klogd_signal);
341 signal(SIGTERM, klogd_signal);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000342 signal(SIGHUP, SIG_IGN);
343 logMessage(0, "klogd started: "
Erik Andersene49d5ec2000-02-08 19:58:47 +0000344 "BusyBox v" BB_VER " (" BB_BT ")");
Eric Andersenb186d981999-12-03 09:19:54 +0000345
Eric Andersen67e32302000-06-19 17:48:02 +0000346 klogctl(1, NULL, 0);
Eric Andersen0ecb54a1999-12-05 23:24:55 +0000347
Erik Andersene49d5ec2000-02-08 19:58:47 +0000348 while (1) {
349 /* Use kernel syscalls */
350 memset(log_buffer, '\0', sizeof(log_buffer));
Eric Andersen67e32302000-06-19 17:48:02 +0000351 if (klogctl(2, log_buffer, sizeof(log_buffer)) < 0) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000352 char message[80];
353
354 if (errno == EINTR)
355 continue;
356 snprintf(message, 79, "klogd: Error return from sys_sycall: " \
357 "%d - %s.\n", errno, strerror(errno));
358 logMessage(LOG_SYSLOG | LOG_ERR, message);
359 exit(1);
360 }
361 logp = log_buffer;
362 if (*log_buffer == '<') {
363 switch (*(log_buffer + 1)) {
364 case '0':
365 priority = LOG_EMERG;
366 break;
367 case '1':
368 priority = LOG_ALERT;
369 break;
370 case '2':
371 priority = LOG_CRIT;
372 break;
373 case '3':
374 priority = LOG_ERR;
375 break;
376 case '4':
377 priority = LOG_WARNING;
378 break;
379 case '5':
380 priority = LOG_NOTICE;
381 break;
382 case '6':
383 priority = LOG_INFO;
384 break;
385 case '7':
386 default:
387 priority = LOG_DEBUG;
388 }
389 logp += 3;
390 }
391 logMessage(LOG_KERN | priority, logp);
Eric Andersenb186d981999-12-03 09:19:54 +0000392 }
Eric Andersenb186d981999-12-03 09:19:54 +0000393
394}
395
Eric Andersen2cb55071999-12-10 08:25:07 +0000396#endif
Eric Andersenb99df0f1999-11-24 09:04:33 +0000397
Erik Andersen983b51b2000-04-04 18:14:25 +0000398static void daemon_init (char **argv, char *dz, void fn (void))
399{
400 setsid();
401 chdir ("/");
402 strncpy(argv[0], dz, strlen(argv[0]));
403 fn();
404 exit(0);
405}
406
Eric Andersen3843e961999-11-25 07:30:46 +0000407extern int syslogd_main(int argc, char **argv)
408{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000409 int pid, klogd_pid;
410 int doFork = TRUE;
411
Eric Andersen2cb55071999-12-10 08:25:07 +0000412#ifdef BB_KLOGD
Erik Andersene49d5ec2000-02-08 19:58:47 +0000413 int startKlogd = TRUE;
Eric Andersen2cb55071999-12-10 08:25:07 +0000414#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000415 int stopDoingThat = FALSE;
416 char *p;
417 char **argv1 = argv;
418
419 while (--argc > 0 && **(++argv1) == '-') {
420 stopDoingThat = FALSE;
421 while (stopDoingThat == FALSE && *(++(*argv1))) {
422 switch (**argv1) {
423 case 'm':
424 if (--argc == 0) {
425 usage(syslogd_usage);
426 }
427 MarkInterval = atoi(*(++argv1)) * 60;
428 break;
429 case 'n':
430 doFork = FALSE;
431 break;
432#ifdef BB_KLOGD
433 case 'K':
434 startKlogd = FALSE;
435 break;
436#endif
437 case 'O':
438 if (--argc == 0) {
439 usage(syslogd_usage);
440 }
441 logFilePath = *(++argv1);
442 stopDoingThat = TRUE;
443 break;
444 default:
445 usage(syslogd_usage);
446 }
Eric Andersen3843e961999-11-25 07:30:46 +0000447 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000448 }
449
Pavel Roskinda10ec02000-06-07 21:08:25 +0000450 if (argc > 0)
451 usage(syslogd_usage);
452
Erik Andersene49d5ec2000-02-08 19:58:47 +0000453 /* Store away localhost's name before the fork */
454 gethostname(LocalHostName, sizeof(LocalHostName));
455 if ((p = strchr(LocalHostName, '.'))) {
456 *p++ = '\0';
457 }
458
Erik Andersen983b51b2000-04-04 18:14:25 +0000459 umask(0);
460
Erik Andersene2729152000-02-18 21:34:17 +0000461#ifdef BB_KLOGD
462 /* Start up the klogd process */
463 if (startKlogd == TRUE) {
464 klogd_pid = fork();
465 if (klogd_pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000466 daemon_init (argv, "klogd", doKlogd);
Erik Andersene2729152000-02-18 21:34:17 +0000467 }
468 }
469#endif
470
Erik Andersene49d5ec2000-02-08 19:58:47 +0000471 if (doFork == TRUE) {
472 pid = fork();
473 if (pid < 0)
474 exit(pid);
475 else if (pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000476 daemon_init (argv, "syslogd", doSyslogd);
Eric Andersen3843e961999-11-25 07:30:46 +0000477 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000478 } else {
479 doSyslogd();
Eric Andersen3843e961999-11-25 07:30:46 +0000480 }
Eric Andersenb186d981999-12-03 09:19:54 +0000481
Eric Andersen67e32302000-06-19 17:48:02 +0000482 return(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000483}
Erik Andersen983b51b2000-04-04 18:14:25 +0000484
485/*
Erik Andersene3ed1562000-04-19 18:52:56 +0000486Local Variables
487c-file-style: "linux"
488c-basic-offset: 4
489tab-width: 4
490End:
491*/