blob: c7906368d909fa80fd5235f91b09d428737d1e25 [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>
Erik Andersen7d6ba572000-04-19 20:02:50 +000040#include <sys/param.h>
Erik Andersen983b51b2000-04-04 18:14:25 +000041#include <time.h>
42#include <unistd.h>
Eric Andersenb186d981999-12-03 09:19:54 +000043
44#define ksyslog klogctl
45extern int ksyslog(int type, char *buf, int len);
Eric Andersenb99df0f1999-11-24 09:04:33 +000046
47
Eric Andersen3843e961999-11-25 07:30:46 +000048/* SYSLOG_NAMES defined to pull some extra junk from syslog.h */
49#define SYSLOG_NAMES
50#include <sys/syslog.h>
51
52/* Path for the file where all log messages are written */
Erik Andersen983b51b2000-04-04 18:14:25 +000053#define __LOG_FILE "/var/log/messages"
Eric Andersen3843e961999-11-25 07:30:46 +000054
Erik Andersen983b51b2000-04-04 18:14:25 +000055/* Path to the unix socket */
Erik Andersen4f3f7572000-04-28 00:18:56 +000056char lfile[BUFSIZ] = "";
Eric Andersen3843e961999-11-25 07:30:46 +000057
Erik Andersene49d5ec2000-02-08 19:58:47 +000058static char *logFilePath = __LOG_FILE;
59
Eric Andersen3843e961999-11-25 07:30:46 +000060/* interval between marks in seconds */
Erik Andersene49d5ec2000-02-08 19:58:47 +000061static int MarkInterval = 20 * 60;
62
Eric Andersen3843e961999-11-25 07:30:46 +000063/* localhost's name */
64static char LocalHostName[32];
65
66static const char syslogd_usage[] =
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000067 "syslogd [OPTION]...\n"
68#ifndef BB_FEATURE_TRIVIAL_HELP
69 "\nLinux system and kernel (provides klogd) logging utility.\n"
Erik Andersene49d5ec2000-02-08 19:58:47 +000070 "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n"
71 "Options:\n"
Pavel Roskinda10ec02000-06-07 21:08:25 +000072 "\t-m NUM\t\tInterval between MARK lines (default=20min, 0=off)\n"
73 "\t-n\t\tRun as a foreground process\n"
Eric Andersen2cb55071999-12-10 08:25:07 +000074#ifdef BB_KLOGD
Pavel Roskinda10ec02000-06-07 21:08:25 +000075 "\t-K\t\tDo not start up the klogd process\n"
Eric Andersen2cb55071999-12-10 08:25:07 +000076#endif
Pavel Roskinda10ec02000-06-07 21:08:25 +000077 "\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n"
Erik Andersen7ab9c7e2000-05-12 19:41:47 +000078#endif
79 ;
Eric Andersen3843e961999-11-25 07:30:46 +000080
Erik Andersenc053e412000-03-21 01:31:24 +000081/* Note: There is also a function called "message()" in init.c */
Erik Andersen983b51b2000-04-04 18:14:25 +000082/* Print a message to the log file. */
Erik Andersenf13df372000-04-18 23:51:51 +000083static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
84static void message (char *fmt, ...)
Eric Andersen3843e961999-11-25 07:30:46 +000085{
Erik Andersene49d5ec2000-02-08 19:58:47 +000086 int fd;
Erik Andersene3ed1562000-04-19 18:52:56 +000087 struct flock fl;
Erik Andersene49d5ec2000-02-08 19:58:47 +000088 va_list arguments;
Eric Andersen3843e961999-11-25 07:30:46 +000089
Erik Andersene3ed1562000-04-19 18:52:56 +000090 fl.l_whence = SEEK_SET;
91 fl.l_start = 0;
92 fl.l_len = 1;
93
Erik Andersenf13df372000-04-18 23:51:51 +000094 if ((fd = device_open (logFilePath,
95 O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND |
96 O_NONBLOCK)) >= 0) {
Erik Andersene3ed1562000-04-19 18:52:56 +000097 fl.l_type = F_WRLCK;
98 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +000099 va_start (arguments, fmt);
100 vdprintf (fd, fmt, arguments);
101 va_end (arguments);
Erik Andersene3ed1562000-04-19 18:52:56 +0000102 fl.l_type = F_UNLCK;
103 fcntl (fd, F_SETLKW, &fl);
Erik Andersenf13df372000-04-18 23:51:51 +0000104 close (fd);
Eric Andersen3843e961999-11-25 07:30:46 +0000105 } else {
Erik Andersene49d5ec2000-02-08 19:58:47 +0000106 /* Always send console messages to /dev/console so people will see them. */
Erik Andersenf13df372000-04-18 23:51:51 +0000107 if ((fd = device_open (_PATH_CONSOLE,
108 O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) {
109 va_start (arguments, fmt);
110 vdprintf (fd, fmt, arguments);
111 va_end (arguments);
112 close (fd);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000113 } else {
Erik Andersenf13df372000-04-18 23:51:51 +0000114 fprintf (stderr, "Bummer, can't print: ");
115 va_start (arguments, fmt);
116 vfprintf (stderr, fmt, arguments);
117 fflush (stderr);
118 va_end (arguments);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000119 }
Eric Andersen3843e961999-11-25 07:30:46 +0000120 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000121}
122
Erik Andersenf13df372000-04-18 23:51:51 +0000123static void logMessage (int pri, char *msg)
Eric Andersen3843e961999-11-25 07:30:46 +0000124{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000125 time_t now;
126 char *timestamp;
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000127 static char res[20] = "";
Erik Andersene49d5ec2000-02-08 19:58:47 +0000128 CODE *c_pri, *c_fac;
Eric Andersenb99df0f1999-11-24 09:04:33 +0000129
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000130 if (pri != 0) {
131 for (c_fac = facilitynames;
132 c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++);
133 for (c_pri = prioritynames;
134 c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++);
135 if (*c_fac->c_name == '\0' || *c_pri->c_name == '\0')
136 snprintf(res, sizeof(res), "<%d>", pri);
137 else
138 snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name);
139 }
Eric Andersen3843e961999-11-25 07:30:46 +0000140
Erik Andersene49d5ec2000-02-08 19:58:47 +0000141 if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' ||
142 msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') {
143 time(&now);
144 timestamp = ctime(&now) + 4;
145 timestamp[15] = '\0';
146 } else {
147 timestamp = msg;
148 timestamp[15] = '\0';
149 msg += 16;
150 }
Eric Andersen3843e961999-11-25 07:30:46 +0000151
Erik Andersene49d5ec2000-02-08 19:58:47 +0000152 /* todo: supress duplicates */
Eric Andersen3843e961999-11-25 07:30:46 +0000153
Erik Andersene49d5ec2000-02-08 19:58:47 +0000154 /* now spew out the message to wherever it is supposed to go */
155 message("%s %s %s %s\n", timestamp, LocalHostName, res, msg);
Eric Andersen3843e961999-11-25 07:30:46 +0000156}
157
158static void quit_signal(int sig)
159{
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000160 logMessage(0, "System log daemon exiting.");
Erik Andersen983b51b2000-04-04 18:14:25 +0000161 unlink(lfile);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000162 exit(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000163}
164
Eric Andersen3843e961999-11-25 07:30:46 +0000165static void domark(int sig)
166{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000167 if (MarkInterval > 0) {
168 logMessage(LOG_SYSLOG | LOG_INFO, "-- MARK --");
169 alarm(MarkInterval);
170 }
Eric Andersen3843e961999-11-25 07:30:46 +0000171}
172
Pavel Roskinda10ec02000-06-07 21:08:25 +0000173#define BUFSIZE 1023
174static void serveConnection (int conn) __attribute__ ((noreturn));
175static void serveConnection (int conn)
176{
177 char buf[ BUFSIZE + 1 ];
178 int n_read;
179
180 while ((n_read = read (conn, buf, BUFSIZE )) > 0) {
181
182 int pri = (LOG_USER | LOG_NOTICE);
183 char line[ BUFSIZE + 1 ];
184 unsigned char c;
185
186 char *p = buf, *q = line;
187
188 buf[ n_read - 1 ] = '\0';
189
190 while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) {
191 if (c == '<') {
192 /* Parse the magic priority number. */
193 pri = 0;
194 while (isdigit (*(++p))) {
195 pri = 10 * pri + (*p - '0');
196 }
197 if (pri & ~(LOG_FACMASK | LOG_PRIMASK))
198 pri = (LOG_USER | LOG_NOTICE);
199 } else if (c == '\n') {
200 *q++ = ' ';
201 } else if (iscntrl (c) && (c < 0177)) {
202 *q++ = '^';
203 *q++ = c ^ 0100;
204 } else {
205 *q++ = c;
206 }
207 p++;
208 }
209 *q = '\0';
210 /* Now log it */
211 logMessage (pri, line);
212 }
213 exit (0);
214}
215
Erik Andersen983b51b2000-04-04 18:14:25 +0000216static void doSyslogd (void) __attribute__ ((noreturn));
217static void doSyslogd (void)
Eric Andersen3843e961999-11-25 07:30:46 +0000218{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000219 struct sockaddr_un sunx;
Erik Andersen1d1d9502000-04-21 01:26:49 +0000220 socklen_t addrLength;
221
Erik Andersenf13df372000-04-18 23:51:51 +0000222
Erik Andersen983b51b2000-04-04 18:14:25 +0000223 int sock_fd;
Erik Andersenf13df372000-04-18 23:51:51 +0000224 fd_set fds;
225
Erik Andersen4f3f7572000-04-28 00:18:56 +0000226 char lfile[BUFSIZ];
Eric Andersenb99df0f1999-11-24 09:04:33 +0000227
Erik Andersenf13df372000-04-18 23:51:51 +0000228 /* Set up signal handlers. */
Erik Andersen983b51b2000-04-04 18:14:25 +0000229 signal (SIGINT, quit_signal);
230 signal (SIGTERM, quit_signal);
231 signal (SIGQUIT, quit_signal);
232 signal (SIGHUP, SIG_IGN);
Erik Andersene3ed1562000-04-19 18:52:56 +0000233 signal (SIGCLD, SIG_IGN);
Erik Andersen983b51b2000-04-04 18:14:25 +0000234 signal (SIGALRM, domark);
235 alarm (MarkInterval);
Eric Andersenb99df0f1999-11-24 09:04:33 +0000236
Erik Andersenf13df372000-04-18 23:51:51 +0000237 /* Create the syslog file so realpath() can work. */
238 close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644));
239 if (realpath (_PATH_LOG, lfile) == NULL)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000240 fatalError ("Could not resolv path to " _PATH_LOG ": %s\n", strerror (errno));
Eric Andersen14ec6cf1999-12-05 22:17:02 +0000241
Erik Andersen983b51b2000-04-04 18:14:25 +0000242 unlink (lfile);
243
Erik Andersenf13df372000-04-18 23:51:51 +0000244 memset (&sunx, 0, sizeof (sunx));
Erik Andersen983b51b2000-04-04 18:14:25 +0000245 sunx.sun_family = AF_UNIX;
Erik Andersenf13df372000-04-18 23:51:51 +0000246 strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path));
247 if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000248 fatalError ("Couldn't obtain descriptor for socket " _PATH_LOG ": %s\n", strerror (errno));
Eric Andersenb99df0f1999-11-24 09:04:33 +0000249
Erik Andersen983b51b2000-04-04 18:14:25 +0000250 addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path);
Erik Andersenf13df372000-04-18 23:51:51 +0000251 if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5)))
Eric Andersen86ab8a32000-06-02 03:21:42 +0000252 fatalError ("Could not connect to socket " _PATH_LOG ": %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000253
Erik Andersenf13df372000-04-18 23:51:51 +0000254 if (chmod (lfile, 0666) < 0)
Eric Andersen86ab8a32000-06-02 03:21:42 +0000255 fatalError ("Could not set permission on " _PATH_LOG ": %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000256
Erik Andersenf13df372000-04-18 23:51:51 +0000257 FD_ZERO (&fds);
258 FD_SET (sock_fd, &fds);
Erik Andersene49d5ec2000-02-08 19:58:47 +0000259
Erik Andersen983b51b2000-04-04 18:14:25 +0000260 logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000261
Erik Andersen983b51b2000-04-04 18:14:25 +0000262 for (;;) {
Erik Andersenf13df372000-04-18 23:51:51 +0000263
264 fd_set readfds;
265 int n_ready;
266 int fd;
267
268 memcpy (&readfds, &fds, sizeof (fds));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000269
Erik Andersen983b51b2000-04-04 18:14:25 +0000270 if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) {
271 if (errno == EINTR) continue; /* alarm may have happened. */
Erik Andersenf13df372000-04-18 23:51:51 +0000272 fatalError ("select error: %s\n", strerror (errno));
Erik Andersene49d5ec2000-02-08 19:58:47 +0000273 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000274
Erik Andersenf13df372000-04-18 23:51:51 +0000275 for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000276 if (FD_ISSET (fd, &readfds)) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000277
Erik Andersenf13df372000-04-18 23:51:51 +0000278 --n_ready;
Erik Andersene3ed1562000-04-19 18:52:56 +0000279
Erik Andersen983b51b2000-04-04 18:14:25 +0000280 if (fd == sock_fd) {
Erik Andersene3ed1562000-04-19 18:52:56 +0000281
282 int conn;
283 pid_t pid;
284
Erik Andersenf13df372000-04-18 23:51:51 +0000285 if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) {
286 fatalError ("accept error: %s\n", strerror (errno));
Erik Andersen983b51b2000-04-04 18:14:25 +0000287 }
Erik Andersena6c75222000-04-18 00:00:52 +0000288
Erik Andersene3ed1562000-04-19 18:52:56 +0000289 pid = fork();
Erik Andersen983b51b2000-04-04 18:14:25 +0000290
Erik Andersene3ed1562000-04-19 18:52:56 +0000291 if (pid < 0) {
292 perror ("syslogd: fork");
293 close (conn);
294 continue;
Erik Andersen983b51b2000-04-04 18:14:25 +0000295 }
Erik Andersene3ed1562000-04-19 18:52:56 +0000296
Pavel Roskinda10ec02000-06-07 21:08:25 +0000297 if (pid == 0)
298 serveConnection (conn);
Erik Andersene3ed1562000-04-19 18:52:56 +0000299 close (conn);
Erik Andersen983b51b2000-04-04 18:14:25 +0000300 }
301 }
302 }
303 }
Eric Andersenb99df0f1999-11-24 09:04:33 +0000304}
305
Eric Andersen2cb55071999-12-10 08:25:07 +0000306#ifdef BB_KLOGD
307
Eric Andersenb186d981999-12-03 09:19:54 +0000308static void klogd_signal(int sig)
309{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000310 ksyslog(7, NULL, 0);
311 ksyslog(0, 0, 0);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000312 logMessage(0, "Kernel log daemon exiting.");
Erik Andersene49d5ec2000-02-08 19:58:47 +0000313 exit(TRUE);
Eric Andersenb186d981999-12-03 09:19:54 +0000314}
315
Erik Andersen983b51b2000-04-04 18:14:25 +0000316static void doKlogd (void) __attribute__ ((noreturn));
317static void doKlogd (void)
Eric Andersenb186d981999-12-03 09:19:54 +0000318{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000319 int priority = LOG_INFO;
320 char log_buffer[4096];
321 char *logp;
Eric Andersenb186d981999-12-03 09:19:54 +0000322
Erik Andersene49d5ec2000-02-08 19:58:47 +0000323 /* Set up sig handlers */
324 signal(SIGINT, klogd_signal);
325 signal(SIGKILL, klogd_signal);
326 signal(SIGTERM, klogd_signal);
Erik Andersen9ffdaa62000-02-11 21:55:04 +0000327 signal(SIGHUP, SIG_IGN);
328 logMessage(0, "klogd started: "
Erik Andersene49d5ec2000-02-08 19:58:47 +0000329 "BusyBox v" BB_VER " (" BB_BT ")");
Eric Andersenb186d981999-12-03 09:19:54 +0000330
Erik Andersene49d5ec2000-02-08 19:58:47 +0000331 ksyslog(1, NULL, 0);
Eric Andersen0ecb54a1999-12-05 23:24:55 +0000332
Erik Andersene49d5ec2000-02-08 19:58:47 +0000333 while (1) {
334 /* Use kernel syscalls */
335 memset(log_buffer, '\0', sizeof(log_buffer));
336 if (ksyslog(2, log_buffer, sizeof(log_buffer)) < 0) {
337 char message[80];
338
339 if (errno == EINTR)
340 continue;
341 snprintf(message, 79, "klogd: Error return from sys_sycall: " \
342 "%d - %s.\n", errno, strerror(errno));
343 logMessage(LOG_SYSLOG | LOG_ERR, message);
344 exit(1);
345 }
346 logp = log_buffer;
347 if (*log_buffer == '<') {
348 switch (*(log_buffer + 1)) {
349 case '0':
350 priority = LOG_EMERG;
351 break;
352 case '1':
353 priority = LOG_ALERT;
354 break;
355 case '2':
356 priority = LOG_CRIT;
357 break;
358 case '3':
359 priority = LOG_ERR;
360 break;
361 case '4':
362 priority = LOG_WARNING;
363 break;
364 case '5':
365 priority = LOG_NOTICE;
366 break;
367 case '6':
368 priority = LOG_INFO;
369 break;
370 case '7':
371 default:
372 priority = LOG_DEBUG;
373 }
374 logp += 3;
375 }
376 logMessage(LOG_KERN | priority, logp);
Eric Andersenb186d981999-12-03 09:19:54 +0000377 }
Eric Andersenb186d981999-12-03 09:19:54 +0000378
379}
380
Eric Andersen2cb55071999-12-10 08:25:07 +0000381#endif
Eric Andersenb99df0f1999-11-24 09:04:33 +0000382
Erik Andersen983b51b2000-04-04 18:14:25 +0000383static void daemon_init (char **argv, char *dz, void fn (void))
384{
385 setsid();
386 chdir ("/");
387 strncpy(argv[0], dz, strlen(argv[0]));
388 fn();
389 exit(0);
390}
391
Eric Andersen3843e961999-11-25 07:30:46 +0000392extern int syslogd_main(int argc, char **argv)
393{
Erik Andersene49d5ec2000-02-08 19:58:47 +0000394 int pid, klogd_pid;
395 int doFork = TRUE;
396
Eric Andersen2cb55071999-12-10 08:25:07 +0000397#ifdef BB_KLOGD
Erik Andersene49d5ec2000-02-08 19:58:47 +0000398 int startKlogd = TRUE;
Eric Andersen2cb55071999-12-10 08:25:07 +0000399#endif
Erik Andersene49d5ec2000-02-08 19:58:47 +0000400 int stopDoingThat = FALSE;
401 char *p;
402 char **argv1 = argv;
403
404 while (--argc > 0 && **(++argv1) == '-') {
405 stopDoingThat = FALSE;
406 while (stopDoingThat == FALSE && *(++(*argv1))) {
407 switch (**argv1) {
408 case 'm':
409 if (--argc == 0) {
410 usage(syslogd_usage);
411 }
412 MarkInterval = atoi(*(++argv1)) * 60;
413 break;
414 case 'n':
415 doFork = FALSE;
416 break;
417#ifdef BB_KLOGD
418 case 'K':
419 startKlogd = FALSE;
420 break;
421#endif
422 case 'O':
423 if (--argc == 0) {
424 usage(syslogd_usage);
425 }
426 logFilePath = *(++argv1);
427 stopDoingThat = TRUE;
428 break;
429 default:
430 usage(syslogd_usage);
431 }
Eric Andersen3843e961999-11-25 07:30:46 +0000432 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000433 }
434
Pavel Roskinda10ec02000-06-07 21:08:25 +0000435 if (argc > 0)
436 usage(syslogd_usage);
437
Erik Andersene49d5ec2000-02-08 19:58:47 +0000438 /* Store away localhost's name before the fork */
439 gethostname(LocalHostName, sizeof(LocalHostName));
440 if ((p = strchr(LocalHostName, '.'))) {
441 *p++ = '\0';
442 }
443
Erik Andersen983b51b2000-04-04 18:14:25 +0000444 umask(0);
445
Erik Andersene2729152000-02-18 21:34:17 +0000446#ifdef BB_KLOGD
447 /* Start up the klogd process */
448 if (startKlogd == TRUE) {
449 klogd_pid = fork();
450 if (klogd_pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000451 daemon_init (argv, "klogd", doKlogd);
Erik Andersene2729152000-02-18 21:34:17 +0000452 }
453 }
454#endif
455
Erik Andersene49d5ec2000-02-08 19:58:47 +0000456 if (doFork == TRUE) {
457 pid = fork();
458 if (pid < 0)
459 exit(pid);
460 else if (pid == 0) {
Erik Andersen983b51b2000-04-04 18:14:25 +0000461 daemon_init (argv, "syslogd", doSyslogd);
Eric Andersen3843e961999-11-25 07:30:46 +0000462 }
Erik Andersene49d5ec2000-02-08 19:58:47 +0000463 } else {
464 doSyslogd();
Eric Andersen3843e961999-11-25 07:30:46 +0000465 }
Eric Andersenb186d981999-12-03 09:19:54 +0000466
Erik Andersene49d5ec2000-02-08 19:58:47 +0000467 exit(TRUE);
Eric Andersen3843e961999-11-25 07:30:46 +0000468}
Erik Andersen983b51b2000-04-04 18:14:25 +0000469
470/*
Erik Andersene3ed1562000-04-19 18:52:56 +0000471Local Variables
472c-file-style: "linux"
473c-basic-offset: 4
474tab-width: 4
475End:
476*/