From: Dietmar Maurer Date: Fri, 14 Mar 2014 12:59:22 +0000 (+0100) Subject: additionally log status messages to syslog X-Git-Url: https://git.proxmox.com/?p=pve-firewall.git;a=commitdiff_plain;h=9da3465c8ae0a93398ccae6d719c031349978bef;hp=e7ceb650f5afc3ff62056e930c0deea1fd980e50 additionally log status messages to syslog --- diff --git a/src/pvefw-logger.c b/src/pvefw-logger.c index ece6604..044a18a 100644 --- a/src/pvefw-logger.c +++ b/src/pvefw-logger.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -121,13 +122,13 @@ log_writer_thread(gpointer data) continue; } - printf("%s", le->buf); int res = safe_write(outfd, le->buf, le->len); - + g_free(le); if (res < 0) { - // printf("write failed\n"); // fixme?? + syslog(3, "writing log failed, stopping daemon - %s", strerror (errno)); + return NULL; } } @@ -184,6 +185,10 @@ log_status_message(guint loglevel, const char *fmt, ...) LEPRINTF("\n"); queue_log_entry(le); + + // also log to syslog + + vsyslog(loglevel, fmt, ap); } static int @@ -594,8 +599,18 @@ nlif_read_cb(GIOChannel *source, GIOCondition condition, gpointer data) { - nlif_catch(nlifh); - // fixme: report errors + static int last_res = 0; + int res; + + if ((res = nlif_catch(nlifh)) < 0) { + if (last_res == 0) { // only report once + log_status_message(3, "nlif_catch failed (res = %d)", res); + } + last_res = res; + } else { + last_res = 0; + } + return TRUE; } @@ -623,8 +638,10 @@ main(int argc, char *argv[]) g_thread_init(NULL); + openlog("pvepw-logger", LOG_CONS|LOG_PID, LOG_DAEMON); + if ((lockfd = open(LOCKFILE, O_RDWR|O_CREAT|O_APPEND, 0644)) == -1) { - fprintf(stderr, "unable to create lock '%s': %s", LOCKFILE, strerror (errno)); + fprintf(stderr, "unable to create lock '%s': %s", LOCKFILE, strerror (errno) ); exit(-1); }