1
0
forked from bip/bip

don't touch bip.log if log = false

This commit is contained in:
nohar 2005-05-21 14:23:05 +00:00
parent ed8f084dae
commit 5ad0a47e68
2 changed files with 15 additions and 5 deletions

View File

@ -168,17 +168,22 @@ static pid_t daemonize(void)
}
if (setsid() < 0)
fatal("setsid() failed");
snprintf(buf, 4095, "%s/bip.log", conf_log_root);
FILE *f = fopen(buf, "a");
if (!f)
fatal("Can't open %s: %s", buf, strerror(errno));
if (conf_log) {
snprintf(buf, 4095, "%s/bip.log", conf_log_root);
FILE *f = fopen(buf, "a");
if (!f)
fatal("Can't open %s: %s", buf, strerror(errno));
conf_global_log_file = f;
} else {
conf_global_log_file = stderr;
}
close(0);
close(1);
close(2);
/* This better be the very last action since fatal makes use of
* conf_global_log_file */
conf_global_log_file = f;
return getpid();
}

View File

@ -24,6 +24,7 @@
#include <errno.h>
extern int conf_log_level;
extern int conf_log;
extern int errno;
/*
@ -117,6 +118,10 @@ void _mylog(int level, char *fmt, va_list ap)
void mylog(int level, char *fmt, ...)
{
va_list ap;
if (!conf_log)
return;
va_start(ap, fmt);
_mylog(level, fmt, ap);
va_end(ap);