diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/aconfig.h.in | 15 | ||||
-rw-r--r-- | src/log.c | 28 | ||||
-rw-r--r-- | src/opt.c | 6 |
3 files changed, 36 insertions, 13 deletions
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 <alloca.h> 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 <syslog.h> 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 @@ -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; } @@ -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]); |