Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 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:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • 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);
Note: See TracChangeset for help on using the changeset viewer.