diff options
author | venaas <venaas> | 2009-02-18 15:37:01 +0000 |
---|---|---|
committer | venaas <venaas@e88ac4ed-0b26-0410-9574-a7f39faa03bf> | 2009-02-18 15:37:01 +0000 |
commit | f2d6619255e9644f4f134dfe98a24342d35e618b (patch) | |
tree | 8f98185b835dbe76483b332724e17094e3d48e74 /debug.c | |
parent | 851dd8c2292a077089bfffb5dd52943b8f7c53b4 (diff) |
updated files for 1.3-beta release
git-svn-id: https://svn.testnett.uninett.no/radsecproxy/branches/release-1.3@480 e88ac4ed-0b26-0410-9574-a7f39faa03bf
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 30 |
1 files changed, 28 insertions, 2 deletions
@@ -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; |