Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini syslogd implementation for busybox |
| 4 | * |
Eric Andersen | 8ec10a9 | 2001-01-27 09:33:39 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999,2000,2001 by Lineo, inc. |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
| 7 | * |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 8 | * Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org> |
| 9 | * |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 10 | * 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 Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 25 | |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 28 | #include <ctype.h> |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 29 | #include <errno.h> |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 30 | #include <fcntl.h> |
| 31 | #include <netdb.h> |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 32 | #include <paths.h> |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 33 | #include <signal.h> |
| 34 | #include <stdarg.h> |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 35 | #include <time.h> |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 36 | #include <string.h> |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 37 | #include <unistd.h> |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 38 | #include <sys/socket.h> |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 39 | #include <sys/types.h> |
| 40 | #include <sys/un.h> |
Erik Andersen | 7d6ba57 | 2000-04-19 20:02:50 +0000 | [diff] [blame] | 41 | #include <sys/param.h> |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 42 | |
Eric Andersen | 999bf72 | 2000-07-09 06:59:58 +0000 | [diff] [blame] | 43 | #if ! defined __GLIBC__ && ! defined __UCLIBC__ |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 44 | #include <sys/syscall.h> |
| 45 | #include <linux/unistd.h> |
Eric Andersen | a15cd0b | 2000-06-19 18:14:20 +0000 | [diff] [blame] | 46 | typedef unsigned int socklen_t; |
| 47 | |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 48 | #ifndef __alpha__ |
| 49 | # define __NR_klogctl __NR_syslog |
| 50 | static 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 |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame^] | 58 | #include "busybox.h" |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 59 | |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 60 | |
| 61 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 62 | /* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ |
| 63 | #define SYSLOG_NAMES |
| 64 | #include <sys/syslog.h> |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 65 | #include <sys/uio.h> |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 66 | |
| 67 | /* Path for the file where all log messages are written */ |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 68 | #define __LOG_FILE "/var/log/messages" |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 69 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 70 | /* Path to the unix socket */ |
Erik Andersen | 4f3f757 | 2000-04-28 00:18:56 +0000 | [diff] [blame] | 71 | char lfile[BUFSIZ] = ""; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 72 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 73 | static char *logFilePath = __LOG_FILE; |
| 74 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 75 | /* interval between marks in seconds */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 76 | static int MarkInterval = 20 * 60; |
| 77 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 78 | /* localhost's name */ |
| 79 | static char LocalHostName[32]; |
| 80 | |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 81 | #ifdef BB_FEATURE_REMOTE_LOG |
| 82 | #include <netinet/in.h> |
| 83 | /* udp socket for logging to remote host */ |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 84 | static int remotefd = -1; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 85 | /* where do we log? */ |
| 86 | static char *RemoteHost; |
| 87 | /* what port to log to? */ |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 88 | static int RemotePort = 514; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 89 | /* To remote log or not to remote log, that is the question. */ |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 90 | static int doRemoteLog = FALSE; |
Eric Andersen | 70d09ed | 2000-12-11 16:24:16 +0000 | [diff] [blame] | 91 | static int local_logging = FALSE; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
Erik Andersen | c053e41 | 2000-03-21 01:31:24 +0000 | [diff] [blame] | 94 | /* Note: There is also a function called "message()" in init.c */ |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 95 | /* Print a message to the log file. */ |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 96 | static void message (char *fmt, ...) __attribute__ ((format (printf, 1, 2))); |
| 97 | static void message (char *fmt, ...) |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 98 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 99 | int fd; |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 100 | struct flock fl; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 101 | va_list arguments; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 102 | |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 103 | fl.l_whence = SEEK_SET; |
| 104 | fl.l_start = 0; |
| 105 | fl.l_len = 1; |
| 106 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 107 | if ((fd = device_open (logFilePath, |
| 108 | O_WRONLY | O_CREAT | O_NOCTTY | O_APPEND | |
| 109 | O_NONBLOCK)) >= 0) { |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 110 | fl.l_type = F_WRLCK; |
| 111 | fcntl (fd, F_SETLKW, &fl); |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 112 | va_start (arguments, fmt); |
| 113 | vdprintf (fd, fmt, arguments); |
| 114 | va_end (arguments); |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 115 | fl.l_type = F_UNLCK; |
| 116 | fcntl (fd, F_SETLKW, &fl); |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 117 | close (fd); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 118 | } else { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 119 | /* Always send console messages to /dev/console so people will see them. */ |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 120 | if ((fd = device_open (_PATH_CONSOLE, |
| 121 | O_WRONLY | O_NOCTTY | O_NONBLOCK)) >= 0) { |
| 122 | va_start (arguments, fmt); |
| 123 | vdprintf (fd, fmt, arguments); |
| 124 | va_end (arguments); |
| 125 | close (fd); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 126 | } else { |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 127 | fprintf (stderr, "Bummer, can't print: "); |
| 128 | va_start (arguments, fmt); |
| 129 | vfprintf (stderr, fmt, arguments); |
| 130 | fflush (stderr); |
| 131 | va_end (arguments); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 132 | } |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 133 | } |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 136 | static void logMessage (int pri, char *msg) |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 137 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 138 | time_t now; |
| 139 | char *timestamp; |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 140 | static char res[20] = ""; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 141 | CODE *c_pri, *c_fac; |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 142 | |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 143 | if (pri != 0) { |
| 144 | for (c_fac = facilitynames; |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 145 | c_fac->c_name && !(c_fac->c_val == LOG_FAC(pri) << 3); c_fac++); |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 146 | for (c_pri = prioritynames; |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 147 | c_pri->c_name && !(c_pri->c_val == LOG_PRI(pri)); c_pri++); |
Matt Kraai | 5a964f9 | 2000-12-11 20:13:37 +0000 | [diff] [blame] | 148 | if (c_fac->c_name == NULL || c_pri->c_name == NULL) |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 149 | snprintf(res, sizeof(res), "<%d>", pri); |
| 150 | else |
| 151 | snprintf(res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name); |
| 152 | } |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 153 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 154 | if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' || |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 155 | msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 156 | time(&now); |
| 157 | timestamp = ctime(&now) + 4; |
| 158 | timestamp[15] = '\0'; |
| 159 | } else { |
| 160 | timestamp = msg; |
| 161 | timestamp[15] = '\0'; |
| 162 | msg += 16; |
| 163 | } |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 164 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 165 | /* todo: supress duplicates */ |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 166 | |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 167 | #ifdef BB_FEATURE_REMOTE_LOG |
| 168 | /* send message to remote logger */ |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 169 | if ( -1 != remotefd){ |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 170 | static const int IOV_COUNT = 2; |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 171 | struct iovec iov[IOV_COUNT]; |
| 172 | struct iovec *v = iov; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 173 | |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 174 | bzero(&res, sizeof(res)); |
| 175 | snprintf(res, sizeof(res), "<%d>", pri); |
| 176 | v->iov_base = res ; |
| 177 | v->iov_len = strlen(res); |
| 178 | v++; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 179 | |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 180 | v->iov_base = msg; |
| 181 | v->iov_len = strlen(msg); |
| 182 | |
| 183 | if ( -1 == writev(remotefd,iov, IOV_COUNT)){ |
| 184 | error_msg_and_die("syslogd: cannot write to remote file handle on" |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 185 | "%s:%d",RemoteHost,RemotePort); |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 186 | } |
| 187 | } |
| 188 | if (local_logging == TRUE) |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 189 | #endif |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 190 | /* now spew out the message to wherever it is supposed to go */ |
| 191 | message("%s %s %s %s\n", timestamp, LocalHostName, res, msg); |
Eric Andersen | 76fef0a | 2000-12-08 19:41:21 +0000 | [diff] [blame] | 192 | |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 193 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void quit_signal(int sig) |
| 197 | { |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 198 | logMessage(0, "System log daemon exiting."); |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 199 | unlink(lfile); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 200 | exit(TRUE); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 203 | static void domark(int sig) |
| 204 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 205 | if (MarkInterval > 0) { |
| 206 | logMessage(LOG_SYSLOG | LOG_INFO, "-- MARK --"); |
| 207 | alarm(MarkInterval); |
| 208 | } |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Mark Whitley | 59ab025 | 2001-01-23 22:30:04 +0000 | [diff] [blame] | 211 | static const int BUFSIZE = 1023; |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 212 | static int serveConnection (int conn) |
Pavel Roskin | da10ec0 | 2000-06-07 21:08:25 +0000 | [diff] [blame] | 213 | { |
Eric Andersen | d35c215 | 2001-01-25 23:49:09 +0000 | [diff] [blame] | 214 | RESERVE_BB_BUFFER(buf, BUFSIZE + 1); |
Pavel Roskin | da10ec0 | 2000-06-07 21:08:25 +0000 | [diff] [blame] | 215 | int n_read; |
| 216 | |
| 217 | while ((n_read = read (conn, buf, BUFSIZE )) > 0) { |
| 218 | |
| 219 | int pri = (LOG_USER | LOG_NOTICE); |
| 220 | char line[ BUFSIZE + 1 ]; |
| 221 | unsigned char c; |
| 222 | |
| 223 | char *p = buf, *q = line; |
| 224 | |
| 225 | buf[ n_read - 1 ] = '\0'; |
| 226 | |
| 227 | while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) { |
| 228 | if (c == '<') { |
| 229 | /* Parse the magic priority number. */ |
| 230 | pri = 0; |
| 231 | while (isdigit (*(++p))) { |
| 232 | pri = 10 * pri + (*p - '0'); |
| 233 | } |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 234 | if (pri & ~(LOG_FACMASK | LOG_PRIMASK)){ |
Pavel Roskin | da10ec0 | 2000-06-07 21:08:25 +0000 | [diff] [blame] | 235 | pri = (LOG_USER | LOG_NOTICE); |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 236 | } |
Pavel Roskin | da10ec0 | 2000-06-07 21:08:25 +0000 | [diff] [blame] | 237 | } else if (c == '\n') { |
| 238 | *q++ = ' '; |
| 239 | } else if (iscntrl (c) && (c < 0177)) { |
| 240 | *q++ = '^'; |
| 241 | *q++ = c ^ 0100; |
| 242 | } else { |
| 243 | *q++ = c; |
| 244 | } |
| 245 | p++; |
| 246 | } |
| 247 | *q = '\0'; |
| 248 | /* Now log it */ |
| 249 | logMessage (pri, line); |
| 250 | } |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 251 | return (0); |
Pavel Roskin | da10ec0 | 2000-06-07 21:08:25 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 254 | |
| 255 | #ifdef BB_FEATURE_REMOTE_LOG |
| 256 | static void init_RemoteLog (void){ |
| 257 | |
| 258 | struct sockaddr_in remoteaddr; |
| 259 | struct hostent *hostinfo; |
| 260 | int len = sizeof(remoteaddr); |
| 261 | |
| 262 | bzero(&remoteaddr, len); |
| 263 | |
| 264 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); |
| 265 | |
| 266 | if (remotefd < 0) { |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 267 | error_msg_and_die("syslogd: cannot create socket"); |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | hostinfo = (struct hostent *) gethostbyname(RemoteHost); |
| 271 | |
| 272 | if (!hostinfo) { |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 273 | error_msg_and_die("syslogd: cannot resolve remote host name [%s]", RemoteHost); |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | remoteaddr.sin_family = AF_INET; |
| 277 | remoteaddr.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list; |
| 278 | remoteaddr.sin_port = htons(RemotePort); |
| 279 | |
| 280 | /* |
| 281 | Since we are using UDP sockets, connect just sets the default host and port |
| 282 | for future operations |
| 283 | */ |
| 284 | if ( 0 != (connect(remotefd, (struct sockaddr *) &remoteaddr, len))){ |
Matt Kraai | dd19c69 | 2001-01-31 19:00:21 +0000 | [diff] [blame] | 285 | error_msg_and_die("syslogd: cannot connect to remote host %s:%d", RemoteHost, RemotePort); |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | } |
| 289 | #endif |
| 290 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 291 | static void doSyslogd (void) __attribute__ ((noreturn)); |
| 292 | static void doSyslogd (void) |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 293 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 294 | struct sockaddr_un sunx; |
Erik Andersen | 1d1d950 | 2000-04-21 01:26:49 +0000 | [diff] [blame] | 295 | socklen_t addrLength; |
| 296 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 297 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 298 | int sock_fd; |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 299 | fd_set fds; |
| 300 | |
Eric Andersen | d35c215 | 2001-01-25 23:49:09 +0000 | [diff] [blame] | 301 | RESERVE_BB_BUFFER(lfile, BUFSIZ); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 302 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 303 | /* Set up signal handlers. */ |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 304 | signal (SIGINT, quit_signal); |
| 305 | signal (SIGTERM, quit_signal); |
| 306 | signal (SIGQUIT, quit_signal); |
| 307 | signal (SIGHUP, SIG_IGN); |
Pavel Roskin | d39d120 | 2000-09-13 14:14:29 +0000 | [diff] [blame] | 308 | signal (SIGCHLD, SIG_IGN); |
| 309 | #ifdef SIGCLD |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 310 | signal (SIGCLD, SIG_IGN); |
Pavel Roskin | d39d120 | 2000-09-13 14:14:29 +0000 | [diff] [blame] | 311 | #endif |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 312 | signal (SIGALRM, domark); |
| 313 | alarm (MarkInterval); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 314 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 315 | /* Create the syslog file so realpath() can work. */ |
| 316 | close (open (_PATH_LOG, O_RDWR | O_CREAT, 0644)); |
| 317 | if (realpath (_PATH_LOG, lfile) == NULL) |
Matt Kraai | 1fa1ade | 2000-12-18 03:57:16 +0000 | [diff] [blame] | 318 | perror_msg_and_die ("Could not resolve path to " _PATH_LOG); |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 319 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 320 | unlink (lfile); |
| 321 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 322 | memset (&sunx, 0, sizeof (sunx)); |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 323 | sunx.sun_family = AF_UNIX; |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 324 | strncpy (sunx.sun_path, lfile, sizeof (sunx.sun_path)); |
| 325 | if ((sock_fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) |
Matt Kraai | 1fa1ade | 2000-12-18 03:57:16 +0000 | [diff] [blame] | 326 | perror_msg_and_die ("Couldn't obtain descriptor for socket " _PATH_LOG); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 327 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 328 | addrLength = sizeof (sunx.sun_family) + strlen (sunx.sun_path); |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 329 | if ((bind (sock_fd, (struct sockaddr *) &sunx, addrLength)) || (listen (sock_fd, 5))) |
Matt Kraai | 1fa1ade | 2000-12-18 03:57:16 +0000 | [diff] [blame] | 330 | perror_msg_and_die ("Could not connect to socket " _PATH_LOG); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 331 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 332 | if (chmod (lfile, 0666) < 0) |
Matt Kraai | 1fa1ade | 2000-12-18 03:57:16 +0000 | [diff] [blame] | 333 | perror_msg_and_die ("Could not set permission on " _PATH_LOG); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 334 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 335 | FD_ZERO (&fds); |
| 336 | FD_SET (sock_fd, &fds); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 337 | |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 338 | #ifdef BB_FEATURE_REMOTE_LOG |
| 339 | if (doRemoteLog == TRUE){ |
| 340 | init_RemoteLog(); |
| 341 | } |
| 342 | #endif |
| 343 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 344 | logMessage (0, "syslogd started: BusyBox v" BB_VER " (" BB_BT ")"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 345 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 346 | for (;;) { |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 347 | |
| 348 | fd_set readfds; |
| 349 | int n_ready; |
| 350 | int fd; |
| 351 | |
| 352 | memcpy (&readfds, &fds, sizeof (fds)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 353 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 354 | if ((n_ready = select (FD_SETSIZE, &readfds, NULL, NULL, NULL)) < 0) { |
| 355 | if (errno == EINTR) continue; /* alarm may have happened. */ |
Matt Kraai | 1fa1ade | 2000-12-18 03:57:16 +0000 | [diff] [blame] | 356 | perror_msg_and_die ("select error"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 357 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 358 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 359 | for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) { |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 360 | if (FD_ISSET (fd, &readfds)) { |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 361 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 362 | --n_ready; |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 363 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 364 | if (fd == sock_fd) { |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 365 | |
| 366 | int conn; |
| 367 | pid_t pid; |
| 368 | |
Erik Andersen | f13df37 | 2000-04-18 23:51:51 +0000 | [diff] [blame] | 369 | if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) { |
Matt Kraai | 1fa1ade | 2000-12-18 03:57:16 +0000 | [diff] [blame] | 370 | perror_msg_and_die ("accept error"); |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 371 | } |
Erik Andersen | a6c7522 | 2000-04-18 00:00:52 +0000 | [diff] [blame] | 372 | |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 373 | pid = fork(); |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 374 | |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 375 | if (pid < 0) { |
| 376 | perror ("syslogd: fork"); |
| 377 | close (conn); |
| 378 | continue; |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 379 | } |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 380 | |
Eric Andersen | b2fc5a0 | 2000-08-20 06:11:32 +0000 | [diff] [blame] | 381 | if (pid == 0) { |
Pavel Roskin | da10ec0 | 2000-06-07 21:08:25 +0000 | [diff] [blame] | 382 | serveConnection (conn); |
Eric Andersen | b2fc5a0 | 2000-08-20 06:11:32 +0000 | [diff] [blame] | 383 | close (conn); |
| 384 | exit( TRUE); |
| 385 | } |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 386 | close (conn); |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 387 | } |
| 388 | } |
| 389 | } |
| 390 | } |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Eric Andersen | 03f4c27 | 2000-07-06 23:10:29 +0000 | [diff] [blame] | 393 | #ifdef BB_FEATURE_KLOGD |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 394 | |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 395 | static void klogd_signal(int sig) |
| 396 | { |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 397 | klogctl(7, NULL, 0); |
| 398 | klogctl(0, 0, 0); |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 399 | logMessage(0, "Kernel log daemon exiting."); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 400 | exit(TRUE); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 403 | static void doKlogd (void) __attribute__ ((noreturn)); |
| 404 | static void doKlogd (void) |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 405 | { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 406 | int priority = LOG_INFO; |
| 407 | char log_buffer[4096]; |
Eric Andersen | cf7982e | 2000-12-11 16:31:11 +0000 | [diff] [blame] | 408 | int i, n, lastc; |
| 409 | char *start; |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 410 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 411 | /* Set up sig handlers */ |
| 412 | signal(SIGINT, klogd_signal); |
| 413 | signal(SIGKILL, klogd_signal); |
| 414 | signal(SIGTERM, klogd_signal); |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 415 | signal(SIGHUP, SIG_IGN); |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 416 | |
| 417 | #ifdef BB_FEATURE_REMOTE_LOG |
| 418 | if (doRemoteLog == TRUE){ |
| 419 | init_RemoteLog(); |
| 420 | } |
| 421 | #endif |
| 422 | |
Erik Andersen | 9ffdaa6 | 2000-02-11 21:55:04 +0000 | [diff] [blame] | 423 | logMessage(0, "klogd started: " |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 424 | "BusyBox v" BB_VER " (" BB_BT ")"); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 425 | |
Eric Andersen | cf7982e | 2000-12-11 16:31:11 +0000 | [diff] [blame] | 426 | /* "Open the log. Currently a NOP." */ |
Eric Andersen | 67e3230 | 2000-06-19 17:48:02 +0000 | [diff] [blame] | 427 | klogctl(1, NULL, 0); |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 428 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 429 | while (1) { |
| 430 | /* Use kernel syscalls */ |
| 431 | memset(log_buffer, '\0', sizeof(log_buffer)); |
Eric Andersen | cf7982e | 2000-12-11 16:31:11 +0000 | [diff] [blame] | 432 | n = klogctl(2, log_buffer, sizeof(log_buffer)); |
| 433 | if (n < 0) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 434 | char message[80]; |
| 435 | |
| 436 | if (errno == EINTR) |
| 437 | continue; |
| 438 | snprintf(message, 79, "klogd: Error return from sys_sycall: " \ |
| 439 | "%d - %s.\n", errno, strerror(errno)); |
| 440 | logMessage(LOG_SYSLOG | LOG_ERR, message); |
| 441 | exit(1); |
| 442 | } |
Eric Andersen | cf7982e | 2000-12-11 16:31:11 +0000 | [diff] [blame] | 443 | |
| 444 | /* klogctl buffer parsing modelled after code in dmesg.c */ |
| 445 | start=&log_buffer[0]; |
| 446 | lastc='\0'; |
| 447 | for (i=0; i<n; i++) { |
| 448 | if (lastc == '\0' && log_buffer[i] == '<') { |
| 449 | priority = 0; |
| 450 | i++; |
| 451 | while (isdigit(log_buffer[i])) { |
| 452 | priority = priority*10+(log_buffer[i]-'0'); |
| 453 | i++; |
| 454 | } |
| 455 | if (log_buffer[i] == '>') i++; |
| 456 | start = &log_buffer[i]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 457 | } |
Eric Andersen | cf7982e | 2000-12-11 16:31:11 +0000 | [diff] [blame] | 458 | if (log_buffer[i] == '\n') { |
| 459 | log_buffer[i] = '\0'; /* zero terminate this message */ |
| 460 | logMessage(LOG_KERN | priority, start); |
| 461 | start = &log_buffer[i+1]; |
| 462 | priority = LOG_INFO; |
| 463 | } |
| 464 | lastc = log_buffer[i]; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 465 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 466 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 467 | |
| 468 | } |
| 469 | |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 470 | #endif |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 471 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 472 | static void daemon_init (char **argv, char *dz, void fn (void)) |
| 473 | { |
| 474 | setsid(); |
| 475 | chdir ("/"); |
| 476 | strncpy(argv[0], dz, strlen(argv[0])); |
| 477 | fn(); |
| 478 | exit(0); |
| 479 | } |
| 480 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 481 | extern int syslogd_main(int argc, char **argv) |
| 482 | { |
Eric Andersen | 394cf22 | 2000-12-11 16:48:50 +0000 | [diff] [blame] | 483 | int opt, pid, klogd_pid; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 484 | int doFork = TRUE; |
| 485 | |
Eric Andersen | 03f4c27 | 2000-07-06 23:10:29 +0000 | [diff] [blame] | 486 | #ifdef BB_FEATURE_KLOGD |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 487 | int startKlogd = TRUE; |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 488 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 489 | char *p; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 490 | |
Eric Andersen | 394cf22 | 2000-12-11 16:48:50 +0000 | [diff] [blame] | 491 | /* do normal option parsing */ |
| 492 | while ((opt = getopt(argc, argv, "m:nKO:R:L")) > 0) { |
| 493 | switch (opt) { |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 494 | case 'm': |
Eric Andersen | 394cf22 | 2000-12-11 16:48:50 +0000 | [diff] [blame] | 495 | MarkInterval = atoi(optarg) * 60; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 496 | break; |
| 497 | case 'n': |
| 498 | doFork = FALSE; |
| 499 | break; |
Eric Andersen | 03f4c27 | 2000-07-06 23:10:29 +0000 | [diff] [blame] | 500 | #ifdef BB_FEATURE_KLOGD |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 501 | case 'K': |
| 502 | startKlogd = FALSE; |
| 503 | break; |
| 504 | #endif |
| 505 | case 'O': |
Eric Andersen | 394cf22 | 2000-12-11 16:48:50 +0000 | [diff] [blame] | 506 | logFilePath = strdup(optarg); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 507 | break; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 508 | #ifdef BB_FEATURE_REMOTE_LOG |
| 509 | case 'R': |
Eric Andersen | 394cf22 | 2000-12-11 16:48:50 +0000 | [diff] [blame] | 510 | RemoteHost = strdup(optarg); |
| 511 | if ( (p = strchr(RemoteHost, ':'))){ |
| 512 | RemotePort = atoi(p+1); |
| 513 | *p = '\0'; |
| 514 | } |
| 515 | doRemoteLog = TRUE; |
| 516 | break; |
Eric Andersen | 70d09ed | 2000-12-11 16:24:16 +0000 | [diff] [blame] | 517 | case 'L': |
| 518 | local_logging = TRUE; |
Eric Andersen | bf2b8ae | 2000-12-08 19:52:01 +0000 | [diff] [blame] | 519 | break; |
Eric Andersen | ced2cef | 2000-07-20 23:41:24 +0000 | [diff] [blame] | 520 | #endif |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 521 | default: |
Eric Andersen | 67991cf | 2001-02-14 21:23:06 +0000 | [diff] [blame] | 522 | show_usage(); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 523 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Eric Andersen | 4ed1782 | 2000-12-11 19:28:29 +0000 | [diff] [blame] | 526 | #ifdef BB_FEATURE_REMOTE_LOG |
| 527 | /* If they have not specified remote logging, then log locally */ |
| 528 | if (doRemoteLog == FALSE) |
| 529 | local_logging = TRUE; |
| 530 | #endif |
| 531 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 532 | /* Store away localhost's name before the fork */ |
| 533 | gethostname(LocalHostName, sizeof(LocalHostName)); |
| 534 | if ((p = strchr(LocalHostName, '.'))) { |
| 535 | *p++ = '\0'; |
| 536 | } |
| 537 | |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 538 | umask(0); |
| 539 | |
Eric Andersen | 03f4c27 | 2000-07-06 23:10:29 +0000 | [diff] [blame] | 540 | #ifdef BB_FEATURE_KLOGD |
Erik Andersen | e272915 | 2000-02-18 21:34:17 +0000 | [diff] [blame] | 541 | /* Start up the klogd process */ |
| 542 | if (startKlogd == TRUE) { |
| 543 | klogd_pid = fork(); |
| 544 | if (klogd_pid == 0) { |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 545 | daemon_init (argv, "klogd", doKlogd); |
Erik Andersen | e272915 | 2000-02-18 21:34:17 +0000 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | #endif |
| 549 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 550 | if (doFork == TRUE) { |
| 551 | pid = fork(); |
| 552 | if (pid < 0) |
| 553 | exit(pid); |
| 554 | else if (pid == 0) { |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 555 | daemon_init (argv, "syslogd", doSyslogd); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 556 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 557 | } else { |
| 558 | doSyslogd(); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 559 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 560 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 561 | return EXIT_SUCCESS; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 562 | } |
Erik Andersen | 983b51b | 2000-04-04 18:14:25 +0000 | [diff] [blame] | 563 | |
| 564 | /* |
Erik Andersen | e3ed156 | 2000-04-19 18:52:56 +0000 | [diff] [blame] | 565 | Local Variables |
| 566 | c-file-style: "linux" |
| 567 | c-basic-offset: 4 |
| 568 | tab-width: 4 |
| 569 | End: |
| 570 | */ |