X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=sysklogd%2Fsyslogd.c;h=d64ff278f2b8ad5c68b9ba91c80db069a3f9cbb3;hb=31c765081dc41f158786545fbea9294be4685bd2;hp=d80447bd73ee669a108b894f47db7b33bb0c19da;hpb=a28c1b21e1a3770b83fe9b15f26ec50f2e14e7f6;p=oweals%2Fbusybox.git diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index d80447bd7..d64ff278f 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -12,6 +12,107 @@ * * Licensed under GPLv2 or later, see file LICENSE in this source tree. */ +//config:config SYSLOGD +//config: bool "syslogd" +//config: default y +//config: help +//config: The syslogd utility is used to record logs of all the +//config: significant events that occur on a system. Every +//config: message that is logged records the date and time of the +//config: event, and will generally also record the name of the +//config: application that generated the message. When used in +//config: conjunction with klogd, messages from the Linux kernel +//config: can also be recorded. This is terribly useful, +//config: especially for finding what happened when something goes +//config: wrong. And something almost always will go wrong if +//config: you wait long enough.... +//config: +//config:config FEATURE_ROTATE_LOGFILE +//config: bool "Rotate message files" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: This enables syslogd to rotate the message files +//config: on his own. No need to use an external rotate script. +//config: +//config:config FEATURE_REMOTE_LOG +//config: bool "Remote Log support" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: When you enable this feature, the syslogd utility can +//config: be used to send system log messages to another system +//config: connected via a network. This allows the remote +//config: machine to log all the system messages, which can be +//config: terribly useful for reducing the number of serial +//config: cables you use. It can also be a very good security +//config: measure to prevent system logs from being tampered with +//config: by an intruder. +//config: +//config:config FEATURE_SYSLOGD_DUP +//config: bool "Support -D (drop dups) option" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: Option -D instructs syslogd to drop consecutive messages +//config: which are totally the same. +//config: +//config:config FEATURE_SYSLOGD_CFG +//config: bool "Support syslog.conf" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: Supports restricted syslogd config. See docs/syslog.conf.txt +//config: +//config:config FEATURE_SYSLOGD_READ_BUFFER_SIZE +//config: int "Read buffer size in bytes" +//config: default 256 +//config: range 256 20000 +//config: depends on SYSLOGD +//config: help +//config: This option sets the size of the syslog read buffer. +//config: Actual memory usage increases around five times the +//config: change done here. +//config: +//config:config FEATURE_IPC_SYSLOG +//config: bool "Circular Buffer support" +//config: default y +//config: depends on SYSLOGD +//config: help +//config: When you enable this feature, the syslogd utility will +//config: use a circular buffer to record system log messages. +//config: When the buffer is filled it will continue to overwrite +//config: the oldest messages. This can be very useful for +//config: systems with little or no permanent storage, since +//config: otherwise system logs can eventually fill up your +//config: entire filesystem, which may cause your system to +//config: break badly. +//config: +//config:config FEATURE_IPC_SYSLOG_BUFFER_SIZE +//config: int "Circular buffer size in Kbytes (minimum 4KB)" +//config: default 16 +//config: range 4 2147483647 +//config: depends on FEATURE_IPC_SYSLOG +//config: help +//config: This option sets the size of the circular buffer +//config: used to record system log messages. +//config: +//config:config FEATURE_KMSG_SYSLOG +//config: bool "Linux kernel printk buffer support" +//config: default y +//config: depends on SYSLOGD +//config: select PLATFORM_LINUX +//config: help +//config: When you enable this feature, the syslogd utility will +//config: write system log message to the Linux kernel's printk buffer. +//config: This can be used as a smaller alternative to the syslogd IPC +//config: support, as klogd and logread aren't needed. +//config: +//config: NOTICE: Syslog facilities in log entries needs kernel 3.5+. + +//applet:IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP)) + +//kbuild:lib-$(CONFIG_SYSLOGD) += syslogd_and_logger.o //usage:#define syslogd_trivial_usage //usage: "[OPTIONS]" @@ -32,10 +133,10 @@ //usage: IF_FEATURE_KMSG_SYSLOG( //usage: "\n -K Log to kernel printk buffer (use dmesg to read it)" //usage: ) -//usage: "\n -O FILE Log to FILE (default:/var/log/messages, stdout if -)" +//usage: "\n -O FILE Log to FILE (default: /var/log/messages, stdout if -)" //usage: IF_FEATURE_ROTATE_LOGFILE( -//usage: "\n -s SIZE Max size (KB) before rotation (default:200KB, 0=off)" -//usage: "\n -b N N rotated logs to keep (default:1, max=99, 0=purge)" +//usage: "\n -s SIZE Max size (KB) before rotation (default 200KB, 0=off)" +//usage: "\n -b N N rotated logs to keep (default 1, max 99, 0=purge)" //usage: ) //usage: "\n -l N Log only messages more urgent than prio N (1-8)" //usage: "\n -S Smaller output" @@ -45,7 +146,7 @@ //usage: IF_FEATURE_SYSLOGD_CFG( //usage: "\n -f FILE Use FILE as config (default:/etc/syslog.conf)" //usage: ) -/* //usage: "\n -m MIN Minutes between MARK lines (default:20, 0=off)" */ +/* //usage: "\n -m MIN Minutes between MARK lines (default 20, 0=off)" */ //usage: //usage:#define syslogd_example_usage //usage: "$ syslogd -R masterlog:514\n" @@ -110,6 +211,7 @@ typedef struct { typedef struct logFile_t { const char *path; int fd; + time_t last_log_time; #if ENABLE_FEATURE_ROTATE_LOGFILE unsigned size; uint8_t isRegular; @@ -165,7 +267,6 @@ struct globals { #if ENABLE_FEATURE_IPC_SYSLOG struct shbuf_ds *shbuf; #endif - time_t last_log_time; /* localhost's name. We print only first 64 chars */ char *hostname; @@ -237,12 +338,11 @@ enum { OPT_dup = IF_FEATURE_SYSLOGD_DUP( (1 << OPTBIT_dup )) + 0, OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0, - }; #define OPTION_STR "m:nO:l:S" \ IF_FEATURE_ROTATE_LOGFILE("s:" ) \ IF_FEATURE_ROTATE_LOGFILE("b:" ) \ - IF_FEATURE_REMOTE_LOG( "R:" ) \ + IF_FEATURE_REMOTE_LOG( "R:*") \ IF_FEATURE_REMOTE_LOG( "L" ) \ IF_FEATURE_IPC_SYSLOG( "C::") \ IF_FEATURE_SYSLOGD_DUP( "D" ) \ @@ -569,7 +669,7 @@ static void log_to_kmsg(int pri, const char *msg) */ pri &= G.primask; - write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); + full_write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); } #else static void kmsg_init(void) {} @@ -588,15 +688,16 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file) /* fd can't be 0 (we connect fd 0 to /dev/log socket) */ /* fd is 1 if "-O -" is in use */ if (log_file->fd > 1) { - /* Reopen log file every second. This allows admin - * to delete the file and not worry about restarting us. + /* Reopen log files every second. This allows admin + * to delete the files and not worry about restarting us. * This costs almost nothing since it happens - * _at most_ once a second. + * _at most_ once a second for each file, and happens + * only when each file is actually written. */ if (!now) now = time(NULL); - if (G.last_log_time != now) { - G.last_log_time = now; + if (log_file->last_log_time != now) { + log_file->last_log_time = now; close(log_file->fd); goto reopen; } @@ -678,9 +779,14 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file) close(log_file->fd); goto reopen; } - log_file->size += +/* TODO: what to do on write errors ("disk full")? */ + len = full_write(log_file->fd, msg, len); + if (len > 0) + log_file->size += len; +#else + full_write(log_file->fd, msg, len); #endif - full_write(log_file->fd, msg, len); + #ifdef SYSLOGD_WRLOCK fl.l_type = F_UNLCK; fcntl(log_file->fd, F_SETLKW, &fl); @@ -830,11 +936,6 @@ static NOINLINE int create_socket(void) int sock_fd; char *dev_log_name; -#if ENABLE_FEATURE_SYSTEMD - if (sd_listen_fds() == 1) - return SD_LISTEN_FDS_START; -#endif - memset(&sunx, 0, sizeof(sunx)); sunx.sun_family = AF_UNIX; @@ -1007,8 +1108,8 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv) INIT_G(); - /* No non-option params, -R can occur multiple times */ - opt_complementary = "=0" IF_FEATURE_REMOTE_LOG(":R::"); + /* No non-option params */ + opt_complementary = "=0"; opts = getopt32(argv, OPTION_STR, OPTION_PARAM); #if ENABLE_FEATURE_REMOTE_LOG while (remoteAddrList) {