Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/sysklogd


Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (9 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
7 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/sysklogd/Config.src

    r3232 r3621  
    88INSERT
    99
    10 config SYSLOGD
    11     bool "syslogd"
    12     default y
    13     help
    14       The syslogd utility is used to record logs of all the
    15       significant events that occur on a system. Every
    16       message that is logged records the date and time of the
    17       event, and will generally also record the name of the
    18       application that generated the message. When used in
    19       conjunction with klogd, messages from the Linux kernel
    20       can also be recorded. This is terribly useful,
    21       especially for finding what happened when something goes
    22       wrong. And something almost always will go wrong if
    23       you wait long enough....
    24 
    25 config FEATURE_ROTATE_LOGFILE
    26     bool "Rotate message files"
    27     default y
    28     depends on SYSLOGD
    29     help
    30       This enables syslogd to rotate the message files
    31       on his own. No need to use an external rotatescript.
    32 
    33 config FEATURE_REMOTE_LOG
    34     bool "Remote Log support"
    35     default y
    36     depends on SYSLOGD
    37     help
    38       When you enable this feature, the syslogd utility can
    39       be used to send system log messages to another system
    40       connected via a network. This allows the remote
    41       machine to log all the system messages, which can be
    42       terribly useful for reducing the number of serial
    43       cables you use. It can also be a very good security
    44       measure to prevent system logs from being tampered with
    45       by an intruder.
    46 
    47 config FEATURE_SYSLOGD_DUP
    48     bool "Support -D (drop dups) option"
    49     default y
    50     depends on SYSLOGD
    51     help
    52       Option -D instructs syslogd to drop consecutive messages
    53       which are totally the same.
    54 
    55 config FEATURE_SYSLOGD_CFG
    56     bool "Support syslog.conf"
    57     default y
    58     depends on SYSLOGD
    59     help
    60       Supports restricted syslogd config. See docs/syslog.conf.txt
    61 
    62 config FEATURE_SYSLOGD_READ_BUFFER_SIZE
    63     int "Read buffer size in bytes"
    64     default 256
    65     range 256 20000
    66     depends on SYSLOGD
    67     help
    68       This option sets the size of the syslog read buffer.
    69       Actual memory usage increases around five times the
    70       change done here.
    71 
    72 config FEATURE_IPC_SYSLOG
    73     bool "Circular Buffer support"
    74     default y
    75     depends on SYSLOGD
    76     help
    77       When you enable this feature, the syslogd utility will
    78       use a circular buffer to record system log messages.
    79       When the buffer is filled it will continue to overwrite
    80       the oldest messages. This can be very useful for
    81       systems with little or no permanent storage, since
    82       otherwise system logs can eventually fill up your
    83       entire filesystem, which may cause your system to
    84       break badly.
    85 
    86 config FEATURE_IPC_SYSLOG_BUFFER_SIZE
    87     int "Circular buffer size in Kbytes (minimum 4KB)"
    88     default 16
    89     range 4 2147483647
    90     depends on FEATURE_IPC_SYSLOG
    91     help
    92       This option sets the size of the circular buffer
    93       used to record system log messages.
    94 
    95 config LOGREAD
    96     bool "logread"
    97     default y
    98     depends on FEATURE_IPC_SYSLOG
    99     help
    100       If you enabled Circular Buffer support, you almost
    101       certainly want to enable this feature as well. This
    102       utility will allow you to read the messages that are
    103       stored in the syslogd circular buffer.
    104 
    105 config FEATURE_LOGREAD_REDUCED_LOCKING
    106     bool "Double buffering"
    107     default y
    108     depends on LOGREAD
    109     help
    110       'logread' ouput to slow serial terminals can have
    111       side effects on syslog because of the semaphore.
    112       This option make logread to double buffer copy
    113       from circular buffer, minimizing semaphore
    114       contention at some minor memory expense.
    115 
    116 config FEATURE_KMSG_SYSLOG
    117     bool "Linux kernel printk buffer support"
    118     default y
    119     depends on SYSLOGD
    120     select PLATFORM_LINUX
    121     help
    122       When you enable this feature, the syslogd utility will
    123       write system log message to the Linux kernel's printk buffer.
    124       This can be used as a smaller alternative to the syslogd IPC
    125       support, as klogd and logread aren't needed.
    126 
    127       NOTICE: Syslog facilities in log entries needs kernel 3.5+.
    128 
    129 config KLOGD
    130     bool "klogd"
    131     default y
    132     help
    133       klogd is a utility which intercepts and logs all
    134       messages from the Linux kernel and sends the messages
    135       out to the 'syslogd' utility so they can be logged. If
    136       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_SYSLOG
    141 
    142 config FEATURE_KLOGD_KLOGCTL
    143     bool "Use the klogctl() interface"
    144     default y
    145     depends on KLOGD
    146     select PLATFORM_LINUX
    147     help
    148       The klogd applet supports two interfaces for reading
    149       kernel messages. Linux provides the klogctl() interface
    150       which allows reading messages from the kernel ring buffer
    151       independently from the file system.
    152 
    153       If you answer 'N' here, klogd will use the more portable
    154       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 LOGGER
    160     bool "logger"
    161     default y
    162     select FEATURE_SYSLOG
    163     help
    164         The logger utility allows you to send arbitrary text
    165         messages to the system log (i.e. the 'syslogd' utility) so
    166         they can be logged. This is generally used to help locate
    167         problems that occur within programs and scripts.
    168 
    16910endmenu
  • branches/3.3/mindi-busybox/sysklogd/Kbuild.src

    r2725 r3621  
    88
    99INSERT
    10 lib-$(CONFIG_KLOGD)     += klogd.o
    11 lib-$(CONFIG_LOGGER)        += syslogd_and_logger.o
    12 lib-$(CONFIG_LOGREAD)       += logread.o
    13 lib-$(CONFIG_SYSLOGD)       += syslogd_and_logger.o
  • branches/3.3/mindi-busybox/sysklogd/klogd.c

    r3232 r3621  
    1717 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1818 */
     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
    1952
    2053//usage:#define klogd_trivial_usage
     
    2659
    2760#include "libbb.h"
     61#include "common_bufsiz.h"
    2862#include <syslog.h>
    2963
     
    66100#else
    67101
    68 # include <paths.h>
    69102# ifndef _PATH_KLOG
    70103#  ifdef __GNU__
     
    116149#define log_buffer bb_common_bufsiz1
    117150enum {
    118     KLOGD_LOGBUF_SIZE = sizeof(log_buffer),
     151    KLOGD_LOGBUF_SIZE = COMMON_BUFSIZE,
    119152    OPT_LEVEL      = (1 << 0),
    120153    OPT_FOREGROUND = (1 << 1),
     
    141174    int opt;
    142175    int used;
     176
     177    setup_common_bufsiz();
    143178
    144179    opt = getopt32(argv, "c:n", &opt_c);
  • branches/3.3/mindi-busybox/sysklogd/logger.c

    r3232 r3621  
    77 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
     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
    922
    1023//usage:#define logger_trivial_usage
     
    87100    int i = 0;
    88101
     102    setup_common_bufsiz();
     103
    89104    /* Fill out the name string early (may be overwritten later) */
    90105    str_t = uid2uname_utoa(geteuid());
  • branches/3.3/mindi-busybox/sysklogd/logread.c

    r3232 r3621  
    99 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1010 */
     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
    1136
    1237//usage:#define logread_trivial_usage
    13 //usage:       "[-f]"
     38//usage:       "[-fF]"
    1439//usage:#define logread_full_usage "\n\n"
    1540//usage:       "Show messages in syslogd's circular buffer\n"
    1641//usage:     "\n    -f  Output data as log grows"
     42//usage:     "\n    -F  Same as -f, but dump buffer first"
    1743
    1844#include "libbb.h"
     45#include "common_bufsiz.h"
    1946#include <sys/ipc.h>
    2047#include <sys/sem.h>
     
    4269    struct shbuf_ds *shbuf;
    4370} FIX_ALIASING;
    44 #define G (*(struct globals*)&bb_common_bufsiz1)
     71#define G (*(struct globals*)bb_common_bufsiz1)
    4572#define SMrup (G.SMrup)
    4673#define SMrdn (G.SMrdn)
    4774#define shbuf (G.shbuf)
    4875#define INIT_G() do { \
     76    setup_common_bufsiz(); \
    4977    memcpy(SMrup, init_sem, sizeof(init_sem)); \
    5078} while (0)
    5179
     80#if 0
    5281static void error_exit(const char *str) NORETURN;
    5382static void error_exit(const char *str)
    5483{
    55     //release all acquired resources
     84    /* Release all acquired resources */
    5685    shmdt(shbuf);
    5786    bb_perror_msg_and_die(str);
    5887}
     88#else
     89/* On Linux, shmdt is not mandatory on exit */
     90# define error_exit(str) bb_perror_msg_and_die(str)
     91#endif
    5992
    6093/*
     
    67100}
    68101
    69 static void interrupted(int sig UNUSED_PARAM)
    70 {
    71     signal(SIGINT, SIG_IGN);
    72     shmdt(shbuf);
    73     exit(EXIT_SUCCESS);
     102static void interrupted(int sig)
     103{
     104    /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */
     105    kill_myself_with_sig(sig);
    74106}
    75107
     
    80112    int log_semid; /* ipc semaphore id */
    81113    int log_shmid; /* ipc shared memory id */
    82     smallint follow = getopt32(argv, "f");
     114    int follow = getopt32(argv, "fF");
    83115
    84116    INIT_G();
     
    86118    log_shmid = shmget(KEY_ID, 0, 0);
    87119    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");
    89121
    90122    /* Attach shared memory to our char* */
    91123    shbuf = shmat(log_shmid, NULL, SHM_RDONLY);
    92124    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");
    94126
    95127    log_semid = semget(KEY_ID, 0, 0);
     
    97129        error_exit("can't get access to semaphores for syslogd buffer");
    98130
    99     signal(SIGINT, interrupted);
     131    bb_signals(BB_FATAL_SIGS, interrupted);
    100132
    101133    /* Suppose atomic memory read */
     
    103135    cur = shbuf->tail;
    104136
    105     /* Loop for logread -f, one pass if there was no -f */
     137    /* Loop for -f or -F, one pass otherwise */
    106138    do {
    107139        unsigned shbuf_size;
     
    123155
    124156        if (DEBUG)
    125             printf("cur:%d tail:%i size:%i\n",
     157            printf("cur:%u tail:%u size:%u\n",
    126158                    cur, shbuf_tail, shbuf_size);
    127159
    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
    129166            /* advance to oldest complete message */
    130167            /* find NUL */
     
    139176            if (cur >= shbuf_size) /* last byte in buffer? */
    140177                cur = 0;
    141         } else { /* logread -f */
     178        } else { /* -f */
    142179            if (cur == shbuf_tail) {
    143180                sem_up(log_semid);
     
    184221        free(copy);
    185222#endif
     223        fflush_all();
    186224    } while (follow);
    187225
    188     shmdt(shbuf);
     226    /* shmdt(shbuf); - on Linux, shmdt is not mandatory on exit */
    189227
    190228    fflush_stdout_and_exit(EXIT_SUCCESS);
  • branches/3.3/mindi-busybox/sysklogd/syslogd.c

    r3232 r3621  
    1313 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    1414 */
     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
    15116
    16117//usage:#define syslogd_trivial_usage
     
    22123//usage:    )
    23124//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:    )
    31125//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)"
    33127//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"
    37128//usage:    )
    38129//usage:    IF_FEATURE_IPC_SYSLOG(
     
    40131//usage:     "\n    -C[size_kb] Log to shared mem buffer (use logread to read it)"
    41132//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:    )
    42146//usage:    IF_FEATURE_SYSLOGD_CFG(
    43147//usage:     "\n    -f FILE     Use FILE as config (default:/etc/syslog.conf)"
    44148//usage:    )
    45149/* //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:    )
    49150//usage:
    50151//usage:#define syslogd_example_usage
     
    59160#include <syslog.h>
    60161*/
     162#ifndef _PATH_LOG
     163#define _PATH_LOG   "/dev/log"
     164#endif
    61165
    62166#include <sys/un.h>
     
    108212    const char *path;
    109213    int fd;
     214    time_t last_log_time;
    110215#if ENABLE_FEATURE_ROTATE_LOGFILE
    111216    unsigned size;
     
    163268    struct shbuf_ds *shbuf;
    164269#endif
    165     time_t last_log_time;
    166270    /* localhost's name. We print only first 64 chars */
    167271    char *hostname;
     
    235339    OPT_cfg         = IF_FEATURE_SYSLOGD_CFG(   (1 << OPTBIT_cfg        )) + 0,
    236340    OPT_kmsg        = IF_FEATURE_KMSG_SYSLOG(   (1 << OPTBIT_kmsg       )) + 0,
    237 
    238341};
    239342#define OPTION_STR "m:nO:l:S" \
     
    567670    pri &= G.primask;
    568671
    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));
    570673}
    571674#else
     
    583686    int len = strlen(msg);
    584687
    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.
    588693         * 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.
    590696         */
    591697        if (!now)
    592698            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;
    595701            close(log_file->fd);
    596702            goto reopen;
    597703        }
    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 {
    599713 reopen:
    600         log_file->fd = open(log_file->path, O_WRONLY | O_CREAT
     714            log_file->fd = open(log_file->path, O_WRONLY | O_CREAT
    601715                    | O_NOCTTY | O_APPEND | O_NONBLOCK,
    602716                    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            }
    613727#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        }
    621736    }
    622737
     
    646761            /* newFile == "f.0" now */
    647762            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);
    656775#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
    668790#ifdef SYSLOGD_WRLOCK
    669791    fl.l_type = F_UNLCK;
     
    815937    char *dev_log_name;
    816938
    817 #if ENABLE_FEATURE_SYSTEMD
    818     if (sd_listen_fds() == 1)
    819         return SD_LISTEN_FDS_START;
    820 #endif
    821 
    822939    memset(&sunx, 0, sizeof(sunx));
    823940    sunx.sun_family = AF_UNIX;
     
    825942    /* Unlink old /dev/log or object it points to. */
    826943    /* (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);
    829946    if (dev_log_name) {
    830947        safe_strncpy(sunx.sun_path, dev_log_name, sizeof(sunx.sun_path));
     
    835952    sock_fd = xsocket(AF_UNIX, SOCK_DGRAM, 0);
    836953    xbind(sock_fd, (struct sockaddr *) &sunx, sizeof(sunx));
    837     chmod("/dev/log", 0666);
     954    chmod(_PATH_LOG, 0666);
    838955
    839956    return sock_fd;
     
    861978static void do_syslogd(void)
    862979{
    863     int sock_fd;
    864980#if ENABLE_FEATURE_REMOTE_LOG
    865981    llist_t *item;
     
    882998    alarm(G.markInterval);
    883999#endif
    884     sock_fd = create_socket();
     1000    xmove_fd(create_socket(), STDIN_FILENO);
    8851001
    8861002    if (option_mask32 & OPT_circularlog)
     
    9031019#endif
    9041020 read_again:
    905         sz = read(sock_fd, recvbuf, MAX_READ - 1);
     1021        sz = read(STDIN_FILENO, recvbuf, MAX_READ - 1);
    9061022        if (sz < 0) {
    9071023            if (!bb_got_signal)
    908                 bb_perror_msg("read from /dev/log");
     1024                bb_perror_msg("read from %s", _PATH_LOG);
    9091025            break;
    9101026        }
     
    9741090
    9751091    timestamp_and_log_internal("syslogd exiting");
    976     puts("syslogd exiting");
    9771092    remove_pidfile(CONFIG_PID_FILE_PATH "/syslogd.pid");
    9781093    ipcsyslog_cleanup();
  • branches/3.3/mindi-busybox/sysklogd/syslogd_and_logger.c

    r2725 r3621  
    99
    1010#include "libbb.h"
     11#include "common_bufsiz.h"
    1112#define SYSLOG_NAMES
    1213#define SYSLOG_NAMES_CONST
Note: See TracChangeset for help on using the changeset viewer.