Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/sysklogd/logger.c

    r821 r1765  
    88 */
    99
    10 #include "busybox.h"
    11 #include <stdio.h>
    12 #include <unistd.h>
    13 #include <sys/types.h>
    14 #include <fcntl.h>
    15 #include <ctype.h>
    16 #include <string.h>
    17 #include <stdlib.h>
     10#include "libbb.h"
    1811
    1912#if !defined CONFIG_SYSLOGD
     
    4942
    5043    if (isdigit(*name))
    51         return (atoi(name));
     44        return atoi(name);
    5245    for (c = codetab; c->c_name; c++) {
    5346        if (!strcasecmp(name, c->c_name)) {
    54             return (c->c_val);
     47            return c->c_val;
    5548        }
    5649    }
    5750
    58     return (-1);
     51    return -1;
    5952}
    6053
     
    7164    int lev, fac = LOG_USER;
    7265
    73     for (save = s; *s && *s != '.'; ++s);
     66    for (save = s; *s && *s != '.'; ++s)
     67        ;
    7468    if (*s) {
    7569        *s = '\0';
    7670        fac = decode(save, facilitynames);
    7771        if (fac < 0)
    78             bb_error_msg_and_die("unknown facility name: %s", save);
     72            bb_error_msg_and_die("unknown %s name: %s", "facility", save);
    7973        *s++ = '.';
    8074    } else {
     
    8377    lev = decode(s, prioritynames);
    8478    if (lev < 0)
    85         bb_error_msg_and_die("unknown priority name: %s", save);
     79        bb_error_msg_and_die("unknown %s name: %s", "priority", save);
    8680    return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
    8781}
    8882
    8983
     84int logger_main(int argc, char **argv);
    9085int logger_main(int argc, char **argv)
    9186{
    92     int pri = LOG_USER | LOG_NOTICE;
    93     int option = 0;
    94     int c, i, opt;
    95     char buf[1024], name[128];
     87    char *str_p, *str_t;
     88    int i = 0;
     89    char name[80];
    9690
    9791    /* Fill out the name string early (may be overwritten later) */
    98     bb_getpwuid(name, geteuid(), sizeof(name));
     92    bb_getpwuid(name, sizeof(name), geteuid());
     93    str_t = name;
    9994
    10095    /* Parse any options */
    101     while ((opt = getopt(argc, argv, "p:st:")) > 0) {
    102         switch (opt) {
    103             case 's':
    104                 option |= LOG_PERROR;
    105                 break;
    106             case 'p':
    107                 pri = pencode(optarg);
    108                 break;
    109             case 't':
    110                 safe_strncpy(name, optarg, sizeof(name));
    111                 break;
    112             default:
    113                 bb_show_usage();
     96    getopt32(argv, "p:st:", &str_p, &str_t);
     97
     98    if (option_mask32 & 0x2) /* -s */
     99        i |= LOG_PERROR;
     100    //if (option_mask32 & 0x4) /* -t */
     101    openlog(str_t, i, 0);
     102    i = LOG_USER | LOG_NOTICE;
     103    if (option_mask32 & 0x1) /* -p */
     104        i = pencode(str_p);
     105
     106    argc -= optind;
     107    argv += optind;
     108    if (!argc) {
     109#define strbuf bb_common_bufsiz1
     110        while (fgets(strbuf, BUFSIZ, stdin)) {
     111            if (strbuf[0]
     112             && NOT_LONE_CHAR(strbuf, '\n')
     113            ) {
     114                /* Neither "" nor "\n" */
     115                syslog(i, "%s", strbuf);
     116            }
    114117        }
    115     }
    116 
    117     openlog(name, option, 0);
    118     if (optind == argc) {
    119         do {
    120             /* read from stdin */
    121             i = 0;
    122             while ((c = getc(stdin)) != EOF && c != '\n' &&
    123                     i < (sizeof(buf)-1)) {
    124                 buf[i++] = c;
    125             }
    126             if (i > 0) {
    127                 buf[i++] = '\0';
    128                 syslog(pri, "%s", buf);
    129             }
    130         } while (c != EOF);
    131118    } else {
    132119        char *message = NULL;
    133         int len = argc - optind; /* for the space between the args
    134                         and  '\0' */
    135         opt = len;
    136         argv += optind;
    137         for (i = 0; i < opt; i++) {
    138             len += strlen(*argv);
     120        int len = 1; /* for NUL */
     121        int pos = 0;
     122        do {
     123            len += strlen(*argv) + 1;
    139124            message = xrealloc(message, len);
    140             if(!i)
    141                 message[0] = 0;
    142             else
    143                 strcat(message, " ");
    144             strcat(message, *argv);
    145             argv++;
    146         }
    147         syslog(pri, "%s", message);
     125            sprintf(message + pos, " %s", *argv),
     126            pos = len;
     127        } while (*++argv);
     128        syslog(i, "%s", message + 1); /* skip leading " " */
    148129    }
    149130
     
    187168 * SUCH DAMAGE.
    188169 */
    189 
    190 
    191 
Note: See TracChangeset for help on using the changeset viewer.