aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-04-30 14:48:28 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2014-04-30 14:48:28 +0200
commit3dfe0ae5a8c4f3a75f61df157db157ac0e044a51 (patch)
tree1675fbf44c96d1d591969104d4322f2fe058fdd9
parent01a1a967c99d6ea75387c6ca8041e9061ea4a111 (diff)
downloadbusybox-w32-3dfe0ae5a8c4f3a75f61df157db157ac0e044a51.tar.gz
busybox-w32-3dfe0ae5a8c4f3a75f61df157db157ac0e044a51.tar.bz2
busybox-w32-3dfe0ae5a8c4f3a75f61df157db157ac0e044a51.zip
libbb: make syslog level for bb_error_msg's configurable. use it in crond
function old new delta bb_verror_msg 380 386 +6 syslog_level - 1 +1 crondlog 165 108 -57 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/verror_msg.c3
-rw-r--r--miscutils/crond.c23
3 files changed, 11 insertions, 16 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 1cbe2c8b4..29cf6bc6d 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1074,6 +1074,7 @@ enum {
1074 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO, 1074 LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
1075}; 1075};
1076extern const char *msg_eol; 1076extern const char *msg_eol;
1077extern smallint syslog_level;
1077extern smallint logmode; 1078extern smallint logmode;
1078extern int die_sleep; 1079extern int die_sleep;
1079extern uint8_t xfunc_error_retval; 1080extern uint8_t xfunc_error_retval;
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c
index ee95be3e3..87efb56b3 100644
--- a/libbb/verror_msg.c
+++ b/libbb/verror_msg.c
@@ -11,6 +11,7 @@
11# include <syslog.h> 11# include <syslog.h>
12#endif 12#endif
13 13
14smallint syslog_level = LOG_ERR;
14smallint logmode = LOGMODE_STDIO; 15smallint logmode = LOGMODE_STDIO;
15const char *msg_eol = "\n"; 16const char *msg_eol = "\n";
16 17
@@ -70,7 +71,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
70 } 71 }
71#if ENABLE_FEATURE_SYSLOG 72#if ENABLE_FEATURE_SYSLOG
72 if (logmode & LOGMODE_SYSLOG) { 73 if (logmode & LOGMODE_SYSLOG) {
73 syslog(LOG_ERR, "%s", msg + applet_len); 74 syslog(syslog_level, "%s", msg + applet_len);
74 } 75 }
75#endif 76#endif
76 free(msg); 77 free(msg);
diff --git a/miscutils/crond.c b/miscutils/crond.c
index 995ed9e0a..8441b6cc5 100644
--- a/miscutils/crond.c
+++ b/miscutils/crond.c
@@ -163,28 +163,21 @@ static void crondlog(const char *ctl, ...) __attribute__ ((format (printf, 1, 2)
163static void crondlog(const char *ctl, ...) 163static void crondlog(const char *ctl, ...)
164{ 164{
165 va_list va; 165 va_list va;
166 int level = (ctl[0] & 0x1f); 166 unsigned level = (ctl[0] & 0x1f);
167 167
168 va_start(va, ctl); 168 va_start(va, ctl);
169 if (level >= (int)G.log_level) { 169 if (level >= G.log_level) {
170 /* Debug mode: all to (non-redirected) stderr, */ 170 if (G.log_filename) {
171 /* Syslog mode: all to syslog (logmode = LOGMODE_SYSLOG), */ 171 /* If log to file, reopen log file at every write: */
172 if (!DebugOpt && G.log_filename) {
173 /* Otherwise (log to file): we reopen log file at every write: */
174 int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND); 172 int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
175 if (logfd >= 0) 173 if (logfd >= 0)
176 xmove_fd(logfd, STDERR_FILENO); 174 xmove_fd(logfd, STDERR_FILENO);
177 } 175 }
178 /* When we log to syslog, level > 8 is logged at LOG_ERR 176 /* When we log to syslog, level > 8 is logged at LOG_ERR
179 * syslog level, level <= 8 is logged at LOG_INFO. */ 177 * syslog level, level <= 8 is logged at LOG_INFO.
180 if (level > 8) { 178 */
181 bb_verror_msg(ctl + 1, va, /* strerr: */ NULL); 179 syslog_level = (level > 8) ? LOG_ERR : LOG_INFO;
182 } else { 180 bb_verror_msg(ctl + 1, va, /* strerr: */ NULL);
183 char *msg = NULL;
184 vasprintf(&msg, ctl + 1, va);
185 bb_info_msg("%s: %s", applet_name, msg);
186 free(msg);
187 }
188 } 181 }
189 va_end(va); 182 va_end(va);
190 if (ctl[0] & 0x80) 183 if (ctl[0] & 0x80)