mirror of https://github.com/mirror/busybox.git
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>1_23_stable
parent
01a1a967c9
commit
3dfe0ae5a8
|
@ -1074,6 +1074,7 @@ enum {
|
||||||
LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
|
LOGMODE_BOTH = LOGMODE_SYSLOG + LOGMODE_STDIO,
|
||||||
};
|
};
|
||||||
extern const char *msg_eol;
|
extern const char *msg_eol;
|
||||||
|
extern smallint syslog_level;
|
||||||
extern smallint logmode;
|
extern smallint logmode;
|
||||||
extern int die_sleep;
|
extern int die_sleep;
|
||||||
extern uint8_t xfunc_error_retval;
|
extern uint8_t xfunc_error_retval;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# include <syslog.h>
|
# include <syslog.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
smallint syslog_level = LOG_ERR;
|
||||||
smallint logmode = LOGMODE_STDIO;
|
smallint logmode = LOGMODE_STDIO;
|
||||||
const char *msg_eol = "\n";
|
const char *msg_eol = "\n";
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ void FAST_FUNC bb_verror_msg(const char *s, va_list p, const char* strerr)
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_SYSLOG
|
#if ENABLE_FEATURE_SYSLOG
|
||||||
if (logmode & LOGMODE_SYSLOG) {
|
if (logmode & LOGMODE_SYSLOG) {
|
||||||
syslog(LOG_ERR, "%s", msg + applet_len);
|
syslog(syslog_level, "%s", msg + applet_len);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
free(msg);
|
free(msg);
|
||||||
|
|
|
@ -163,28 +163,21 @@ static void crondlog(const char *ctl, ...) __attribute__ ((format (printf, 1, 2)
|
||||||
static void crondlog(const char *ctl, ...)
|
static void crondlog(const char *ctl, ...)
|
||||||
{
|
{
|
||||||
va_list va;
|
va_list va;
|
||||||
int level = (ctl[0] & 0x1f);
|
unsigned level = (ctl[0] & 0x1f);
|
||||||
|
|
||||||
va_start(va, ctl);
|
va_start(va, ctl);
|
||||||
if (level >= (int)G.log_level) {
|
if (level >= G.log_level) {
|
||||||
/* Debug mode: all to (non-redirected) stderr, */
|
if (G.log_filename) {
|
||||||
/* Syslog mode: all to syslog (logmode = LOGMODE_SYSLOG), */
|
/* If log to file, reopen log file at every write: */
|
||||||
if (!DebugOpt && G.log_filename) {
|
|
||||||
/* Otherwise (log to file): we reopen log file at every write: */
|
|
||||||
int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
|
int logfd = open_or_warn(G.log_filename, O_WRONLY | O_CREAT | O_APPEND);
|
||||||
if (logfd >= 0)
|
if (logfd >= 0)
|
||||||
xmove_fd(logfd, STDERR_FILENO);
|
xmove_fd(logfd, STDERR_FILENO);
|
||||||
}
|
}
|
||||||
/* When we log to syslog, level > 8 is logged at LOG_ERR
|
/* When we log to syslog, level > 8 is logged at LOG_ERR
|
||||||
* syslog level, level <= 8 is logged at LOG_INFO. */
|
* syslog level, level <= 8 is logged at LOG_INFO.
|
||||||
if (level > 8) {
|
*/
|
||||||
bb_verror_msg(ctl + 1, va, /* strerr: */ NULL);
|
syslog_level = (level > 8) ? LOG_ERR : LOG_INFO;
|
||||||
} else {
|
bb_verror_msg(ctl + 1, va, /* strerr: */ NULL);
|
||||||
char *msg = NULL;
|
|
||||||
vasprintf(&msg, ctl + 1, va);
|
|
||||||
bb_info_msg("%s: %s", applet_name, msg);
|
|
||||||
free(msg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
va_end(va);
|
va_end(va);
|
||||||
if (ctl[0] & 0x80)
|
if (ctl[0] & 0x80)
|
||||||
|
|
Loading…
Reference in New Issue