Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mini syslogd implementation for busybox |
| 3 | * |
| 4 | * Copyright (C) 1999 by Lineo, inc. |
| 5 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | * |
| 21 | */ |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 22 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 23 | #include "internal.h" |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 24 | #include <stdio.h> |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 25 | #include <stdarg.h> |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 26 | #include <sys/socket.h> |
| 27 | #include <sys/un.h> |
| 28 | #include <unistd.h> |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 29 | #include <time.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/stat.h> |
| 32 | #include <fcntl.h> |
| 33 | #include <signal.h> |
| 34 | #include <ctype.h> |
| 35 | #include <netdb.h> |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 36 | #include <sys/klog.h> |
| 37 | #include <errno.h> |
| 38 | #include <paths.h> |
| 39 | |
| 40 | #define ksyslog klogctl |
| 41 | extern int ksyslog(int type, char *buf, int len); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 42 | |
| 43 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 44 | /* SYSLOG_NAMES defined to pull some extra junk from syslog.h */ |
| 45 | #define SYSLOG_NAMES |
| 46 | #include <sys/syslog.h> |
| 47 | |
| 48 | /* Path for the file where all log messages are written */ |
| 49 | #define __LOG_FILE "/var/log/messages" |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 50 | |
| 51 | |
| 52 | static char* logFilePath = __LOG_FILE; |
| 53 | /* interval between marks in seconds */ |
| 54 | static int MarkInterval = 20*60; |
| 55 | /* localhost's name */ |
| 56 | static char LocalHostName[32]; |
| 57 | |
| 58 | static const char syslogd_usage[] = |
| 59 | "syslogd [OPTION]...\n\n" |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 60 | "Linux system and kernel (provides klogd) logging utility.\n" |
| 61 | "Note that this version of syslogd/klogd ignores /etc/syslog.conf.\n\n" |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 62 | "Options:\n" |
| 63 | "\t-m\tChange the mark timestamp interval. default=20min. 0=off\n" |
| 64 | "\t-n\tDo not fork into the background (for when run by init)\n" |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 65 | #ifdef BB_KLOGD |
| 66 | "\t-K\tDo not start up the klogd process (by default syslogd spawns klogd).\n" |
| 67 | #endif |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 68 | "\t-O\tSpecify an alternate log file. default=/var/log/messages\n"; |
| 69 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 70 | |
| 71 | /* try to open up the specified device */ |
| 72 | static int device_open(char *device, int mode) |
| 73 | { |
| 74 | int m, f, fd = -1; |
| 75 | |
| 76 | m = mode | O_NONBLOCK; |
| 77 | |
| 78 | /* Retry up to 5 times */ |
| 79 | for (f = 0; f < 5; f++) |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 80 | if ((fd = open(device, m, 0600)) >= 0) |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 81 | break; |
| 82 | if (fd < 0) |
| 83 | return fd; |
| 84 | /* Reset original flags. */ |
| 85 | if (m != mode) |
| 86 | fcntl(fd, F_SETFL, mode); |
| 87 | return fd; |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 90 | /* print a message to the log file */ |
| 91 | static void message(char *fmt, ...) |
| 92 | { |
| 93 | int fd; |
| 94 | va_list arguments; |
| 95 | |
| 96 | if ((fd = device_open(logFilePath, O_WRONLY|O_CREAT|O_NOCTTY|O_APPEND|O_NONBLOCK)) >= 0) { |
| 97 | va_start(arguments, fmt); |
| 98 | vdprintf(fd, fmt, arguments); |
| 99 | va_end(arguments); |
| 100 | close(fd); |
| 101 | } else { |
| 102 | /* Always send console messages to /dev/console so people will see them. */ |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 103 | if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NONBLOCK)) >= 0) { |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 104 | va_start(arguments, fmt); |
| 105 | vdprintf(fd, fmt, arguments); |
| 106 | va_end(arguments); |
| 107 | close(fd); |
| 108 | } else { |
| 109 | fprintf(stderr, "Bummer, can't print: "); |
| 110 | va_start(arguments, fmt); |
| 111 | vfprintf(stderr, fmt, arguments); |
| 112 | fflush(stderr); |
| 113 | va_end(arguments); |
| 114 | } |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 115 | } |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 118 | static void logMessage( int pri, char* msg) |
| 119 | { |
| 120 | time_t now; |
| 121 | char *timestamp; |
| 122 | static char res[20]; |
| 123 | CODE *c_pri, *c_fac; |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 124 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 125 | for (c_fac=facilitynames; c_fac->c_name && !(c_fac->c_val==LOG_FAC(pri)<<3); c_fac++); |
| 126 | for (c_pri=prioritynames; c_pri->c_name && !(c_pri->c_val==LOG_PRI(pri)); c_pri++); |
| 127 | if (*c_fac->c_name=='\0' || *c_pri->c_name=='\0') |
| 128 | snprintf (res, sizeof(res), "<%d>", pri); |
| 129 | else |
| 130 | snprintf (res, sizeof(res), "%s.%s", c_fac->c_name, c_pri->c_name); |
| 131 | |
| 132 | if (strlen(msg) < 16 || msg[3] != ' ' || msg[6] != ' ' || |
| 133 | msg[9] != ':' || msg[12] != ':' || msg[15] != ' ') |
| 134 | { |
| 135 | time(&now); |
| 136 | timestamp = ctime(&now) + 4; |
| 137 | timestamp[15] = '\0'; |
| 138 | } else { |
| 139 | timestamp = msg; |
| 140 | timestamp[15] = '\0'; |
| 141 | msg += 16; |
| 142 | } |
| 143 | |
| 144 | /* todo: supress duplicates */ |
| 145 | |
| 146 | /* now spew out the message to wherever it is supposed to go */ |
| 147 | message( "%s %s %s %s\n", timestamp, LocalHostName, res, msg); |
| 148 | } |
| 149 | |
| 150 | static void quit_signal(int sig) |
| 151 | { |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 152 | logMessage(LOG_SYSLOG|LOG_INFO, "System log daemon exiting."); |
| 153 | unlink( _PATH_LOG); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 154 | exit( TRUE); |
| 155 | } |
| 156 | |
| 157 | static void restart_signal(int sig) |
| 158 | { |
| 159 | /* pretend to restart */ |
| 160 | logMessage(LOG_SYSLOG|LOG_INFO, "syslogd restarting"); |
| 161 | } |
| 162 | |
| 163 | static void domark(int sig) |
| 164 | { |
| 165 | if (MarkInterval > 0) { |
| 166 | logMessage(LOG_SYSLOG|LOG_INFO, "-- MARK --"); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 167 | alarm(MarkInterval); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | static void doSyslogd(void) |
| 172 | { |
| 173 | struct sockaddr_un sunx; |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 174 | int fd, conn; |
| 175 | size_t addrLength; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 176 | char buf[1024]; |
| 177 | char *q, *p = buf; |
| 178 | int readSize; |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 179 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 180 | /* Set up sig handlers */ |
| 181 | signal(SIGINT, quit_signal); |
| 182 | signal(SIGTERM, quit_signal); |
| 183 | signal(SIGQUIT, quit_signal); |
| 184 | signal(SIGHUP, restart_signal); |
| 185 | signal(SIGALRM, domark); |
| 186 | alarm(MarkInterval); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 187 | |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 188 | /* Remove any preexisting socket/file */ |
| 189 | unlink(_PATH_LOG); |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 190 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 191 | memset(&sunx, 0, sizeof(sunx)); |
| 192 | sunx.sun_family = AF_UNIX; /* Unix domain socket */ |
| 193 | strncpy(sunx.sun_path, _PATH_LOG, sizeof(sunx.sun_path)); |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 194 | if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0 ) { |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 195 | perror("Couldn't obtain descriptor for socket " _PATH_LOG); |
| 196 | exit( FALSE); |
| 197 | } |
| 198 | |
| 199 | addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); |
| 200 | if ( (bind(fd, (struct sockaddr *) &sunx, addrLength)) || |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 201 | (listen(fd, 5)) ) |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 202 | { |
| 203 | perror("Could not connect to socket " _PATH_LOG); |
| 204 | exit( FALSE); |
| 205 | } |
| 206 | |
Erik Andersen | fac10d7 | 2000-02-07 05:29:42 +0000 | [diff] [blame] | 207 | umask(0); |
| 208 | if (chmod(_PATH_LOG, 0666) < 0) { |
| 209 | perror("Could not set permission on " _PATH_LOG); |
| 210 | exit (FALSE); |
| 211 | } |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 212 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 213 | logMessage(LOG_SYSLOG|LOG_INFO, "syslogd started: " |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 214 | "BusyBox v" BB_VER " (" BB_BT ")"); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 215 | |
| 216 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 217 | while ((conn = accept(fd, (struct sockaddr *) &sunx, |
| 218 | &addrLength)) >= 0) |
| 219 | { |
| 220 | while ((readSize=read(conn, buf, sizeof(buf))) > 0) |
| 221 | { |
| 222 | char line[1025]; |
| 223 | unsigned char c; |
| 224 | int pri = (LOG_USER|LOG_NOTICE); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 225 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 226 | memset (line, 0, sizeof(line)); |
| 227 | p = buf; |
| 228 | q = line; |
| 229 | while ( p && (c = *p) && q < &line[sizeof(line) - 1]) { |
| 230 | if (c == '<') { |
| 231 | /* Parse the magic priority number */ |
| 232 | pri = 0; |
| 233 | while (isdigit(*(++p))) { |
| 234 | pri = 10 * pri + (*p - '0'); |
| 235 | } |
| 236 | if (pri &~ (LOG_FACMASK|LOG_PRIMASK)) |
| 237 | pri = (LOG_USER|LOG_NOTICE); |
| 238 | } else if (c == '\n') { |
| 239 | *q++ = ' '; |
| 240 | } else if (iscntrl(c)&&(c<0177)) { |
| 241 | *q++ = '^'; |
| 242 | *q++ = c ^ 0100; |
| 243 | } else { |
| 244 | *q++ = c; |
| 245 | } |
| 246 | p++; |
| 247 | } |
| 248 | *q = '\0'; |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 249 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 250 | /* Now log it */ |
| 251 | logMessage( pri, line); |
| 252 | } |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 253 | close(conn); |
| 254 | } |
| 255 | |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 256 | close(fd); |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 259 | #ifdef BB_KLOGD |
| 260 | |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 261 | static void klogd_signal(int sig) |
| 262 | { |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 263 | ksyslog(7, NULL, 0); |
| 264 | ksyslog(0, 0, 0); |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 265 | logMessage(LOG_SYSLOG|LOG_INFO, "Kernel log daemon exiting."); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 266 | exit( TRUE); |
| 267 | } |
| 268 | |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 269 | static void doKlogd(void) |
| 270 | { |
| 271 | int priority=LOG_INFO; |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 272 | char log_buffer[4096]; |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 273 | char *logp; |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 274 | |
| 275 | /* Set up sig handlers */ |
| 276 | signal(SIGINT, klogd_signal); |
| 277 | signal(SIGKILL, klogd_signal); |
| 278 | signal(SIGTERM, klogd_signal); |
| 279 | signal(SIGHUP, klogd_signal); |
| 280 | logMessage(LOG_SYSLOG|LOG_INFO, "klogd started: " |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 281 | "BusyBox v" BB_VER " (" BB_BT ")"); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 282 | |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 283 | ksyslog(1, NULL, 0); |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 284 | |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 285 | while (1) { |
Eric Andersen | 0ecb54a | 1999-12-05 23:24:55 +0000 | [diff] [blame] | 286 | /* Use kernel syscalls */ |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 287 | memset(log_buffer, '\0', sizeof(log_buffer)); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 288 | if ( ksyslog(2, log_buffer, sizeof(log_buffer)) < 0 ) { |
| 289 | char message[80]; |
| 290 | if ( errno == EINTR ) |
| 291 | continue; |
| 292 | snprintf(message, 79, "klogd: Error return from sys_sycall: " \ |
| 293 | "%d - %s.\n", errno, strerror(errno)); |
| 294 | logMessage(LOG_SYSLOG|LOG_ERR, message); |
| 295 | exit(1); |
| 296 | } |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 297 | logp=log_buffer; |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 298 | if ( *log_buffer == '<' ) |
| 299 | { |
| 300 | switch ( *(log_buffer+1) ) |
| 301 | { |
| 302 | case '0': |
| 303 | priority = LOG_EMERG; |
| 304 | break; |
| 305 | case '1': |
| 306 | priority = LOG_ALERT; |
| 307 | break; |
| 308 | case '2': |
| 309 | priority = LOG_CRIT; |
| 310 | break; |
| 311 | case '3': |
| 312 | priority = LOG_ERR; |
| 313 | break; |
| 314 | case '4': |
| 315 | priority = LOG_WARNING; |
| 316 | break; |
| 317 | case '5': |
| 318 | priority = LOG_NOTICE; |
| 319 | break; |
| 320 | case '6': |
| 321 | priority = LOG_INFO; |
| 322 | break; |
| 323 | case '7': |
| 324 | default: |
| 325 | priority = LOG_DEBUG; |
| 326 | } |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 327 | logp+=3; |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 328 | } |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 329 | logMessage(LOG_KERN|priority, logp); |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | } |
| 333 | |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 334 | #endif |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 335 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 336 | extern int syslogd_main(int argc, char **argv) |
| 337 | { |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 338 | int pid, klogd_pid; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 339 | int doFork = TRUE; |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 340 | #ifdef BB_KLOGD |
| 341 | int startKlogd = TRUE; |
| 342 | #endif |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 343 | int stopDoingThat = FALSE; |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 344 | char *p; |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 345 | char **argv1=argv; |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 346 | |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 347 | while (--argc > 0 && **(++argv1) == '-') { |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 348 | stopDoingThat = FALSE; |
| 349 | while (stopDoingThat == FALSE && *(++(*argv1))) { |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 350 | switch (**argv1) { |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 351 | case 'm': |
| 352 | if (--argc == 0) { |
| 353 | usage(syslogd_usage); |
| 354 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 355 | MarkInterval = atoi(*(++argv1))*60; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 356 | break; |
| 357 | case 'n': |
| 358 | doFork = FALSE; |
| 359 | break; |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 360 | #ifdef BB_KLOGD |
| 361 | case 'K': |
| 362 | startKlogd = FALSE; |
| 363 | break; |
| 364 | #endif |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 365 | case 'O': |
| 366 | if (--argc == 0) { |
| 367 | usage(syslogd_usage); |
| 368 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 369 | logFilePath = *(++argv1); |
Erik Andersen | 05df239 | 2000-01-13 04:43:48 +0000 | [diff] [blame] | 370 | stopDoingThat = TRUE; |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 371 | break; |
| 372 | default: |
| 373 | usage(syslogd_usage); |
| 374 | } |
| 375 | } |
| 376 | } |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 377 | |
| 378 | /* Store away localhost's name before the fork */ |
| 379 | gethostname(LocalHostName, sizeof(LocalHostName)); |
| 380 | if ( (p = strchr(LocalHostName, '.')) ) { |
| 381 | *p++ = '\0'; |
| 382 | } |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 383 | |
| 384 | if (doFork == TRUE) { |
| 385 | pid = fork(); |
| 386 | if ( pid < 0 ) |
| 387 | exit( pid); |
| 388 | else if ( pid == 0 ) { |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 389 | strncpy(argv[0], "syslogd",strlen(argv[0])); |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 390 | doSyslogd(); |
| 391 | } |
| 392 | } else { |
| 393 | doSyslogd(); |
| 394 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 395 | |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 396 | #ifdef BB_KLOGD |
Eric Andersen | 14ec6cf | 1999-12-05 22:17:02 +0000 | [diff] [blame] | 397 | /* Start up the klogd process */ |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 398 | if (startKlogd == TRUE) { |
| 399 | klogd_pid = fork(); |
| 400 | if (klogd_pid == 0 ) { |
| 401 | strncpy(argv[0], "klogd", strlen(argv[0])); |
| 402 | doKlogd(); |
| 403 | } |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 404 | } |
Eric Andersen | 2cb5507 | 1999-12-10 08:25:07 +0000 | [diff] [blame] | 405 | #endif |
Eric Andersen | b186d98 | 1999-12-03 09:19:54 +0000 | [diff] [blame] | 406 | |
Eric Andersen | 3843e96 | 1999-11-25 07:30:46 +0000 | [diff] [blame] | 407 | exit( TRUE); |
| 408 | } |
| 409 | |
Eric Andersen | b99df0f | 1999-11-24 09:04:33 +0000 | [diff] [blame] | 410 | |