* Changes: Made this a standalone busybox module which uses standalone
* syslog() client interface.
*
- * Copyright (C) 1999,2000,2001 by Lineo, inc.
- * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
+ * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
+ * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
*
* Copyright (C) 2000 by Karl M. Hegbloom <karlheg@debian.org>
*
#include <stdio.h>
#include <stdlib.h>
-#include <signal.h> /* for our signal() handlers */
-#include <string.h> /* strncpy() */
-#include <errno.h> /* errno and friends */
+#include <signal.h> /* for our signal() handlers */
+#include <string.h> /* strncpy() */
+#include <errno.h> /* errno and friends */
#include <unistd.h>
#include <ctype.h>
#include <sys/syslog.h>
-#if ! defined __GLIBC__ && ! defined __UCLIBC__
-#include <sys/syscall.h>
-#include <linux/unistd.h>
-
-#ifndef __alpha__
-# define __NR_klogctl __NR_syslog
-static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
-#else /* __alpha__ */
-#define klogctl syslog
-#endif
-
+#if __GNU_LIBRARY__ < 5
+# ifdef __alpha__
+# define klogctl syslog
+# endif
#else
# include <sys/klog.h>
#endif
+
#include "busybox.h"
static void klogd_signal(int sig)
{
klogctl(7, NULL, 0);
klogctl(0, 0, 0);
- //logMessage(0, "Kernel log daemon exiting.");
- syslog_msg(LOG_DAEMON, 0, "Kernel log daemon exiting.");
+ /* logMessage(0, "Kernel log daemon exiting."); */
+ syslog_msg(LOG_SYSLOG, LOG_NOTICE, "Kernel log daemon exiting.");
exit(TRUE);
}
-static void doKlogd (void) __attribute__ ((noreturn));
-static void doKlogd (void)
+static void doKlogd(void) __attribute__ ((noreturn));
+static void doKlogd(void)
{
int priority = LOG_INFO;
char log_buffer[4096];
/* "Open the log. Currently a NOP." */
klogctl(1, NULL, 0);
- syslog_msg(LOG_DAEMON, 0, "klogd started: BusyBox v" BB_VER " (" BB_BT ")");
+ syslog_msg(LOG_SYSLOG, LOG_NOTICE, "klogd started: " BB_BANNER);
while (1) {
/* Use kernel syscalls */
if (errno == EINTR)
continue;
- snprintf(message, 79, "klogd: Error return from sys_sycall: %d - %s.\n",
- errno, strerror(errno));
- syslog_msg(LOG_DAEMON, LOG_SYSLOG | LOG_ERR, message);
+ snprintf(message, 79,
+ "klogd: Error return from sys_sycall: %d - %s.\n", errno,
+ strerror(errno));
+ syslog_msg(LOG_SYSLOG, LOG_ERR, message);
exit(1);
}
/* klogctl buffer parsing modelled after code in dmesg.c */
- start=&log_buffer[0];
- lastc='\0';
- for (i=0; i<n; i++) {
+ start = &log_buffer[0];
+ lastc = '\0';
+ for (i = 0; i < n; i++) {
if (lastc == '\0' && log_buffer[i] == '<') {
priority = 0;
i++;
while (isdigit(log_buffer[i])) {
- priority = priority*10+(log_buffer[i]-'0');
+ priority = priority * 10 + (log_buffer[i] - '0');
i++;
}
- if (log_buffer[i] == '>') i++;
+ if (log_buffer[i] == '>')
+ i++;
start = &log_buffer[i];
}
if (log_buffer[i] == '\n') {
- log_buffer[i] = '\0'; /* zero terminate this message */
- syslog_msg(LOG_DAEMON, LOG_KERN | priority, start);
- start = &log_buffer[i+1];
+ log_buffer[i] = '\0'; /* zero terminate this message */
+ syslog_msg(LOG_KERN, priority, start);
+ start = &log_buffer[i + 1];
priority = LOG_INFO;
}
lastc = log_buffer[i];
}
}
-static void daemon_init (char **argv, char *dz, void fn (void))
-{
- setsid(); /* start a new session? */
- strncpy(argv[0], dz, strlen(argv[0]));
- fn();
- exit(0);
-}
-
extern int klogd_main(int argc, char **argv)
{
/* no options, no getopt */
- int opt, pid;
+ int opt;
int doFork = TRUE;
/* do normal option parsing */
while ((opt = getopt(argc, argv, "n")) > 0) {
switch (opt) {
- case 'n':
- doFork = FALSE;
- break;
- default:
- show_usage();
+ case 'n':
+ doFork = FALSE;
+ break;
+ default:
+ show_usage();
}
}
- if (doFork == TRUE) {
- pid = fork();
- if (pid < 0)
- exit(pid);
- else if (pid == 0) {
- daemon_init (argv, "klogd", doKlogd);
- }
- } else {
- doKlogd();
+ if (doFork) {
+#if !defined(__UCLIBC__) || defined(__UCLIBC_HAS_MMU__)
+ if (daemon(0, 1) < 0)
+ perror_msg_and_die("daemon");
+#else
+ error_msg_and_die("daemon not supported");
+#endif
}
-
+ doKlogd();
+
return EXIT_SUCCESS;
}