diff options
Diffstat (limited to 'src')
4 files changed, 24 insertions, 11 deletions
@@ -1,19 +1,31 @@ #include <stdio.h> #include <stdlib.h> +#include <errno.h> +#include <stdarg.h> #include "log.h" +#define LOG_BUFSIZ 128 -static int logfd; +static FILE* logfile; -int log_init(char *file) + +int log_init(char* file) { - logfd = fopen(file, "a+"); - return logfd; + logfile = fopen(file, "a+"); + return (logfile ? 0 : errno); } -int logs(char *format, ...) +int logs(char* format, ...) { - + int ret; + char* buf; + va_list vargs; + + buf = (char*) calloc(LOG_BUFSIZ, sizeof(char)); + va_start(vargs, format); + ret = vsnprintf(buf, LOG_BUFSIZ, format, vargs); + va_end(vargs); + return ret; } @@ -1,8 +1,8 @@ #ifndef LOG_H #define LOG_H 1 -int log_init(char *file); +int log_init(char* file); -int logs(char *format, ...); +int logs(char* format, ...); #endif @@ -9,7 +9,7 @@ #define CONFIG_OPT(default_val) { {0},0,{default_val} } -struct opt config_opts[] = { CONFIG_OPT(DEFAULT_FIFO), CONFIG_OPT(NULL) }; +struct opt config_opts[] = { CONFIG_OPT(DEFAULT_FIFO), CONFIG_OPT(NULL), CONFIG_OPT("/tmp/naskpass.log") }; const int opt_siz = ( sizeof(config_opts)/sizeof(config_opts[0]) ); @@ -20,7 +20,7 @@ usage(char *arg0) fprintf(stderr, " Written by %s (%s).\n", AUTHOR, AUTHOR_EMAIL); fprintf(stderr, " License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n\n"); fprintf(stderr, " Command:\n\t%s [args]\n", arg0); - fprintf(stderr, " Arguments:\n\t-h this\n\t-f [passfifo] default: %s\n\t-c [cryptcreate]\n", DEFAULT_FIFO); + fprintf(stderr, " Arguments:\n\t-h this\n\t-l [logfile] default: %s\n\t-f [passfifo] default: %s\n\t-c [cryptcreate]\n", GETOPT(LOG_FILE), GETOPT(FIFO_PATH)); } int @@ -20,7 +20,8 @@ struct opt { enum opt_index { FIFO_PATH = 0, - CRYPT_CMD + CRYPT_CMD, + LOG_FILE }; |