Disable logging to stderr if it is not a tty

This commit is contained in:
Michael Spang 2009-01-30 23:40:22 -05:00
parent 597d6c5908
commit 3358c617ad
4 changed files with 14 additions and 4 deletions

View File

@ -146,7 +146,7 @@ int main(int argc, char *argv[]) {
int opt;
prog = basename(argv[0]);
openlog(prog, 0, LOG_AUTHPRIV);
init_log(prog, LOG_PID, LOG_AUTHPRIV);
configure();

View File

@ -154,7 +154,7 @@ int main(int argc, char *argv[]) {
int opt;
prog = basename(argv[0]);
openlog(prog, 0, LOG_AUTHPRIV);
init_log(prog, LOG_PID, LOG_AUTHPRIV);
configure();

View File

@ -10,6 +10,13 @@
static char message[4096];
static int log_stderr = 1;
void init_log(const char *ident, int option, int facility) {
openlog(ident, option, facility);
log_stderr = isatty(STDERR_FILENO);
}
static void errmsg(int prio, const char *prefix, const char *fmt, va_list args) {
char *msgp = message;
@ -25,7 +32,8 @@ static void errmsg(int prio, const char *prefix, const char *fmt, va_list args)
*msgp++ = '\0';
syslog(prio, "%s", message);
fputs(message, stderr);
if (log_stderr)
fputs(message, stderr);
}
static void errmsgpe(int prio, const char *prefix, const char *fmt, va_list args) {
@ -47,7 +55,8 @@ static void errmsgpe(int prio, const char *prefix, const char *fmt, va_list args
*msgp++ = '\0';
syslog(prio, "%s", message);
fputs(message, stderr);
if (log_stderr)
fputs(message, stderr);
}
NORETURN static void die(int prio, const char *prefix, const char *msg, va_list args) {

View File

@ -16,6 +16,7 @@
#endif
int spawnv(const char *, char *[]);
void init_log(const char *ident, int option, int facility);
NORETURN void fatal(const char *, ...);
NORETURN void fatalpe(const char *, ...);