aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoni <matzeton@googlemail.com>2016-01-25 04:32:53 +0100
committertoni <matzeton@googlemail.com>2016-01-25 04:32:53 +0100
commit2decdd502f1c9b33800cc41daff25536066f7560 (patch)
tree4afe55fd6ae14d16bb5fd5fa0c95b1a794464338
parentad31e73105e58079c2f4fe85b70b80cd7ae1c76a (diff)
early logging
-rw-r--r--src/log.c24
-rw-r--r--src/log.h4
-rw-r--r--src/opt.c4
-rw-r--r--src/opt.h3
4 files changed, 24 insertions, 11 deletions
diff --git a/src/log.c b/src/log.c
index 93d6532..06513cf 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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;
}
diff --git a/src/log.h b/src/log.h
index 7b4affc..aad0bfb 100644
--- a/src/log.h
+++ b/src/log.h
@@ -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
diff --git a/src/opt.c b/src/opt.c
index 19d8879..76b17e7 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -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
diff --git a/src/opt.h b/src/opt.h
index a5fd37f..102dc68 100644
--- a/src/opt.h
+++ b/src/opt.h
@@ -20,7 +20,8 @@ struct opt {
enum opt_index {
FIFO_PATH = 0,
- CRYPT_CMD
+ CRYPT_CMD,
+ LOG_FILE
};