From 0beb5c10d3055736530b86d7aaea204607f052c2 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Mon, 25 Oct 2004 04:50:59 +0000 Subject: [PATCH] don't rescan the database if nobody is connected --- src/configfile.c | 28 ++++++++++++++++++++-------- src/configfile.h | 1 + src/main.c | 22 ++++++++++++++-------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/configfile.c b/src/configfile.c index c11bcdc7..6700947f 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -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,"\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()); } /* diff --git a/src/configfile.h b/src/configfile.h index 984c249e..986ce079 100644 --- a/src/configfile.h +++ b/src/configfile.h @@ -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); diff --git a/src/main.c b/src/main.c index 56fff972..6f5369c1 100644 --- a/src/main.c +++ b/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);