diff options
author | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-09 17:37:32 +0000 |
---|---|---|
committer | aldot <aldot@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2007-01-09 17:37:32 +0000 |
commit | b7af7de7560f10b01a38912a469d132b71fa23af (patch) | |
tree | 3b824e7eee3d9f331079b76cb1295775b862324d | |
parent | 30edba5e0de383e0ea710e2d3cebd9dcfcf0f04d (diff) | |
download | busybox-w32-b7af7de7560f10b01a38912a469d132b71fa23af.tar.gz busybox-w32-b7af7de7560f10b01a38912a469d132b71fa23af.tar.bz2 busybox-w32-b7af7de7560f10b01a38912a469d132b71fa23af.zip |
- shrink by 26 bytes or so
git-svn-id: svn://busybox.net/trunk/busybox@17207 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | sysklogd/logger.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/sysklogd/logger.c b/sysklogd/logger.c index 3a4f51575..c5e17c2e5 100644 --- a/sysklogd/logger.c +++ b/sysklogd/logger.c | |||
@@ -63,50 +63,56 @@ static int pencode(char *s) | |||
63 | char *save; | 63 | char *save; |
64 | int lev, fac = LOG_USER; | 64 | int lev, fac = LOG_USER; |
65 | 65 | ||
66 | for (save = s; *s && *s != '.'; ++s); | 66 | for (save = s; *s && *s != '.'; ++s) |
67 | ; | ||
67 | if (*s) { | 68 | if (*s) { |
68 | *s = '\0'; | 69 | *s = '\0'; |
69 | fac = decode(save, facilitynames); | 70 | fac = decode(save, facilitynames); |
70 | if (fac < 0) | 71 | if (fac < 0) |
71 | bb_error_msg_and_die("unknown facility name: %s", save); | 72 | bb_error_msg_and_die("unknown %s name: %s", "facility", save); |
72 | *s++ = '.'; | 73 | *s++ = '.'; |
73 | } else { | 74 | } else { |
74 | s = save; | 75 | s = save; |
75 | } | 76 | } |
76 | lev = decode(s, prioritynames); | 77 | lev = decode(s, prioritynames); |
77 | if (lev < 0) | 78 | if (lev < 0) |
78 | bb_error_msg_and_die("unknown priority name: %s", save); | 79 | bb_error_msg_and_die("unknown %s name: %s", "priority", save); |
79 | return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); | 80 | return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK)); |
80 | } | 81 | } |
81 | 82 | ||
82 | 83 | ||
83 | int logger_main(int argc, char **argv) | 84 | int logger_main(int argc, char **argv) |
84 | { | 85 | { |
85 | unsigned opt; | ||
86 | char *opt_p, *opt_t; | 86 | char *opt_p, *opt_t; |
87 | int pri = LOG_USER | LOG_NOTICE; | 87 | int i = 0; |
88 | int option = 0; | 88 | RESERVE_CONFIG_BUFFER(name, 80); |
89 | char name[80]; | ||
90 | 89 | ||
91 | /* Fill out the name string early (may be overwritten later) */ | 90 | /* Fill out the name string early (may be overwritten later) */ |
92 | bb_getpwuid(name, geteuid(), sizeof(name)); | 91 | bb_getpwuid(name, geteuid(), sizeof(name)); |
93 | 92 | ||
94 | /* Parse any options */ | 93 | /* Parse any options */ |
95 | opt = getopt32(argc, argv, "p:st:", &opt_p, &opt_t); | 94 | getopt32(argc, argv, "p:st:", &opt_p, &opt_t); |
95 | |||
96 | if (option_mask32 & 0x2) /* -s */ | ||
97 | i |= LOG_PERROR; | ||
98 | if (option_mask32 & 0x4) /* -t */ | ||
99 | safe_strncpy(name, opt_t, sizeof(name)); | ||
100 | openlog(name, i, 0); | ||
101 | if (ENABLE_FEATURE_CLEAN_UP) | ||
102 | RELEASE_CONFIG_BUFFER(name); | ||
103 | i = LOG_USER | LOG_NOTICE; | ||
104 | if (option_mask32 & 0x1) /* -p */ | ||
105 | i = pencode(opt_p); | ||
106 | |||
96 | argc -= optind; | 107 | argc -= optind; |
97 | argv += optind; | 108 | argv += optind; |
98 | if (opt & 0x1) pri = pencode(opt_p); // -p | ||
99 | if (opt & 0x2) option |= LOG_PERROR; // -s | ||
100 | if (opt & 0x4) safe_strncpy(name, opt_t, sizeof(name)); // -t | ||
101 | |||
102 | openlog(name, option, 0); | ||
103 | if (!argc) { | 109 | if (!argc) { |
104 | while (fgets(bb_common_bufsiz1, BUFSIZ, stdin)) { | 110 | while (fgets(bb_common_bufsiz1, BUFSIZ, stdin)) { |
105 | if (bb_common_bufsiz1[0] | 111 | if (bb_common_bufsiz1[0] |
106 | && NOT_LONE_CHAR(bb_common_bufsiz1, '\n') | 112 | && NOT_LONE_CHAR(bb_common_bufsiz1, '\n') |
107 | ) { | 113 | ) { |
108 | /* Neither "" nor "\n" */ | 114 | /* Neither "" nor "\n" */ |
109 | syslog(pri, "%s", bb_common_bufsiz1); | 115 | syslog(i, "%s", bb_common_bufsiz1); |
110 | } | 116 | } |
111 | } | 117 | } |
112 | } else { | 118 | } else { |
@@ -119,7 +125,7 @@ int logger_main(int argc, char **argv) | |||
119 | sprintf(message + pos, " %s", *argv), | 125 | sprintf(message + pos, " %s", *argv), |
120 | pos = len; | 126 | pos = len; |
121 | } while (*++argv); | 127 | } while (*++argv); |
122 | syslog(pri, "%s", message + 1); /* skip leading " " */ | 128 | syslog(i, "%s", message + 1); /* skip leading " " */ |
123 | } | 129 | } |
124 | 130 | ||
125 | closelog(); | 131 | closelog(); |