Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/sysklogd
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (9 years ago)
- Location:
- branches/3.3
- Files:
-
- 7 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/sysklogd/Config.src
r3232 r3621 8 8 INSERT 9 9 10 config SYSLOGD11 bool "syslogd"12 default y13 help14 The syslogd utility is used to record logs of all the15 significant events that occur on a system. Every16 message that is logged records the date and time of the17 event, and will generally also record the name of the18 application that generated the message. When used in19 conjunction with klogd, messages from the Linux kernel20 can also be recorded. This is terribly useful,21 especially for finding what happened when something goes22 wrong. And something almost always will go wrong if23 you wait long enough....24 25 config FEATURE_ROTATE_LOGFILE26 bool "Rotate message files"27 default y28 depends on SYSLOGD29 help30 This enables syslogd to rotate the message files31 on his own. No need to use an external rotatescript.32 33 config FEATURE_REMOTE_LOG34 bool "Remote Log support"35 default y36 depends on SYSLOGD37 help38 When you enable this feature, the syslogd utility can39 be used to send system log messages to another system40 connected via a network. This allows the remote41 machine to log all the system messages, which can be42 terribly useful for reducing the number of serial43 cables you use. It can also be a very good security44 measure to prevent system logs from being tampered with45 by an intruder.46 47 config FEATURE_SYSLOGD_DUP48 bool "Support -D (drop dups) option"49 default y50 depends on SYSLOGD51 help52 Option -D instructs syslogd to drop consecutive messages53 which are totally the same.54 55 config FEATURE_SYSLOGD_CFG56 bool "Support syslog.conf"57 default y58 depends on SYSLOGD59 help60 Supports restricted syslogd config. See docs/syslog.conf.txt61 62 config FEATURE_SYSLOGD_READ_BUFFER_SIZE63 int "Read buffer size in bytes"64 default 25665 range 256 2000066 depends on SYSLOGD67 help68 This option sets the size of the syslog read buffer.69 Actual memory usage increases around five times the70 change done here.71 72 config FEATURE_IPC_SYSLOG73 bool "Circular Buffer support"74 default y75 depends on SYSLOGD76 help77 When you enable this feature, the syslogd utility will78 use a circular buffer to record system log messages.79 When the buffer is filled it will continue to overwrite80 the oldest messages. This can be very useful for81 systems with little or no permanent storage, since82 otherwise system logs can eventually fill up your83 entire filesystem, which may cause your system to84 break badly.85 86 config FEATURE_IPC_SYSLOG_BUFFER_SIZE87 int "Circular buffer size in Kbytes (minimum 4KB)"88 default 1689 range 4 214748364790 depends on FEATURE_IPC_SYSLOG91 help92 This option sets the size of the circular buffer93 used to record system log messages.94 95 config LOGREAD96 bool "logread"97 default y98 depends on FEATURE_IPC_SYSLOG99 help100 If you enabled Circular Buffer support, you almost101 certainly want to enable this feature as well. This102 utility will allow you to read the messages that are103 stored in the syslogd circular buffer.104 105 config FEATURE_LOGREAD_REDUCED_LOCKING106 bool "Double buffering"107 default y108 depends on LOGREAD109 help110 'logread' ouput to slow serial terminals can have111 side effects on syslog because of the semaphore.112 This option make logread to double buffer copy113 from circular buffer, minimizing semaphore114 contention at some minor memory expense.115 116 config FEATURE_KMSG_SYSLOG117 bool "Linux kernel printk buffer support"118 default y119 depends on SYSLOGD120 select PLATFORM_LINUX121 help122 When you enable this feature, the syslogd utility will123 write system log message to the Linux kernel's printk buffer.124 This can be used as a smaller alternative to the syslogd IPC125 support, as klogd and logread aren't needed.126 127 NOTICE: Syslog facilities in log entries needs kernel 3.5+.128 129 config KLOGD130 bool "klogd"131 default y132 help133 klogd is a utility which intercepts and logs all134 messages from the Linux kernel and sends the messages135 out to the 'syslogd' utility so they can be logged. If136 you wish to record the messages produced by the kernel,137 you should enable this option.138 139 comment "klogd should not be used together with syslog to kernel printk buffer"140 depends on KLOGD && FEATURE_KMSG_SYSLOG141 142 config FEATURE_KLOGD_KLOGCTL143 bool "Use the klogctl() interface"144 default y145 depends on KLOGD146 select PLATFORM_LINUX147 help148 The klogd applet supports two interfaces for reading149 kernel messages. Linux provides the klogctl() interface150 which allows reading messages from the kernel ring buffer151 independently from the file system.152 153 If you answer 'N' here, klogd will use the more portable154 approach of reading them from /proc or a device node.155 However, this method requires the file to be available.156 157 If in doubt, say 'Y'.158 159 config LOGGER160 bool "logger"161 default y162 select FEATURE_SYSLOG163 help164 The logger utility allows you to send arbitrary text165 messages to the system log (i.e. the 'syslogd' utility) so166 they can be logged. This is generally used to help locate167 problems that occur within programs and scripts.168 169 10 endmenu -
branches/3.3/mindi-busybox/sysklogd/Kbuild.src
r2725 r3621 8 8 9 9 INSERT 10 lib-$(CONFIG_KLOGD) += klogd.o11 lib-$(CONFIG_LOGGER) += syslogd_and_logger.o12 lib-$(CONFIG_LOGREAD) += logread.o13 lib-$(CONFIG_SYSLOGD) += syslogd_and_logger.o -
branches/3.3/mindi-busybox/sysklogd/klogd.c
r3232 r3621 17 17 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 18 18 */ 19 //config:config KLOGD 20 //config: bool "klogd" 21 //config: default y 22 //config: help 23 //config: klogd is a utility which intercepts and logs all 24 //config: messages from the Linux kernel and sends the messages 25 //config: out to the 'syslogd' utility so they can be logged. If 26 //config: you wish to record the messages produced by the kernel, 27 //config: you should enable this option. 28 //config: 29 //config:comment "klogd should not be used together with syslog to kernel printk buffer" 30 //config: depends on KLOGD && FEATURE_KMSG_SYSLOG 31 //config: 32 //config:config FEATURE_KLOGD_KLOGCTL 33 //config: bool "Use the klogctl() interface" 34 //config: default y 35 //config: depends on KLOGD 36 //config: select PLATFORM_LINUX 37 //config: help 38 //config: The klogd applet supports two interfaces for reading 39 //config: kernel messages. Linux provides the klogctl() interface 40 //config: which allows reading messages from the kernel ring buffer 41 //config: independently from the file system. 42 //config: 43 //config: If you answer 'N' here, klogd will use the more portable 44 //config: approach of reading them from /proc or a device node. 45 //config: However, this method requires the file to be available. 46 //config: 47 //config: If in doubt, say 'Y'. 48 49 //applet:IF_KLOGD(APPLET(klogd, BB_DIR_SBIN, BB_SUID_DROP)) 50 51 //kbuild:lib-$(CONFIG_KLOGD) += klogd.o 19 52 20 53 //usage:#define klogd_trivial_usage … … 26 59 27 60 #include "libbb.h" 61 #include "common_bufsiz.h" 28 62 #include <syslog.h> 29 63 … … 66 100 #else 67 101 68 # include <paths.h>69 102 # ifndef _PATH_KLOG 70 103 # ifdef __GNU__ … … 116 149 #define log_buffer bb_common_bufsiz1 117 150 enum { 118 KLOGD_LOGBUF_SIZE = sizeof(log_buffer),151 KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE, 119 152 OPT_LEVEL = (1 << 0), 120 153 OPT_FOREGROUND = (1 << 1), … … 141 174 int opt; 142 175 int used; 176 177 setup_common_bufsiz(); 143 178 144 179 opt = getopt32(argv, "c:n", &opt_c); -
branches/3.3/mindi-busybox/sysklogd/logger.c
r3232 r3621 7 7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 //config:config LOGGER 10 //config: bool "logger" 11 //config: default y 12 //config: select FEATURE_SYSLOG 13 //config: help 14 //config: The logger utility allows you to send arbitrary text 15 //config: messages to the system log (i.e. the 'syslogd' utility) so 16 //config: they can be logged. This is generally used to help locate 17 //config: problems that occur within programs and scripts. 18 19 //applet:IF_LOGGER(APPLET(logger, BB_DIR_USR_BIN, BB_SUID_DROP)) 20 21 //kbuild:lib-$(CONFIG_LOGGER) += syslogd_and_logger.o 9 22 10 23 //usage:#define logger_trivial_usage … … 87 100 int i = 0; 88 101 102 setup_common_bufsiz(); 103 89 104 /* Fill out the name string early (may be overwritten later) */ 90 105 str_t = uid2uname_utoa(geteuid()); -
branches/3.3/mindi-busybox/sysklogd/logread.c
r3232 r3621 9 9 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 10 */ 11 //config:config LOGREAD 12 //config: bool "logread" 13 //config: default y 14 //config: depends on FEATURE_IPC_SYSLOG 15 //config: help 16 //config: If you enabled Circular Buffer support, you almost 17 //config: certainly want to enable this feature as well. This 18 //config: utility will allow you to read the messages that are 19 //config: stored in the syslogd circular buffer. 20 //config: 21 //config:config FEATURE_LOGREAD_REDUCED_LOCKING 22 //config: bool "Double buffering" 23 //config: default y 24 //config: depends on LOGREAD 25 //config: help 26 //config: 'logread' ouput to slow serial terminals can have 27 //config: side effects on syslog because of the semaphore. 28 //config: This option make logread to double buffer copy 29 //config: from circular buffer, minimizing semaphore 30 //config: contention at some minor memory expense. 31 //config: 32 33 //applet:IF_LOGREAD(APPLET(logread, BB_DIR_SBIN, BB_SUID_DROP)) 34 35 //kbuild:lib-$(CONFIG_LOGREAD) += logread.o 11 36 12 37 //usage:#define logread_trivial_usage 13 //usage: "[-f ]"38 //usage: "[-fF]" 14 39 //usage:#define logread_full_usage "\n\n" 15 40 //usage: "Show messages in syslogd's circular buffer\n" 16 41 //usage: "\n -f Output data as log grows" 42 //usage: "\n -F Same as -f, but dump buffer first" 17 43 18 44 #include "libbb.h" 45 #include "common_bufsiz.h" 19 46 #include <sys/ipc.h> 20 47 #include <sys/sem.h> … … 42 69 struct shbuf_ds *shbuf; 43 70 } FIX_ALIASING; 44 #define G (*(struct globals*) &bb_common_bufsiz1)71 #define G (*(struct globals*)bb_common_bufsiz1) 45 72 #define SMrup (G.SMrup) 46 73 #define SMrdn (G.SMrdn) 47 74 #define shbuf (G.shbuf) 48 75 #define INIT_G() do { \ 76 setup_common_bufsiz(); \ 49 77 memcpy(SMrup, init_sem, sizeof(init_sem)); \ 50 78 } while (0) 51 79 80 #if 0 52 81 static void error_exit(const char *str) NORETURN; 53 82 static void error_exit(const char *str) 54 83 { 55 / /release all acquired resources84 /* Release all acquired resources */ 56 85 shmdt(shbuf); 57 86 bb_perror_msg_and_die(str); 58 87 } 88 #else 89 /* On Linux, shmdt is not mandatory on exit */ 90 # define error_exit(str) bb_perror_msg_and_die(str) 91 #endif 59 92 60 93 /* … … 67 100 } 68 101 69 static void interrupted(int sig UNUSED_PARAM) 70 { 71 signal(SIGINT, SIG_IGN); 72 shmdt(shbuf); 73 exit(EXIT_SUCCESS); 102 static void interrupted(int sig) 103 { 104 /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */ 105 kill_myself_with_sig(sig); 74 106 } 75 107 … … 80 112 int log_semid; /* ipc semaphore id */ 81 113 int log_shmid; /* ipc shared memory id */ 82 smallint follow = getopt32(argv, "f");114 int follow = getopt32(argv, "fF"); 83 115 84 116 INIT_G(); … … 86 118 log_shmid = shmget(KEY_ID, 0, 0); 87 119 if (log_shmid == -1) 88 bb_perror_msg_and_die("can't find syslogd buffer");120 bb_perror_msg_and_die("can't %s syslogd buffer", "find"); 89 121 90 122 /* Attach shared memory to our char* */ 91 123 shbuf = shmat(log_shmid, NULL, SHM_RDONLY); 92 124 if (shbuf == NULL) 93 bb_perror_msg_and_die("can't access syslogd buffer");125 bb_perror_msg_and_die("can't %s syslogd buffer", "access"); 94 126 95 127 log_semid = semget(KEY_ID, 0, 0); … … 97 129 error_exit("can't get access to semaphores for syslogd buffer"); 98 130 99 signal(SIGINT, interrupted);131 bb_signals(BB_FATAL_SIGS, interrupted); 100 132 101 133 /* Suppose atomic memory read */ … … 103 135 cur = shbuf->tail; 104 136 105 /* Loop for logread -f, one pass if there was no -f*/137 /* Loop for -f or -F, one pass otherwise */ 106 138 do { 107 139 unsigned shbuf_size; … … 123 155 124 156 if (DEBUG) 125 printf("cur:% d tail:%i size:%i\n",157 printf("cur:%u tail:%u size:%u\n", 126 158 cur, shbuf_tail, shbuf_size); 127 159 128 if (!follow) { 160 if (!(follow & 1)) { /* not -f */ 161 /* if -F, "convert" it to -f, so that we dont 162 * dump the entire buffer on each iteration 163 */ 164 follow >>= 1; 165 129 166 /* advance to oldest complete message */ 130 167 /* find NUL */ … … 139 176 if (cur >= shbuf_size) /* last byte in buffer? */ 140 177 cur = 0; 141 } else { /* logread-f */178 } else { /* -f */ 142 179 if (cur == shbuf_tail) { 143 180 sem_up(log_semid); … … 184 221 free(copy); 185 222 #endif 223 fflush_all(); 186 224 } while (follow); 187 225 188 shmdt(shbuf);226 /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */ 189 227 190 228 fflush_stdout_and_exit(EXIT_SUCCESS); -
branches/3.3/mindi-busybox/sysklogd/syslogd.c
r3232 r3621 13 13 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 14 14 */ 15 //config:config SYSLOGD 16 //config: bool "syslogd" 17 //config: default y 18 //config: help 19 //config: The syslogd utility is used to record logs of all the 20 //config: significant events that occur on a system. Every 21 //config: message that is logged records the date and time of the 22 //config: event, and will generally also record the name of the 23 //config: application that generated the message. When used in 24 //config: conjunction with klogd, messages from the Linux kernel 25 //config: can also be recorded. This is terribly useful, 26 //config: especially for finding what happened when something goes 27 //config: wrong. And something almost always will go wrong if 28 //config: you wait long enough.... 29 //config: 30 //config:config FEATURE_ROTATE_LOGFILE 31 //config: bool "Rotate message files" 32 //config: default y 33 //config: depends on SYSLOGD 34 //config: help 35 //config: This enables syslogd to rotate the message files 36 //config: on his own. No need to use an external rotate script. 37 //config: 38 //config:config FEATURE_REMOTE_LOG 39 //config: bool "Remote Log support" 40 //config: default y 41 //config: depends on SYSLOGD 42 //config: help 43 //config: When you enable this feature, the syslogd utility can 44 //config: be used to send system log messages to another system 45 //config: connected via a network. This allows the remote 46 //config: machine to log all the system messages, which can be 47 //config: terribly useful for reducing the number of serial 48 //config: cables you use. It can also be a very good security 49 //config: measure to prevent system logs from being tampered with 50 //config: by an intruder. 51 //config: 52 //config:config FEATURE_SYSLOGD_DUP 53 //config: bool "Support -D (drop dups) option" 54 //config: default y 55 //config: depends on SYSLOGD 56 //config: help 57 //config: Option -D instructs syslogd to drop consecutive messages 58 //config: which are totally the same. 59 //config: 60 //config:config FEATURE_SYSLOGD_CFG 61 //config: bool "Support syslog.conf" 62 //config: default y 63 //config: depends on SYSLOGD 64 //config: help 65 //config: Supports restricted syslogd config. See docs/syslog.conf.txt 66 //config: 67 //config:config FEATURE_SYSLOGD_READ_BUFFER_SIZE 68 //config: int "Read buffer size in bytes" 69 //config: default 256 70 //config: range 256 20000 71 //config: depends on SYSLOGD 72 //config: help 73 //config: This option sets the size of the syslog read buffer. 74 //config: Actual memory usage increases around five times the 75 //config: change done here. 76 //config: 77 //config:config FEATURE_IPC_SYSLOG 78 //config: bool "Circular Buffer support" 79 //config: default y 80 //config: depends on SYSLOGD 81 //config: help 82 //config: When you enable this feature, the syslogd utility will 83 //config: use a circular buffer to record system log messages. 84 //config: When the buffer is filled it will continue to overwrite 85 //config: the oldest messages. This can be very useful for 86 //config: systems with little or no permanent storage, since 87 //config: otherwise system logs can eventually fill up your 88 //config: entire filesystem, which may cause your system to 89 //config: break badly. 90 //config: 91 //config:config FEATURE_IPC_SYSLOG_BUFFER_SIZE 92 //config: int "Circular buffer size in Kbytes (minimum 4KB)" 93 //config: default 16 94 //config: range 4 2147483647 95 //config: depends on FEATURE_IPC_SYSLOG 96 //config: help 97 //config: This option sets the size of the circular buffer 98 //config: used to record system log messages. 99 //config: 100 //config:config FEATURE_KMSG_SYSLOG 101 //config: bool "Linux kernel printk buffer support" 102 //config: default y 103 //config: depends on SYSLOGD 104 //config: select PLATFORM_LINUX 105 //config: help 106 //config: When you enable this feature, the syslogd utility will 107 //config: write system log message to the Linux kernel's printk buffer. 108 //config: This can be used as a smaller alternative to the syslogd IPC 109 //config: support, as klogd and logread aren't needed. 110 //config: 111 //config: NOTICE: Syslog facilities in log entries needs kernel 3.5+. 112 113 //applet:IF_SYSLOGD(APPLET(syslogd, BB_DIR_SBIN, BB_SUID_DROP)) 114 115 //kbuild:lib-$(CONFIG_SYSLOGD) += syslogd_and_logger.o 15 116 16 117 //usage:#define syslogd_trivial_usage … … 22 123 //usage: ) 23 124 //usage: "\n -n Run in foreground" 24 //usage: "\n -O FILE Log to FILE (default:/var/log/messages)"25 //usage: "\n -l N Log only messages more urgent than prio N (1-8)"26 //usage: "\n -S Smaller output"27 //usage: IF_FEATURE_ROTATE_LOGFILE(28 //usage: "\n -s SIZE Max size (KB) before rotation (default:200KB, 0=off)"29 //usage: "\n -b N N rotated logs to keep (default:1, max=99, 0=purge)"30 //usage: )31 125 //usage: IF_FEATURE_REMOTE_LOG( 32 //usage: "\n -R HOST[:PORT] Log to IP or hostname on PORT (default PORT=514/UDP)"126 //usage: "\n -R HOST[:PORT] Log to HOST:PORT (default PORT:514)" 33 127 //usage: "\n -L Log locally and via network (default is network only if -R)" 34 //usage: )35 //usage: IF_FEATURE_SYSLOGD_DUP(36 //usage: "\n -D Drop duplicates"37 128 //usage: ) 38 129 //usage: IF_FEATURE_IPC_SYSLOG( … … 40 131 //usage: "\n -C[size_kb] Log to shared mem buffer (use logread to read it)" 41 132 //usage: ) 133 //usage: IF_FEATURE_KMSG_SYSLOG( 134 //usage: "\n -K Log to kernel printk buffer (use dmesg to read it)" 135 //usage: ) 136 //usage: "\n -O FILE Log to FILE (default: /var/log/messages, stdout if -)" 137 //usage: IF_FEATURE_ROTATE_LOGFILE( 138 //usage: "\n -s SIZE Max size (KB) before rotation (default:200KB, 0=off)" 139 //usage: "\n -b N N rotated logs to keep (default:1, max=99, 0=purge)" 140 //usage: ) 141 //usage: "\n -l N Log only messages more urgent than prio N (1-8)" 142 //usage: "\n -S Smaller output" 143 //usage: IF_FEATURE_SYSLOGD_DUP( 144 //usage: "\n -D Drop duplicates" 145 //usage: ) 42 146 //usage: IF_FEATURE_SYSLOGD_CFG( 43 147 //usage: "\n -f FILE Use FILE as config (default:/etc/syslog.conf)" 44 148 //usage: ) 45 149 /* //usage: "\n -m MIN Minutes between MARK lines (default:20, 0=off)" */ 46 //usage: IF_FEATURE_KMSG_SYSLOG(47 //usage: "\n -K Log to kernel printk buffer (use dmesg to read it)"48 //usage: )49 150 //usage: 50 151 //usage:#define syslogd_example_usage … … 59 160 #include <syslog.h> 60 161 */ 162 #ifndef _PATH_LOG 163 #define _PATH_LOG "/dev/log" 164 #endif 61 165 62 166 #include <sys/un.h> … … 108 212 const char *path; 109 213 int fd; 214 time_t last_log_time; 110 215 #if ENABLE_FEATURE_ROTATE_LOGFILE 111 216 unsigned size; … … 163 268 struct shbuf_ds *shbuf; 164 269 #endif 165 time_t last_log_time;166 270 /* localhost's name. We print only first 64 chars */ 167 271 char *hostname; … … 235 339 OPT_cfg = IF_FEATURE_SYSLOGD_CFG( (1 << OPTBIT_cfg )) + 0, 236 340 OPT_kmsg = IF_FEATURE_KMSG_SYSLOG( (1 << OPTBIT_kmsg )) + 0, 237 238 341 }; 239 342 #define OPTION_STR "m:nO:l:S" \ … … 567 670 pri &= G.primask; 568 671 569 write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg));672 full_write(G.kmsgfd, G.printbuf, sprintf(G.printbuf, "<%d>%s\n", pri, msg)); 570 673 } 571 674 #else … … 583 686 int len = strlen(msg); 584 687 585 if (log_file->fd >= 0) { 586 /* Reopen log file every second. This allows admin 587 * to delete the file and not worry about restarting us. 688 /* fd can't be 0 (we connect fd 0 to /dev/log socket) */ 689 /* fd is 1 if "-O -" is in use */ 690 if (log_file->fd > 1) { 691 /* Reopen log files every second. This allows admin 692 * to delete the files and not worry about restarting us. 588 693 * This costs almost nothing since it happens 589 * _at most_ once a second. 694 * _at most_ once a second for each file, and happens 695 * only when each file is actually written. 590 696 */ 591 697 if (!now) 592 698 now = time(NULL); 593 if ( G.last_log_time != now) {594 G.last_log_time = now;699 if (log_file->last_log_time != now) { 700 log_file->last_log_time = now; 595 701 close(log_file->fd); 596 702 goto reopen; 597 703 } 598 } else { 704 } 705 else if (log_file->fd == 1) { 706 /* We are logging to stdout: do nothing */ 707 } 708 else { 709 if (LONE_DASH(log_file->path)) { 710 log_file->fd = 1; 711 /* log_file->isRegular = 0; - already is */ 712 } else { 599 713 reopen: 600 log_file->fd = open(log_file->path, O_WRONLY | O_CREAT714 log_file->fd = open(log_file->path, O_WRONLY | O_CREAT 601 715 | O_NOCTTY | O_APPEND | O_NONBLOCK, 602 716 0666); 603 if (log_file->fd < 0) {604 /* cannot open logfile? - print to /dev/console then */605 int fd = device_open(DEV_CONSOLE, O_WRONLY | O_NOCTTY | O_NONBLOCK);606 if (fd < 0)607 fd = 2; /* then stderr, dammit */608 full_write(fd, msg, len);609 if (fd != 2)610 close(fd);611 return;612 }717 if (log_file->fd < 0) { 718 /* cannot open logfile? - print to /dev/console then */ 719 int fd = device_open(DEV_CONSOLE, O_WRONLY | O_NOCTTY | O_NONBLOCK); 720 if (fd < 0) 721 fd = 2; /* then stderr, dammit */ 722 full_write(fd, msg, len); 723 if (fd != 2) 724 close(fd); 725 return; 726 } 613 727 #if ENABLE_FEATURE_ROTATE_LOGFILE 614 { 615 struct stat statf; 616 log_file->isRegular = (fstat(log_file->fd, &statf) == 0 && S_ISREG(statf.st_mode)); 617 /* bug (mostly harmless): can wrap around if file > 4gb */ 618 log_file->size = statf.st_size; 619 } 620 #endif 728 { 729 struct stat statf; 730 log_file->isRegular = (fstat(log_file->fd, &statf) == 0 && S_ISREG(statf.st_mode)); 731 /* bug (mostly harmless): can wrap around if file > 4gb */ 732 log_file->size = statf.st_size; 733 } 734 #endif 735 } 621 736 } 622 737 … … 646 761 /* newFile == "f.0" now */ 647 762 rename(log_file->path, newFile); 648 /* Incredibly, if F and F.0 are hardlinks, POSIX 649 * _demands_ that rename returns 0 but does not 650 * remove F!!! 651 * (hardlinked F/F.0 pair was observed after 652 * power failure during rename()). 653 * Ensure old file is gone: 654 */ 655 unlink(log_file->path); 763 } 764 765 /* We may or may not have just renamed the file away; 766 * if we didn't rename because we aren't keeping any backlog, 767 * then it's time to clobber the file. If we did rename it..., 768 * incredibly, if F and F.0 are hardlinks, POSIX _demands_ 769 * that rename returns 0 but does not remove F!!! 770 * (hardlinked F/F.0 pair was observed after 771 * power failure during rename()). 772 * So ensure old file is gone in any case: 773 */ 774 unlink(log_file->path); 656 775 #ifdef SYSLOGD_WRLOCK 657 fl.l_type = F_UNLCK; 658 fcntl(log_file->fd, F_SETLKW, &fl); 659 #endif 660 close(log_file->fd); 661 goto reopen; 662 } 663 ftruncate(log_file->fd, 0); 664 } 665 log_file->size += 666 #endif 667 full_write(log_file->fd, msg, len); 776 fl.l_type = F_UNLCK; 777 fcntl(log_file->fd, F_SETLKW, &fl); 778 #endif 779 close(log_file->fd); 780 goto reopen; 781 } 782 /* TODO: what to do on write errors ("disk full")? */ 783 len = full_write(log_file->fd, msg, len); 784 if (len > 0) 785 log_file->size += len; 786 #else 787 full_write(log_file->fd, msg, len); 788 #endif 789 668 790 #ifdef SYSLOGD_WRLOCK 669 791 fl.l_type = F_UNLCK; … … 815 937 char *dev_log_name; 816 938 817 #if ENABLE_FEATURE_SYSTEMD818 if (sd_listen_fds() == 1)819 return SD_LISTEN_FDS_START;820 #endif821 822 939 memset(&sunx, 0, sizeof(sunx)); 823 940 sunx.sun_family = AF_UNIX; … … 825 942 /* Unlink old /dev/log or object it points to. */ 826 943 /* (if it exists, bind will fail) */ 827 strcpy(sunx.sun_path, "/dev/log");828 dev_log_name = xmalloc_follow_symlinks( "/dev/log");944 strcpy(sunx.sun_path, _PATH_LOG); 945 dev_log_name = xmalloc_follow_symlinks(_PATH_LOG); 829 946 if (dev_log_name) { 830 947 safe_strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path)); … … 835 952 sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0); 836 953 xbind(sock_fd, (struct sockaddr *) &sunx, sizeof(sunx)); 837 chmod( "/dev/log", 0666);954 chmod(_PATH_LOG, 0666); 838 955 839 956 return sock_fd; … … 861 978 static void do_syslogd(void) 862 979 { 863 int sock_fd;864 980 #if ENABLE_FEATURE_REMOTE_LOG 865 981 llist_t *item; … … 882 998 alarm(G.markInterval); 883 999 #endif 884 sock_fd = create_socket();1000 xmove_fd(create_socket(), STDIN_FILENO); 885 1001 886 1002 if (option_mask32 & OPT_circularlog) … … 903 1019 #endif 904 1020 read_again: 905 sz = read( sock_fd, recvbuf, MAX_READ - 1);1021 sz = read(STDIN_FILENO, recvbuf, MAX_READ - 1); 906 1022 if (sz < 0) { 907 1023 if (!bb_got_signal) 908 bb_perror_msg("read from /dev/log");1024 bb_perror_msg("read from %s", _PATH_LOG); 909 1025 break; 910 1026 } … … 974 1090 975 1091 timestamp_and_log_internal("syslogd exiting"); 976 puts("syslogd exiting");977 1092 remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid"); 978 1093 ipcsyslog_cleanup(); -
branches/3.3/mindi-busybox/sysklogd/syslogd_and_logger.c
r2725 r3621 9 9 10 10 #include "libbb.h" 11 #include "common_bufsiz.h" 11 12 #define SYSLOG_NAMES 12 13 #define SYSLOG_NAMES_CONST
Note:
See TracChangeset
for help on using the changeset viewer.