simplified logging in debug mode

This commit is contained in:
Nikos Mavrogiannopoulos
2013-02-09 12:39:57 +01:00
parent 519f0a13ef
commit 43fed529bb
2 changed files with 10 additions and 12 deletions

View File

@@ -79,18 +79,14 @@ void __attribute__ ((format(printf, 3, 4)))
ip = human_addr((void*)&ws->remote_addr, ws->remote_addr_len,
ipbuf, sizeof(ipbuf));
buf[1023] = 0;
va_start(args, fmt);
vsnprintf(buf, 1023, fmt, args);
vsnprintf(buf, sizeof(buf)-1, fmt, args);
va_end(args);
if (ip) {
syslog(priority, "%s %s", ip, buf);
if (ws->config->debug != 0) fprintf(stderr, "%s %s", ip, buf);
} else {
syslog(priority, "[unknown] %s", buf);
if (ws->config->debug != 0) fprintf(stderr, "[unknown] %s", buf);
}
return;
@@ -114,18 +110,14 @@ void __attribute__ ((format(printf, 4, 5)))
ipbuf, sizeof(ipbuf));
}
buf[1023] = 0;
va_start(args, fmt);
vsnprintf(buf, 1023, fmt, args);
vsnprintf(buf, sizeof(buf)-1, fmt, args);
va_end(args);
if (ip) {
syslog(priority, "%s %s", ip, buf);
if (s->config->debug != 0) fprintf(stderr, "%s %s", ip, buf);
} else {
syslog(priority, "[unknown] %s", buf);
if (s->config->debug != 0) fprintf(stderr, "[unknown] %s", buf);
}
return;

View File

@@ -470,7 +470,7 @@ int main(int argc, char** argv)
struct proc_st *ctmp, *cpos;
struct tun_st tun;
fd_set rd;
int val, n = 0, ret;
int val, n = 0, ret, flags;
struct timeval tv;
int cmd_fd[2];
struct worker_st ws;
@@ -531,7 +531,13 @@ int main(int argc, char** argv)
#define MAINTAINANCE_TIME (config.cookie_validity + 300)
alarm(MAINTAINANCE_TIME);
openlog("ocserv", LOG_PID|LOG_NDELAY, LOG_LOCAL0);
flags = LOG_PID|LOG_NDELAY;
#ifdef LOG_PERROR
if (config.debug != 0)
flags |= LOG_PERROR;
#endif
openlog("ocserv", flags, LOG_DAEMON);
syslog_open = 1;
for (;;) {