diff options
author | toni <matzeton@googlemail.com> | 2016-01-25 04:32:53 +0100 |
---|---|---|
committer | toni <matzeton@googlemail.com> | 2016-01-25 04:32:53 +0100 |
commit | 2decdd502f1c9b33800cc41daff25536066f7560 (patch) | |
tree | 4afe55fd6ae14d16bb5fd5fa0c95b1a794464338 | |
parent | ad31e73105e58079c2f4fe85b70b80cd7ae1c76a (diff) |
early logging
-rw-r--r-- | src/log.c | 24 | ||||
-rw-r--r-- | src/log.h | 4 | ||||
-rw-r--r-- | src/opt.c | 4 | ||||
-rw-r--r-- | src/opt.h | 3 |
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 }; |