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