- shrink by 26 bytes or so

This commit is contained in:
Bernhard Reutner-Fischer 2007-01-09 17:37:32 +00:00
parent e86bd6cde5
commit 0f48663f83

View File

@ -63,50 +63,56 @@ static int pencode(char *s)
char *save; char *save;
int lev, fac = LOG_USER; int lev, fac = LOG_USER;
for (save = s; *s && *s != '.'; ++s); for (save = s; *s && *s != '.'; ++s)
;
if (*s) { if (*s) {
*s = '\0'; *s = '\0';
fac = decode(save, facilitynames); fac = decode(save, facilitynames);
if (fac < 0) if (fac < 0)
bb_error_msg_and_die("unknown facility name: %s", save); bb_error_msg_and_die("unknown %s name: %s", "facility", save);
*s++ = '.'; *s++ = '.';
} else { } else {
s = save; s = save;
} }
lev = decode(s, prioritynames); lev = decode(s, prioritynames);
if (lev < 0) if (lev < 0)
bb_error_msg_and_die("unknown priority name: %s", save); bb_error_msg_and_die("unknown %s name: %s", "priority", save);
return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
} }
int logger_main(int argc, char **argv) int logger_main(int argc, char **argv)
{ {
unsigned opt;
char *opt_p, *opt_t; char *opt_p, *opt_t;
int pri = LOG_USER | LOG_NOTICE; int i = 0;
int option = 0; RESERVE_CONFIG_BUFFER(name, 80);
char name[80];
/* Fill out the name string early (may be overwritten later) */ /* Fill out the name string early (may be overwritten later) */
bb_getpwuid(name, geteuid(), sizeof(name)); bb_getpwuid(name, geteuid(), sizeof(name));
/* Parse any options */ /* Parse any options */
opt = getopt32(argc, argv, "p:st:", &opt_p, &opt_t); getopt32(argc, argv, "p:st:", &opt_p, &opt_t);
if (option_mask32 & 0x2) /* -s */
i |= LOG_PERROR;
if (option_mask32 & 0x4) /* -t */
safe_strncpy(name, opt_t, sizeof(name));
openlog(name, i, 0);
if (ENABLE_FEATURE_CLEAN_UP)
RELEASE_CONFIG_BUFFER(name);
i = LOG_USER | LOG_NOTICE;
if (option_mask32 & 0x1) /* -p */
i = pencode(opt_p);
argc -= optind; argc -= optind;
argv += optind; argv += optind;
if (opt & 0x1) pri = pencode(opt_p); // -p
if (opt & 0x2) option |= LOG_PERROR; // -s
if (opt & 0x4) safe_strncpy(name, opt_t, sizeof(name)); // -t
openlog(name, option, 0);
if (!argc) { if (!argc) {
while (fgets(bb_common_bufsiz1, BUFSIZ, stdin)) { while (fgets(bb_common_bufsiz1, BUFSIZ, stdin)) {
if (bb_common_bufsiz1[0] if (bb_common_bufsiz1[0]
&& NOT_LONE_CHAR(bb_common_bufsiz1, '\n') && NOT_LONE_CHAR(bb_common_bufsiz1, '\n')
) { ) {
/* Neither "" nor "\n" */ /* Neither "" nor "\n" */
syslog(pri, "%s", bb_common_bufsiz1); syslog(i, "%s", bb_common_bufsiz1);
} }
} }
} else { } else {
@ -119,7 +125,7 @@ int logger_main(int argc, char **argv)
sprintf(message + pos, " %s", *argv), sprintf(message + pos, " %s", *argv),
pos = len; pos = len;
} while (*++argv); } while (*++argv);
syslog(pri, "%s", message + 1); /* skip leading " " */ syslog(i, "%s", message + 1); /* skip leading " " */
} }
closelog(); closelog();