don't rescan the database if nobody is connected

This commit is contained in:
Ron Pedde 2004-10-25 04:50:59 +00:00
parent 040421a5e3
commit 0beb5c10d3
3 changed files with 35 additions and 16 deletions

View File

@ -160,6 +160,7 @@ int config_read(char *file) {
return -1; return -1;
} }
config.always_scan=0;
config.configfile=strdup(file); config.configfile=strdup(file);
config.web_root=NULL; config.web_root=NULL;
config.adminpassword=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"); 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; SCAN_STATUS *pcurrent, *pcheck;
int count=0; int count=0;
if(config_mutex_lock()) if(config_mutex_lock()) {
return; return 0;
}
pcurrent=scan_status.next; pcurrent=scan_status.next;
while(pcurrent) { while(pcurrent) {
if(pcurrent->session != 0) { if(pcurrent->session != 0) {
/* check to see if there is another one before this one */ /* 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; pcurrent=pcurrent->next;
} }
ws_writefd(pwsc,"%d",count);
config_mutex_unlock(); 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());
} }
/* /*

View File

@ -30,6 +30,7 @@ extern int config_write(WS_CONNINFO *pwsc);
extern int config_auth(char *user, char *password); extern int config_auth(char *user, char *password);
extern void config_handler(WS_CONNINFO *pwsc); extern void config_handler(WS_CONNINFO *pwsc);
extern void config_set_status(WS_CONNINFO *pwsc, int session, char *fmt, ...); 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 int config_get_next_session(void);
extern void config_close(void); extern void config_close(void);

View File

@ -52,8 +52,12 @@
#include "dynamic-art.h" #include "dynamic-art.h"
#ifndef DEFAULT_CONFIGFILE #ifndef DEFAULT_CONFIGFILE
#ifdef NSLU2
#define DEFAULT_CONFIGFILE "/opt/etc/mt-daapd.conf"
#else
#define DEFAULT_CONFIGFILE "/etc/mt-daapd.conf" #define DEFAULT_CONFIGFILE "/etc/mt-daapd.conf"
#endif #endif
#endif
#ifndef PIDFILE #ifndef PIDFILE
#define PIDFILE "/var/run/mt-daapd.pid" #define PIDFILE "/var/run/mt-daapd.pid"
@ -483,7 +487,12 @@ int drop_privs(char *user) {
/* drop privs */ /* drop privs */
if(getuid() == (uid_t)0) { 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(pw) {
if(initgroups(user,pw->pw_gid) != 0 || if(initgroups(user,pw->pw_gid) != 0 ||
setgid(pw->pw_gid) != 0 || setgid(pw->pw_gid) != 0 ||
@ -737,9 +746,10 @@ int main(int argc, char *argv[]) {
while(!config.stop) { while(!config.stop) {
if((config.rescan_interval) && (rescan_counter > config.rescan_interval)) { if((config.rescan_interval) && (rescan_counter > config.rescan_interval)) {
if(scan_init(config.mp3dir)) { if((config.always_scan) || (config_get_session_count())) {
DPRINTF(ERR_LOG,"Background scanning error... exiting\n"); config.reload=1;
config.stop=1; } else {
DPRINTF(ERR_DEBUG,"Skipping background scan... no connected users\n");
} }
rescan_counter=0; rescan_counter=0;
} }
@ -768,10 +778,6 @@ int main(int argc, char *argv[]) {
rend_stop(); 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"); DPRINTF(ERR_LOG,"Stopping web server\n");
ws_stop(server); ws_stop(server);