summaryrefslogtreecommitdiff
path: root/debug.c
diff options
context:
space:
mode:
authorvenaas <venaas>2009-02-13 15:54:40 +0000
committervenaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf>2009-02-13 15:54:40 +0000
commitccb73e4109f9c1d7318c1b5053ae0ff1cc9f2a99 (patch)
treecabe9d656259dfc15ef405ddec1e88b10095658a /debug.c
parent55be0e6590f835ec7c8c65c88f706a2d3f9edc14 (diff)
added -i option for pid file, HUP for reopening log file
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@471 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/debug.c b/debug.c
index 2b2e07d..c011b08 100644
--- a/debug.c
+++ b/debug.c
@@ -19,9 +19,11 @@
#include <syslog.h>
#include <errno.h>
#include "debug.h"
+#include "util.h"
static char *debug_ident = NULL;
static uint8_t debug_level = DBG_INFO;
+static char *debug_filepath = NULL;
static FILE *debug_file = NULL;
static int debug_syslogfacility = 0;
static uint8_t debug_timestamp = 0;
@@ -68,11 +70,12 @@ int debug_set_destination(char *dest) {
int i;
if (!strncasecmp(dest, "file:///", 8)) {
- debug_file = fopen(dest + 7, "a");
+ debug_filepath = stringcopy(dest + 7, 0);
+ debug_file = fopen(debug_filepath, "a");
if (!debug_file) {
debug_file = stderr;
debugx(1, DBG_ERR, "Failed to open logfile %s\n%s",
- dest + 7, strerror(errno));
+ debug_filepath, strerror(errno));
}
setvbuf(debug_file, NULL, _IONBF, 0);
return 1;
@@ -97,6 +100,29 @@ int debug_set_destination(char *dest) {
exit(1);
}
+void debug_reopen_log() {
+ extern int errno;
+
+ /* not a file, noop, return success */
+ if (!debug_filepath) {
+ debug(DBG_ERR, "skipping reopen");
+ return;
+ }
+
+ if (debug_file != stderr)
+ fclose(debug_file);
+
+ debug_file = fopen(debug_filepath, "a");
+ if (debug_file)
+ debug(DBG_ERR, "Reopened logfile %s", debug_filepath);
+ else {
+ debug_file = stderr;
+ debug(DBG_ERR, "Failed to open logfile %s, using stderr\n%s",
+ debug_filepath, strerror(errno));
+ }
+ setvbuf(debug_file, NULL, _IONBF, 0);
+}
+
void debug_logit(uint8_t level, const char *format, va_list ap) {
struct timeval now;
char *timebuf;