mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-03 09:56:00 -05:00
don't rescan the database if nobody is connected
This commit is contained in:
parent
040421a5e3
commit
0beb5c10d3
@ -160,6 +160,7 @@ int config_read(char *file) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
config.always_scan=0;
|
||||
config.configfile=strdup(file);
|
||||
config.web_root=NULL;
|
||||
config.adminpassword=NULL;
|
||||
@ -641,20 +642,21 @@ void config_emit_service_status(WS_CONNINFO *pwsc, void *value, char *arg) {
|
||||
ws_writefd(pwsc,"</TABLE>\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* config_emit_session_count
|
||||
|
||||
/*
|
||||
* config_get_session_count
|
||||
*
|
||||
* emit the number of unique hosts (with a session)
|
||||
* get the number of unique hosts with a session
|
||||
*/
|
||||
void config_emit_session_count(WS_CONNINFO *pwsc, void *value, char *arg) {
|
||||
int config_get_session_count(void) {
|
||||
SCAN_STATUS *pcurrent, *pcheck;
|
||||
int count=0;
|
||||
|
||||
if(config_mutex_lock())
|
||||
return;
|
||||
if(config_mutex_lock()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pcurrent=scan_status.next;
|
||||
|
||||
while(pcurrent) {
|
||||
if(pcurrent->session != 0) {
|
||||
/* check to see if there is another one before this one */
|
||||
@ -671,8 +673,18 @@ void config_emit_session_count(WS_CONNINFO *pwsc, void *value, char *arg) {
|
||||
pcurrent=pcurrent->next;
|
||||
}
|
||||
|
||||
ws_writefd(pwsc,"%d",count);
|
||||
config_mutex_unlock();
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* config_emit_session_count
|
||||
*
|
||||
* emit the number of unique hosts (with a session)
|
||||
*/
|
||||
void config_emit_session_count(WS_CONNINFO *pwsc, void *value, char *arg) {
|
||||
ws_writefd(pwsc,"%d",config_get_session_count());
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -30,6 +30,7 @@ extern int config_write(WS_CONNINFO *pwsc);
|
||||
extern int config_auth(char *user, char *password);
|
||||
extern void config_handler(WS_CONNINFO *pwsc);
|
||||
extern void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...);
|
||||
extern int config_get_session_count(void);
|
||||
extern int config_get_next_session(void);
|
||||
extern void config_close(void);
|
||||
|
||||
|
22
src/main.c
22
src/main.c
@ -52,8 +52,12 @@
|
||||
#include "dynamic-art.h"
|
||||
|
||||
#ifndef DEFAULT_CONFIGFILE
|
||||
#ifdef NSLU2
|
||||
#define DEFAULT_CONFIGFILE "/opt/etc/mt-daapd.conf"
|
||||
#else
|
||||
#define DEFAULT_CONFIGFILE "/etc/mt-daapd.conf"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef PIDFILE
|
||||
#define PIDFILE "/var/run/mt-daapd.pid"
|
||||
@ -483,7 +487,12 @@ int drop_privs(char *user) {
|
||||
|
||||
/* drop privs */
|
||||
if(getuid() == (uid_t)0) {
|
||||
pw=getpwnam(config.runas);
|
||||
if(atoi(user)) {
|
||||
pw=getpwuid((uid_t)atoi(user)); /* doh! */
|
||||
} else {
|
||||
pw=getpwnam(config.runas);
|
||||
}
|
||||
|
||||
if(pw) {
|
||||
if(initgroups(user,pw->pw_gid) != 0 ||
|
||||
setgid(pw->pw_gid) != 0 ||
|
||||
@ -737,9 +746,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
while(!config.stop) {
|
||||
if((config.rescan_interval) && (rescan_counter > config.rescan_interval)) {
|
||||
if(scan_init(config.mp3dir)) {
|
||||
DPRINTF(ERR_LOG,"Background scanning error... exiting\n");
|
||||
config.stop=1;
|
||||
if((config.always_scan) || (config_get_session_count())) {
|
||||
config.reload=1;
|
||||
} else {
|
||||
DPRINTF(ERR_DEBUG,"Skipping background scan... no connected users\n");
|
||||
}
|
||||
rescan_counter=0;
|
||||
}
|
||||
@ -768,10 +778,6 @@ int main(int argc, char *argv[]) {
|
||||
rend_stop();
|
||||
}
|
||||
|
||||
/* Have a refcount problem with the web server...
|
||||
* Need to troubleshoot it more later, but for now, we'll
|
||||
* just stop the webserver the non-graceful way. */
|
||||
|
||||
DPRINTF(ERR_LOG,"Stopping web server\n");
|
||||
ws_stop(server);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user