From ac97850fb2b8c1e4efbaf782bf8afbc4b3d6a058 Mon Sep 17 00:00:00 2001 From: toni Date: Mon, 4 Jul 2016 10:01:34 +0200 Subject: syslog && compile script --- src/aconfig.h.in | 15 ++++++++++++--- src/log.c | 28 ++++++++++++++++++++-------- src/opt.c | 6 ++++-- 3 files changed, 36 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/aconfig.h.in b/src/aconfig.h.in index a24ff8d..8dcbf12 100644 --- a/src/aconfig.h.in +++ b/src/aconfig.h.in @@ -3,9 +3,6 @@ /* Define to 1 if you have the `alarm' function. */ #undef HAVE_ALARM -/* Define to 1 if you have the header file. */ -#undef HAVE_ALLOCA_H - /* Define to 1 if you have the `asprintf' function. */ #undef HAVE_ASPRINTF @@ -15,6 +12,9 @@ /* Define to 1 if you have the `close' function. */ #undef HAVE_CLOSE +/* Define to 1 if you have the `closelog' function. */ +#undef HAVE_CLOSELOG + /* Do NOT change THIS! */ #undef HAVE_CONFIG @@ -74,6 +74,9 @@ /* Define to 1 if you have the `open' function. */ #undef HAVE_OPEN +/* Define to 1 if you have the `openlog' function. */ +#undef HAVE_OPENLOG + /* Define to 1 if you have the `printf' function. */ #undef HAVE_PRINTF @@ -130,6 +133,9 @@ /* Define to 1 if you have the `strtol' function. */ #undef HAVE_STRTOL +/* Define to 1 if you have the header file. */ +#undef HAVE_SYSLOG_H + /* Define to 1 if you have the `system' function. */ #undef HAVE_SYSTEM @@ -171,6 +177,9 @@ /* Define to 1 if you have the `vprintf' function. */ #undef HAVE_VPRINTF +/* Define to 1 if you have the `vsyslog' function. */ +#undef HAVE_VSYSLOG + /* Define to 1 if `fork' works. */ #undef HAVE_WORKING_FORK diff --git a/src/log.c b/src/log.c index ea52fda..cd8fc7c 100644 --- a/src/log.c +++ b/src/log.c @@ -2,6 +2,7 @@ #include #include #include +#include #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; } diff --git a/src/opt.c b/src/opt.c index e1ea835..0c2071a 100644 --- a/src/opt.c +++ b/src/opt.c @@ -28,7 +28,7 @@ parse_cmd(int argc, char **argv) { int opt; - while ((opt = getopt(argc, argv, "hf:c:l:")) != -1) { + while ((opt = getopt(argc, argv, "hf:c:l::")) != -1) { switch (opt) { case 'h': usage(argv[0]); @@ -40,7 +40,9 @@ parse_cmd(int argc, char **argv) SETOPT_str(CRYPT_CMD, strdup(optarg)); break; case 'l': - SETOPT_str(LOG_FILE, strdup(optarg)); + if (optarg) { + SETOPT_str(LOG_FILE, strdup(optarg)); + } else SETOPT_str(LOG_FILE, NULL); break; default: usage(argv[0]); -- cgit v1.2.3