diff options
author | toni <matzeton@googlemail.com> | 2016-07-04 10:01:34 +0200 |
---|---|---|
committer | toni <matzeton@googlemail.com> | 2016-07-04 10:01:34 +0200 |
commit | ac97850fb2b8c1e4efbaf782bf8afbc4b3d6a058 (patch) | |
tree | f7468d863f00e8d9b7e0ab55afaa4844dd4cdd65 /src/log.c | |
parent | 3a8e6b979f6a741342546622477d8bd4e8483cce (diff) |
syslog && compile script
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -2,6 +2,7 @@ #include <stdlib.h> #include <errno.h> #include <stdarg.h> +#include <syslog.h> #include "log.h" @@ -12,16 +13,23 @@ static FILE* logfile = NULL; int log_init(char* file) { - if (!file) return -1; - logfile = fopen(file, "a+"); - return (logfile ? 0 : errno); + if (!file) { + openlog("naskpass", LOG_NDELAY | LOG_PID, LOG_DAEMON); + return 0; + } else { + logfile = fopen(file, "a+"); + return (logfile ? 0 : errno); + } } void log_free(void) { - if (logfile) + if (!logfile) { + closelog(); + } else { fclose(logfile); - logfile = NULL; + logfile = NULL; + } } int logs(char* format, ...) @@ -29,10 +37,14 @@ int logs(char* format, ...) int ret; va_list vargs; - if (!logfile) return -1; va_start(vargs, format); - ret = vfprintf(logfile, format, vargs); - fflush(logfile); + if (!logfile) { + vsyslog(LOG_DEBUG, format, vargs); + ret = 0; + } else { + ret = vfprintf(logfile, format, vargs); + fflush(logfile); + } va_end(vargs); return ret; } |