blob: 264d899f3377ad1b0b8d597b118ac09dcd840c32 [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 Andersenb186d981999-12-03 09:19:54 +000043
Eric Andersen999bf722000-07-09 06:59:58 +000044#if ! defined __GLIBC__ && ! defined __UCLIBC__
Eric Andersen67e32302000-06-19 17:48:02 +000045
Eric Andersena15cd0b2000-06-19 18:14:20 +000046typedef unsigned int socklen_t;
47
Eric Andersen67e32302000-06-19 17:48:02 +000048#ifndef __alpha__
49# define __NR_klogctl __NR_syslog
50static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
51#else /* __alpha__ */
52#define klogctl syslog
53#endif
54
55#else
56# include <sys/klog.h>
57#endif
58
Eric Andersenb99df0f1999-11-24 09:04:33 +000059
60
Eric Andersen3843e961999-11-25 07:30:46 +000061/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
62#define SYSLOG_NAMES
63#include <sys/syslog.h>
64
65/* Path for the file where all log messages are written */
Erik Andersen983b51b2000-04-04 18:14:25 +000066#define __LOG_FILE "/var/log/messages"
Eric Andersen3843e961999-11-25 07:30:46 +000067
Erik Andersen983b51b2000-04-04 18:14:25 +000068/* Path to the unix socket */
Erik Andersen4f3f7572000-04-28 00:18:56 +000069char lfile[BUFSIZ] = "";
Eric Andersen3843e961999-11-25 07:30:46 +000070
Erik Andersene49d5ec2000-02-08 19:58:47 +000071static char *logFilePath = __LOG_FILE;
72
Eric Andersen3843e961999-11-25 07:30:46 +000073/* interval between marks in seconds */
Erik Andersene49d5ec2000-02-08 19:58:47 +000074static int MarkInterval = 20 * 60;
75
Eric Andersen3843e961999-11-25 07:30:46 +000076/* localhost's name */
77static char LocalHostName[32];
78
Erik Andersenc053e412000-03-21 01:31:24 +000079/* Note: There is also a function called "message()" in init.c */
Erik Andersen983b51b2000-04-04 18:14:25 +000080/* Print a message to the log file. */
Erik Andersenf13df372000-04-18 23:51:51 +000081static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
82static void message (char *fmt, ...)
Eric Andersen3843e961999-11-25 07:30:46 +000083{
Erik Andersene49d5ec2000-02-08 19:58:47 +000084 int fd;
Erik Andersene3ed1562000-04-19 18:52:56 +000085 struct flock fl;
Erik Andersene49d5ec2000-02-08 19:58:47 +000086 va_list arguments;
Eric Andersen3843e961999-11-25 07:30:46 +000087
Erik Andersene3ed1562000-04-19 18:52:56 +000088 fl.l_whence = SEEK_SET;
89 fl.l_start = 0;
90 fl.l_len = 1;
91
Erik Andersenf13df372000-04-18 23:51:51 +000092 if ((fd = device_open (logFilePath,
93 O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND |
94 O_NONBLOCK)) >= 0) {
Erik Andersene3ed1562000-04-19 18:52:56 +000095 fl.l_type = F_WRLCK;
96 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +000097 va_start (arguments, fmt);
98 vdprintf (fd, fmt, arguments);
99 va_end (arguments);
Erik Andersene3ed1562000-04-19 18:52:56 +0000100 fl.l_type = F_UNLCK;
101 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +0000102 close (fd);
Eric Andersen3843e961999-11-25 07:30:46 +0000103 } else {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000104 /* Always send console messages to /dev/console so people will see them. */
Erik Andersenf13df372000-04-18 23:51:51 +0000105 if ((fd = device_open (_PATH_CONSOLE,
106 O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) {
107 va_start (arguments, fmt);
108 vdprintf (fd, fmt, arguments);
109 va_end (arguments);
110 close (fd);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000111 } else {
Erik Andersenf13df372000-04-18 23:51:51 +0000112 fprintf (stderr, "Bummer, can't print: ");
113 va_start (arguments, fmt);
114 vfprintf (stderr, fmt, arguments);
115 fflush (stderr);
116 va_end (arguments);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000117 }
Eric Andersen3843e961999-11-25 07:30:46 +0000118 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000119}
120
Erik Andersenf13df372000-04-18 23:51:51 +0000121static void logMessage (int pri, char *msg)
Eric Andersen3843e961999-11-25 07:30:46 +0000122{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000123 time_t now;
124 char *timestamp;
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000125 static char res[20] = "";
Erik Andersene49d5ec2000-02-08 19:58:47 +0000126 CODE *c_pri, *c_fac;
Eric Andersenb99df0f1999-11-24 09:04:33 +0000127
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000128 if (pri != 0) {
129 for (c_fac = facilitynames;
130 c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++);
131 for (c_pri = prioritynames;
132 c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++);
133 if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0')
134 snprintf(res, sizeof(res), "<%d>", pri);
135 else
136 snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name);
137 }
Eric Andersen3843e961999-11-25 07:30:46 +0000138
Erik Andersene49d5ec2000-02-08 19:58:47 +0000139 if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' ||
140 msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') {
141 time(&now);
142 timestamp = ctime(&now) + 4;
143 timestamp[15] = '\0';
144 } else {
145 timestamp = msg;
146 timestamp[15] = '\0';
147 msg += 16;
148 }
Eric Andersen3843e961999-11-25 07:30:46 +0000149
Erik Andersene49d5ec2000-02-08 19:58:47 +0000150 /* todo: supress duplicates */
Eric Andersen3843e961999-11-25 07:30:46 +0000151
Erik Andersene49d5ec2000-02-08 19:58:47 +0000152 /* now spew out the message to wherever it is supposed to go */
153 message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
Eric Andersen3843e961999-11-25 07:30:46 +0000154}
155
156static void quit_signal(int sig)
157{
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000158 logMessage(0, "System log daemon exiting.");
Erik Andersen983b51b2000-04-04 18:14:25 +0000159 unlink(lfile);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000160 exit(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000161}
162
Eric Andersen3843e961999-11-25 07:30:46 +0000163static void domark(int sig)
164{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000165 if (MarkInterval > 0) {
166 logMessage(LOG_SYSLOG | LOG_INFO, "-- MARK --");
167 alarm(MarkInterval);
168 }
Eric Andersen3843e961999-11-25 07:30:46 +0000169}
170
Pavel Roskinda10ec02000-06-07 21:08:25 +0000171#define BUFSIZE 1023
Eric Andersen67e32302000-06-19 17:48:02 +0000172static int serveConnection (int conn)
Pavel Roskinda10ec02000-06-07 21:08:25 +0000173{
174 char buf[ BUFSIZE + 1 ];
175 int n_read;
176
177 while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
178
179 int pri = (LOG_USER | LOG_NOTICE);
180 char line[ BUFSIZE + 1 ];
181 unsigned char c;
182
183 char *p = buf, *q = line;
184
185 buf[ n_read - 1 ] = '\0';
186
187 while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
188 if (c == '<') {
189 /* Parse the magic priority number. */
190 pri = 0;
191 while (isdigit (*(++p))) {
192 pri = 10 * pri + (*p - '0');
193 }
194 if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
195 pri = (LOG_USER | LOG_NOTICE);
196 } else if (c == '\n') {
197 *q++ = ' ';
198 } else if (iscntrl (c) && (c < 0177)) {
199 *q++ = '^';
200 *q++ = c ^ 0100;
201 } else {
202 *q++ = c;
203 }
204 p++;
205 }
206 *q = '\0';
207 /* Now log it */
208 logMessage (pri, line);
209 }
Eric Andersen67e32302000-06-19 17:48:02 +0000210 return (0);
Pavel Roskinda10ec02000-06-07 21:08:25 +0000211}
212
Erik Andersen983b51b2000-04-04 18:14:25 +0000213static void doSyslogd (void) __attribute__ ((noreturn));
214static void doSyslogd (void)
Eric Andersen3843e961999-11-25 07:30:46 +0000215{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000216 struct sockaddr_un sunx;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000217 socklen_t addrLength;
218
Erik Andersenf13df372000-04-18 23:51:51 +0000219
Erik Andersen983b51b2000-04-04 18:14:25 +0000220 int sock_fd;
Erik Andersenf13df372000-04-18 23:51:51 +0000221 fd_set fds;
222
Erik Andersen4f3f7572000-04-28 00:18:56 +0000223 char lfile[BUFSIZ];
Eric Andersenb99df0f1999-11-24 09:04:33 +0000224
Erik Andersenf13df372000-04-18 23:51:51 +0000225 /* Set up signal handlers. */
Erik Andersen983b51b2000-04-04 18:14:25 +0000226 signal (SIGINT, quit_signal);
227 signal (SIGTERM, quit_signal);
228 signal (SIGQUIT, quit_signal);
229 signal (SIGHUP, SIG_IGN);
Erik Andersene3ed1562000-04-19 18:52:56 +0000230 signal (SIGCLD, SIG_IGN);
Erik Andersen983b51b2000-04-04 18:14:25 +0000231 signal (SIGALRM, domark);
232 alarm (MarkInterval);
Eric Andersenb99df0f1999-11-24 09:04:33 +0000233
Erik Andersenf13df372000-04-18 23:51:51 +0000234 /* Create the syslog file so realpath() can work. */
235 close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
236 if (realpath (_PATH_LOG, lfile) == NULL)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000237 fatalError ("Could not resolv path to " _PATH_LOG ": %s\n", strerror (errno));
Eric Andersen14ec6cf1999-12-05 22:17:02 +0000238
Erik Andersen983b51b2000-04-04 18:14:25 +0000239 unlink (lfile);
240
Erik Andersenf13df372000-04-18 23:51:51 +0000241 memset (&sunx, 0, sizeof (sunx));
Erik Andersen983b51b2000-04-04 18:14:25 +0000242 sunx.sun_family = AF_UNIX;
Erik Andersenf13df372000-04-18 23:51:51 +0000243 strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
244 if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000245 fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s\n", strerror (errno));
Eric Andersenb99df0f1999-11-24 09:04:33 +0000246
Erik Andersen983b51b2000-04-04 18:14:25 +0000247 addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
Erik Andersenf13df372000-04-18 23:51:51 +0000248 if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
Eric Andersen86ab8a32000-06-02 03:21:42 +0000249 fatalError ("Could not connect to socket " _PATH_LOG ": %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000250
Erik Andersenf13df372000-04-18 23:51:51 +0000251 if (chmod (lfile, 0666) < 0)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000252 fatalError ("Could not set permission on " _PATH_LOG ": %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000253
Erik Andersenf13df372000-04-18 23:51:51 +0000254 FD_ZERO (&fds);
255 FD_SET (sock_fd, &fds);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000256
Erik Andersen983b51b2000-04-04 18:14:25 +0000257 logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000258
Erik Andersen983b51b2000-04-04 18:14:25 +0000259 for (;;) {
Erik Andersenf13df372000-04-18 23:51:51 +0000260
261 fd_set readfds;
262 int n_ready;
263 int fd;
264
265 memcpy (&readfds, &fds, sizeof (fds));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000266
Erik Andersen983b51b2000-04-04 18:14:25 +0000267 if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
268 if (errno == EINTR) continue; /* alarm may have happened. */
Erik Andersenf13df372000-04-18 23:51:51 +0000269 fatalError ("select error: %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000270 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000271
Erik Andersenf13df372000-04-18 23:51:51 +0000272 for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000273 if (FD_ISSET (fd, &readfds)) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000274
Erik Andersenf13df372000-04-18 23:51:51 +0000275 --n_ready;
Erik Andersene3ed1562000-04-19 18:52:56 +0000276
Erik Andersen983b51b2000-04-04 18:14:25 +0000277 if (fd == sock_fd) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000278
279 int conn;
280 pid_t pid;
281
Erik Andersenf13df372000-04-18 23:51:51 +0000282 if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) {
283 fatalError ("accept error: %s\n", strerror (errno));
Erik Andersen983b51b2000-04-04 18:14:25 +0000284 }
Erik Andersena6c75222000-04-18 00:00:52 +0000285
Erik Andersene3ed1562000-04-19 18:52:56 +0000286 pid = fork();
Erik Andersen983b51b2000-04-04 18:14:25 +0000287
Erik Andersene3ed1562000-04-19 18:52:56 +0000288 if (pid < 0) {
289 perror ("syslogd: fork");
290 close (conn);
291 continue;
Erik Andersen983b51b2000-04-04 18:14:25 +0000292 }
Erik Andersene3ed1562000-04-19 18:52:56 +0000293
Pavel Roskinda10ec02000-06-07 21:08:25 +0000294 if (pid == 0)
295 serveConnection (conn);
Erik Andersene3ed1562000-04-19 18:52:56 +0000296 close (conn);
Erik Andersen983b51b2000-04-04 18:14:25 +0000297 }
298 }
299 }
300 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000301}
302
Eric Andersen03f4c272000-07-06 23:10:29 +0000303#ifdef BB_FEATURE_KLOGD
Eric Andersen2cb55071999-12-10 08:25:07 +0000304
Eric Andersenb186d981999-12-03 09:19:54 +0000305static void klogd_signal(int sig)
306{
Eric Andersen67e32302000-06-19 17:48:02 +0000307 klogctl(7, NULL, 0);
308 klogctl(0, 0, 0);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000309 logMessage(0, "Kernel log daemon exiting.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000310 exit(TRUE);
Eric Andersenb186d981999-12-03 09:19:54 +0000311}
312
Erik Andersen983b51b2000-04-04 18:14:25 +0000313static void doKlogd (void) __attribute__ ((noreturn));
314static void doKlogd (void)
Eric Andersenb186d981999-12-03 09:19:54 +0000315{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000316 int priority = LOG_INFO;
317 char log_buffer[4096];
318 char *logp;
Eric Andersenb186d981999-12-03 09:19:54 +0000319
Erik Andersene49d5ec2000-02-08 19:58:47 +0000320 /* Set up sig handlers */
321 signal(SIGINT, klogd_signal);
322 signal(SIGKILL, klogd_signal);
323 signal(SIGTERM, klogd_signal);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000324 signal(SIGHUP, SIG_IGN);
325 logMessage(0, "klogd started: "
Erik Andersene49d5ec2000-02-08 19:58:47 +0000326 "BusyBox v" BB_VER " (" BB_BT ")");
Eric Andersenb186d981999-12-03 09:19:54 +0000327
Eric Andersen67e32302000-06-19 17:48:02 +0000328 klogctl(1, NULL, 0);
Eric Andersen0ecb54a1999-12-05 23:24:55 +0000329
Erik Andersene49d5ec2000-02-08 19:58:47 +0000330 while (1) {
331 /* Use kernel syscalls */
332 memset(log_buffer, '\0', sizeof(log_buffer));
Eric Andersen67e32302000-06-19 17:48:02 +0000333 if (klogctl(2, log_buffer, sizeof(log_buffer)) < 0) {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000334 char message[80];
335
336 if (errno == EINTR)
337 continue;
338 snprintf(message, 79, "klogd: Error return from sys_sycall: " \
339 "%d - %s.\n", errno, strerror(errno));
340 logMessage(LOG_SYSLOG | LOG_ERR, message);
341 exit(1);
342 }
343 logp = log_buffer;
344 if (*log_buffer == '<') {
345 switch (*(log_buffer + 1)) {
346 case '0':
347 priority = LOG_EMERG;
348 break;
349 case '1':
350 priority = LOG_ALERT;
351 break;
352 case '2':
353 priority = LOG_CRIT;
354 break;
355 case '3':
356 priority = LOG_ERR;
357 break;
358 case '4':
359 priority = LOG_WARNING;
360 break;
361 case '5':
362 priority = LOG_NOTICE;
363 break;
364 case '6':
365 priority = LOG_INFO;
366 break;
367 case '7':
368 default:
369 priority = LOG_DEBUG;
370 }
371 logp += 3;
372 }
373 logMessage(LOG_KERN | priority, logp);
Eric Andersenb186d981999-12-03 09:19:54 +0000374 }
Eric Andersenb186d981999-12-03 09:19:54 +0000375
376}
377
Eric Andersen2cb55071999-12-10 08:25:07 +0000378#endif
Eric Andersenb99df0f1999-11-24 09:04:33 +0000379
Erik Andersen983b51b2000-04-04 18:14:25 +0000380static void daemon_init (char **argv, char *dz, void fn (void))
381{
382 setsid();
383 chdir ("/");
384 strncpy(argv[0], dz, strlen(argv[0]));
385 fn();
386 exit(0);
387}
388
Eric Andersen3843e961999-11-25 07:30:46 +0000389extern int syslogd_main(int argc, char **argv)
390{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000391 int pid, klogd_pid;
392 int doFork = TRUE;
393
Eric Andersen03f4c272000-07-06 23:10:29 +0000394#ifdef BB_FEATURE_KLOGD
Erik Andersene49d5ec2000-02-08 19:58:47 +0000395 int startKlogd = TRUE;
Eric Andersen2cb55071999-12-10 08:25:07 +0000396#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000397 int stopDoingThat = FALSE;
398 char *p;
399 char **argv1 = argv;
400
401 while (--argc > 0 && **(++argv1) == '-') {
402 stopDoingThat = FALSE;
403 while (stopDoingThat == FALSE && *(++(*argv1))) {
404 switch (**argv1) {
405 case 'm':
406 if (--argc == 0) {
407 usage(syslogd_usage);
408 }
409 MarkInterval = atoi(*(++argv1)) * 60;
410 break;
411 case 'n':
412 doFork = FALSE;
413 break;
Eric Andersen03f4c272000-07-06 23:10:29 +0000414#ifdef BB_FEATURE_KLOGD
Erik Andersene49d5ec2000-02-08 19:58:47 +0000415 case 'K':
416 startKlogd = FALSE;
417 break;
418#endif
419 case 'O':
420 if (--argc == 0) {
421 usage(syslogd_usage);
422 }
423 logFilePath = *(++argv1);
424 stopDoingThat = TRUE;
425 break;
426 default:
427 usage(syslogd_usage);
428 }
Eric Andersen3843e961999-11-25 07:30:46 +0000429 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000430 }
431
Pavel Roskinda10ec02000-06-07 21:08:25 +0000432 if (argc > 0)
433 usage(syslogd_usage);
434
Erik Andersene49d5ec2000-02-08 19:58:47 +0000435 /* Store away localhost's name before the fork */
436 gethostname(LocalHostName, sizeof(LocalHostName));
437 if ((p = strchr(LocalHostName, '.'))) {
438 *p++ = '\0';
439 }
440
Erik Andersen983b51b2000-04-04 18:14:25 +0000441 umask(0);
442
Eric Andersen03f4c272000-07-06 23:10:29 +0000443#ifdef BB_FEATURE_KLOGD
Erik Andersene2729152000-02-18 21:34:17 +0000444 /* Start up the klogd process */
445 if (startKlogd == TRUE) {
446 klogd_pid = fork();
447 if (klogd_pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000448 daemon_init (argv, "klogd", doKlogd);
Erik Andersene2729152000-02-18 21:34:17 +0000449 }
450 }
451#endif
452
Erik Andersene49d5ec2000-02-08 19:58:47 +0000453 if (doFork == TRUE) {
454 pid = fork();
455 if (pid < 0)
456 exit(pid);
457 else if (pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000458 daemon_init (argv, "syslogd", doSyslogd);
Eric Andersen3843e961999-11-25 07:30:46 +0000459 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000460 } else {
461 doSyslogd();
Eric Andersen3843e961999-11-25 07:30:46 +0000462 }
Eric Andersenb186d981999-12-03 09:19:54 +0000463
Eric Andersen67e32302000-06-19 17:48:02 +0000464 return(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000465}
Erik Andersen983b51b2000-04-04 18:14:25 +0000466
467/*
Erik Andersene3ed1562000-04-19 18:52:56 +0000468Local Variables
469c-file-style: "linux"
470c-basic-offset: 4
471tab-width: 4
472End:
473*/