mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 15:45:56 -05:00
reopen log and re-read config on sighup -- fixes ticket #73
This commit is contained in:
parent
7907540aa5
commit
882111a52a
@ -361,6 +361,14 @@ int _conf_verify(LL_HANDLE pll) {
|
||||
return is_valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* reload the existing config file.
|
||||
*
|
||||
* @returns CONF_E_SUCCESS on success
|
||||
*/
|
||||
int conf_reload(void) {
|
||||
return conf_read(conf_main_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* read a configfile into a tree
|
||||
|
@ -33,6 +33,7 @@
|
||||
#define CONF_E_NOTWRITABLE 8
|
||||
|
||||
extern int conf_read(char *file);
|
||||
extern int conf_reload(void);
|
||||
extern int conf_close(void);
|
||||
extern int conf_get_int(char *section, char *key, int dflt);
|
||||
extern int conf_get_string(char *section, char *key, char *dflt,
|
||||
|
35
src/err.c
35
src/err.c
@ -36,6 +36,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -45,8 +46,13 @@
|
||||
# include "os.h"
|
||||
#endif
|
||||
|
||||
#ifndef PACKAGE
|
||||
# define PACKAGE "unknown daemon"
|
||||
#endif
|
||||
|
||||
static int err_debuglevel=0; /**< current debuglevel, set from command line with -d */
|
||||
static int err_logdestination=LOGDEST_STDERR; /**< current log destination */
|
||||
static char err_filename[PATH_MAX + 1];
|
||||
static FILE *err_file=NULL; /**< if logging to file, the handle of that file */
|
||||
static pthread_mutex_t err_mutex=PTHREAD_MUTEX_INITIALIZER; /**< for serializing log messages */
|
||||
static unsigned int err_debugmask=0xFFFFFFFF; /**< modules to debug, see \ref log_categories */
|
||||
@ -64,6 +70,32 @@ static char *err_categorylist[] = {
|
||||
static int _err_lock(void);
|
||||
static int _err_unlock(void);
|
||||
|
||||
|
||||
/**
|
||||
* if we are logging to a file, then re-open the file. This
|
||||
* would help for log rotation
|
||||
*/
|
||||
void err_reopen(void) {
|
||||
int err;
|
||||
|
||||
if(err_logdestination != LOGDEST_LOGFILE)
|
||||
return;
|
||||
|
||||
fclose(err_file);
|
||||
err_file = fopen(err_filename,"a");
|
||||
if(!err_file) {
|
||||
/* what to do when you lose your logging mechanism? Keep
|
||||
* going?
|
||||
*/
|
||||
err = errno;
|
||||
err_setdest(PACKAGE,LOGDEST_SYSLOG);
|
||||
DPRINTF(E_LOG,L_MISC,"Could not rotate log file: %s\n",
|
||||
strerror(err));
|
||||
} else {
|
||||
DPRINTF(E_LOG,L_MISC,"Rotated logs\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a printf-style formatted message to the log destination.
|
||||
* This can be stderr, syslog/eventviewer, or a logfile, as determined by
|
||||
@ -160,7 +192,8 @@ void err_setdest(char *cvalue, int destination) {
|
||||
|
||||
switch(destination) {
|
||||
case LOGDEST_LOGFILE:
|
||||
err_file=fopen(cvalue,"a");
|
||||
strncpy(err_filename,cvalue,PATH_MAX);
|
||||
err_file=fopen(err_filename,"a");
|
||||
if(err_file==NULL) {
|
||||
fprintf(stderr,"Error opening %s: %s\n",cvalue,strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -64,6 +64,7 @@
|
||||
#endif
|
||||
|
||||
extern void err_log(int level, unsigned int cat, char *fmt, ...);
|
||||
extern void err_reopen(void); /** rotate logfile */
|
||||
extern void err_setdest(char *cvalue, int destination);
|
||||
extern void err_setlevel(int level);
|
||||
extern int err_getlevel(void);
|
||||
|
@ -363,6 +363,11 @@ void *_os_signal_handler(void *arg) {
|
||||
break;
|
||||
case SIGHUP:
|
||||
DPRINTF(E_LOG,L_MAIN,"Got HUP signal. Notifying daap server.\n");
|
||||
/* if we can't reload, it keeps the old config file,
|
||||
* so no real damage */
|
||||
conf_reload();
|
||||
err_reopen();
|
||||
|
||||
config.reload=1;
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user