mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-31 01:33:44 -04:00
Get rid of the global struct tag_config (CONFIG) config
This commit is contained in:
parent
2530c3512b
commit
d1449a875b
13
src/daapd.h
13
src/daapd.h
@ -67,19 +67,6 @@ typedef struct tag_stats {
|
|||||||
unsigned int bytes_served; /**< How many bytes of data served (unused) */
|
unsigned int bytes_served; /**< How many bytes of data served (unused) */
|
||||||
} STATS;
|
} STATS;
|
||||||
|
|
||||||
/** Global config struct */
|
|
||||||
typedef struct tag_config {
|
|
||||||
int use_mdns; /**< Should we do rendezvous advertisements? */
|
|
||||||
int stop; /**< Time to exit? */
|
|
||||||
int reload; /**< Time to reload and/or rescan the database? */
|
|
||||||
int foreground; /**< Whether or not we are running in foreground */
|
|
||||||
int full_reload; /**< Whether the reload should be a full one */
|
|
||||||
|
|
||||||
STATS stats; /**< Stats structure (see above) */
|
|
||||||
} CONFIG;
|
|
||||||
|
|
||||||
extern CONFIG config;
|
|
||||||
|
|
||||||
/* Event bases */
|
/* Event bases */
|
||||||
extern struct event_base *evbase_main;
|
extern struct event_base *evbase_main;
|
||||||
|
|
||||||
|
50
src/main.c
50
src/main.c
@ -115,9 +115,9 @@
|
|||||||
/*
|
/*
|
||||||
* Globals
|
* Globals
|
||||||
*/
|
*/
|
||||||
CONFIG config; /**< Main configuration structure, as read from configfile */
|
|
||||||
|
|
||||||
struct event_base *evbase_main;
|
struct event_base *evbase_main;
|
||||||
|
static int main_exit;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Forwards
|
* Forwards
|
||||||
@ -296,24 +296,22 @@ signal_cb(int fd, short event, void *arg)
|
|||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
DPRINTF(E_LOG, L_MAIN, "Got SIGTERM or SIGINT\n");
|
DPRINTF(E_LOG, L_MAIN, "Got SIGTERM or SIGINT\n");
|
||||||
|
|
||||||
config.stop = 1;
|
main_exit = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
DPRINTF(E_LOG, L_MAIN, "Got SIGHUP\n");
|
DPRINTF(E_LOG, L_MAIN, "Got SIGHUP\n");
|
||||||
|
|
||||||
if (!config.stop)
|
if (!main_exit)
|
||||||
{
|
{
|
||||||
conf_reload();
|
conf_reload();
|
||||||
err_reopen();
|
err_reopen();
|
||||||
|
|
||||||
config.reload = 1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.stop)
|
if (main_exit)
|
||||||
event_base_loopbreak(evbase_main);
|
event_base_loopbreak(evbase_main);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,9 +337,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int option;
|
int option;
|
||||||
char *configfile=CONFFILE;
|
char *configfile=CONFFILE;
|
||||||
int reload=0;
|
int reload=0;
|
||||||
int start_time;
|
int foreground;
|
||||||
int end_time;
|
|
||||||
int song_count;
|
|
||||||
int force_non_root=0;
|
int force_non_root=0;
|
||||||
int skip_initial=1;
|
int skip_initial=1;
|
||||||
char *db_type,*db_parms,*runas, *tmp;
|
char *db_type,*db_parms,*runas, *tmp;
|
||||||
@ -363,7 +359,8 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
err_setlevel(2);
|
err_setlevel(2);
|
||||||
|
|
||||||
config.foreground=0;
|
foreground = 0;
|
||||||
|
|
||||||
while((option=getopt(argc,argv,"D:d:c:P:frysiub:v")) != -1) {
|
while((option=getopt(argc,argv,"D:d:c:P:frysiub:v")) != -1) {
|
||||||
switch(option) {
|
switch(option) {
|
||||||
case 'b':
|
case 'b':
|
||||||
@ -383,7 +380,7 @@ int main(int argc, char *argv[]) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
config.foreground=1;
|
foreground = 1;
|
||||||
err_setdest(err_getdest() | LOGDEST_STDERR);
|
err_setdest(err_getdest() | LOGDEST_STDERR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -426,11 +423,6 @@ int main(int argc, char *argv[]) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the configfile, if specified, otherwise
|
|
||||||
* try defaults */
|
|
||||||
config.stats.start_time=start_time=(int)time(NULL);
|
|
||||||
config.stop=0;
|
|
||||||
|
|
||||||
ret = conffile_load(configfile);
|
ret = conffile_load(configfile);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
{
|
{
|
||||||
@ -465,7 +457,7 @@ int main(int argc, char *argv[]) {
|
|||||||
/* Daemonize and drop privileges */
|
/* Daemonize and drop privileges */
|
||||||
runas = conf_alloc_string("general", "runas", "nobody");
|
runas = conf_alloc_string("general", "runas", "nobody");
|
||||||
|
|
||||||
ret = daemonize(config.foreground, runas, pidfile);
|
ret = daemonize(foreground, runas, pidfile);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n");
|
DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n");
|
||||||
@ -508,14 +500,6 @@ int main(int argc, char *argv[]) {
|
|||||||
DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_init: %s\n",strerror(errno));
|
DPRINTF(E_FATAL,L_MAIN|L_DB,"Error in db_init: %s\n",strerror(errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
err=db_get_song_count(&perr,&song_count);
|
|
||||||
if(err != DB_E_SUCCESS) {
|
|
||||||
DPRINTF(E_FATAL,L_MISC,"Error getting song count: %s\n",perr);
|
|
||||||
}
|
|
||||||
/* do a full reload if the db is empty */
|
|
||||||
if(!song_count)
|
|
||||||
reload = 1;
|
|
||||||
|
|
||||||
/* Spawn file scanner thread */
|
/* Spawn file scanner thread */
|
||||||
ret = filescanner_init();
|
ret = filescanner_init();
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
@ -596,20 +580,6 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
free(servername);
|
free(servername);
|
||||||
|
|
||||||
end_time=(int) time(NULL);
|
|
||||||
|
|
||||||
err=db_get_song_count(&perr,&song_count);
|
|
||||||
if(err != DB_E_SUCCESS) {
|
|
||||||
DPRINTF(E_FATAL,L_MISC,"Error getting song count: %s\n",perr);
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF(E_LOG,L_MAIN,"Serving %d songs. Startup complete in %d seconds\n",
|
|
||||||
song_count,end_time-start_time);
|
|
||||||
|
|
||||||
if(conf_get_int("general","rescan_interval",0) && (!reload) &&
|
|
||||||
(!conf_get_int("scanning","skip_first",0)))
|
|
||||||
config.reload = 1; /* force a reload on start */
|
|
||||||
|
|
||||||
/* Set up signal fd */
|
/* Set up signal fd */
|
||||||
sigfd = signalfd(-1, &sigs, SFD_NONBLOCK | SFD_CLOEXEC);
|
sigfd = signalfd(-1, &sigs, SFD_NONBLOCK | SFD_CLOEXEC);
|
||||||
if (sigfd < 0)
|
if (sigfd < 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user