diff options
Diffstat (limited to 'hugin.c')
-rw-r--r-- | hugin.c | 31 |
1 files changed, 28 insertions, 3 deletions
@@ -34,6 +34,7 @@ #include <time.h> #include <string.h> #include <unistd.h> +#include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> @@ -119,7 +120,8 @@ struct hug_config_t { int fd; int file_fd; int stdout_no_date; - mutex_t mutex; + mutex_t mutex; + char *filename; #ifdef WITH_HUG_SYSLOG const char* syslog_host; int syslog_port; @@ -132,6 +134,7 @@ struct hug_config_t { //#ifdef WITH_HUG_MUTEX MUTEX_INIT_VALUE, // mutex; //#endif + NULL, // filename #ifdef WITH_HUG_SYSLOG NULL, // syslog_host; 541, // syslog_port; @@ -226,8 +229,13 @@ hug_status_t hug_init(unsigned int flags, ...) break; case HUG_OPTION_FILENAME: if(hug_config.flags & HUG_FLAG_OUTPUT_TO_FILE) { - const char *filename = (const char*)va_arg(vl, char*); - hug_config.file_fd = open(filename, O_CREAT | O_RDWR, 0777); + hug_config.filename = strdup((const char*)va_arg(vl, char*)); + hug_config.file_fd = open(hug_config.filename, O_CREAT | O_RDWR, 0777); + if(hug_config.file_fd == -1) { + fprintf(stderr, "Could not open logfile for writing: %s\n", + hug_config.filename); + return HUG_STATUS_ERROR; + } } break; #ifdef WITH_HUG_SYSLOG @@ -268,6 +276,7 @@ void hug_close() { if(hug_config.flags & HUG_FLAG_OUTPUT_TO_FILE) { if(hug_config.file_fd != -1) close(hug_config.file_fd); + if(hug_config.filename) free(hug_config.filename); } #ifdef WITH_HUG_SYSLOG @@ -277,6 +286,22 @@ void hug_close() hug_mutex_close(); } +hug_status_t hugin_reopen_log() +{ + if((hug_config.flags & HUG_FLAG_OUTPUT_TO_FILE) == 0) return HUG_STATUS_OK; + + close(hug_config.file_fd); + hug_config.file_fd = open(hug_config.filename, O_CREAT | O_RDWR, 0777); + + if(hug_config.file_fd == -1) { + fprintf(stderr, "Could not re-open logfile for writing: %s\n", + hug_config.filename); + return HUG_STATUS_ERROR; + } + + return HUG_STATUS_OK; +} + /* static unsigned int gettid() { |