mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-26 23:25:56 -05:00
logging enhancements
This commit is contained in:
parent
625729613b
commit
6170df9af4
@ -97,6 +97,7 @@ CONFIGELEMENT config_elements[] = {
|
||||
{ 1,0,0,CONFIG_TYPE_STRING,"playlist",(void*)&config.playlist,config_emit_string },
|
||||
{ 1,0,0,CONFIG_TYPE_STRING,"extensions",(void*)&config.extensions,config_emit_string },
|
||||
{ 1,0,0,CONFIG_TYPE_STRING,"password",(void*)&config.readpassword, config_emit_string },
|
||||
{ 1,0,0,CONFIG_TYPE_STRING,"logfile",(void*)&config.logfile, config_emit_string },
|
||||
{ 0,0,0,CONFIG_TYPE_SPECIAL,"release",(void*)VERSION,config_emit_literal },
|
||||
{ 0,0,0,CONFIG_TYPE_SPECIAL,"package",(void*)PACKAGE,config_emit_literal },
|
||||
{ 0,0,0,CONFIG_TYPE_SPECIAL,"include",(void*)NULL,config_emit_include },
|
||||
@ -163,6 +164,7 @@ int config_read(char *file) {
|
||||
config.mp3dir=NULL;
|
||||
config.playlist=NULL;
|
||||
config.runas=NULL;
|
||||
config.logfile=NULL;
|
||||
config.extensions=".mp3";
|
||||
|
||||
config.servername="mt-daapd " VERSION;
|
||||
@ -224,7 +226,6 @@ int config_read(char *file) {
|
||||
while((pce->config_element != -1)) {
|
||||
if(pce->required && pce->config_element && !pce->changed) {
|
||||
fprintf(stderr,"Required config entry '%s' not specified\n",pce->name);
|
||||
errno=EINVAL;
|
||||
err=-1;
|
||||
}
|
||||
if((pce->config_element) && (pce->changed)) {
|
||||
|
@ -192,16 +192,18 @@ DAAP_BLOCK *daap_response_content_codes(void) {
|
||||
* handle the daap block for the /login URI
|
||||
*/
|
||||
|
||||
DAAP_BLOCK *daap_response_login(void) {
|
||||
DAAP_BLOCK *daap_response_login(char *hostname) {
|
||||
DAAP_BLOCK *root;
|
||||
int g=1;
|
||||
int session;
|
||||
|
||||
DPRINTF(ERR_DEBUG,"Preparing to send login response\n");
|
||||
|
||||
root=daap_add_empty(NULL,"mlog");
|
||||
if(root) {
|
||||
g = (int)daap_add_int(root,"mstt",200);
|
||||
g = g && daap_add_int(root,"mlid",config_get_next_session());
|
||||
session=config_get_next_session();
|
||||
g = g && daap_add_int(root,"mlid",session);
|
||||
}
|
||||
|
||||
if(!g) {
|
||||
@ -209,6 +211,8 @@ DAAP_BLOCK *daap_response_login(void) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DPRINTF(ERR_LOG,"%s logging in as session %d\n",hostname,session);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
|
||||
DAAP_BLOCK *daap_response_server_info(char *name);
|
||||
DAAP_BLOCK *daap_response_content_codes(void);
|
||||
DAAP_BLOCK *daap_response_login(void);
|
||||
DAAP_BLOCK *daap_response_login(char *hostname);
|
||||
DAAP_BLOCK *daap_response_update(int fd, int clientver);
|
||||
DAAP_BLOCK *daap_response_songlist(void);
|
||||
DAAP_BLOCK *daap_response_playlists(char *name);
|
||||
|
@ -44,6 +44,7 @@ typedef struct tag_config {
|
||||
char *runas;
|
||||
char *dbdir;
|
||||
char *extensions;
|
||||
char *logfile;
|
||||
STATS stats;
|
||||
} CONFIG;
|
||||
|
||||
|
@ -609,7 +609,8 @@ int db_unpackrecord(datum *pdatum, MP3FILE *pmp3) {
|
||||
ppacked=(MP3PACKED*)pdatum->dptr;
|
||||
|
||||
if(ppacked->version != DB_VERSION)
|
||||
log_err(1,"ON-DISK DATABASE VERSION HAS CHANGED\nDelete your songs.gdb and restart.\n");
|
||||
DPRINTF(ERR_FATAL,"ON-DISK DATABASE VERSION HAS CHANGED\n"
|
||||
"Delete your songs.gdb and restart.\n");
|
||||
|
||||
pmp3->bitrate=ppacked->bitrate;
|
||||
pmp3->samplerate=ppacked->samplerate;
|
||||
@ -715,7 +716,7 @@ int db_add(MP3FILE *pmp3) {
|
||||
ppacked->time_played=0;
|
||||
|
||||
if(gdbm_store(db_songs,dkey,*pnew,GDBM_REPLACE)) {
|
||||
log_err(1,"Error inserting file %s in database\n",pmp3->fname);
|
||||
DPRINTF(ERR_FATAL,"Error inserting file %s in database\n",pmp3->fname);
|
||||
}
|
||||
|
||||
DPRINTF(ERR_DEBUG,"Testing for %d\n",pmp3->id);
|
||||
@ -724,7 +725,7 @@ int db_add(MP3FILE *pmp3) {
|
||||
dkey.dsize=sizeof(unsigned int);
|
||||
|
||||
if(!gdbm_exists(db_songs,dkey)) {
|
||||
log_err(1,"Error.. could not find just added file\n");
|
||||
DPRINTF(ERR_FATAL,"Error.. could not find just added file\n");
|
||||
}
|
||||
|
||||
free(pnew->dptr);
|
||||
@ -774,7 +775,7 @@ MP3RECORD *db_enum_begin(void) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -798,7 +799,7 @@ DB_PLAYLIST *db_playlist_enum_begin(void) {
|
||||
DB_PLAYLIST *current;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -821,7 +822,7 @@ DB_PLAYLISTENTRY *db_playlist_items_enum_begin(int playlistid) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -853,11 +854,11 @@ MP3FILE *db_enum(MP3RECORD **current) {
|
||||
data=gdbm_fetch(db_songs,db_enum_helper.key);
|
||||
MEMNOTIFY(data.dptr);
|
||||
if(!data.dptr) {
|
||||
log_err(1,"Inconsistant database.\n");
|
||||
DPRINTF(ERR_FATAL,"Inconsistant database.\n");
|
||||
}
|
||||
|
||||
if(db_unpackrecord(&data,&db_enum_helper.mp3file)) {
|
||||
log_err(1,"Cannot unpack item.. Corrupt database?\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot unpack item.. Corrupt database?\n");
|
||||
}
|
||||
|
||||
if(data.dptr)
|
||||
@ -1011,7 +1012,7 @@ int db_get_playlist_is_smart(int playlistid) {
|
||||
int result;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
@ -1041,7 +1042,7 @@ int db_get_playlist_entry_count(int playlistid) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
@ -1073,7 +1074,7 @@ char *db_get_playlist_name(int playlistid) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -1104,7 +1105,7 @@ int db_exists(int id) {
|
||||
MP3FILE *pmp3;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
@ -1138,7 +1139,7 @@ int db_last_modified(int id) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
@ -1171,7 +1172,7 @@ int db_delete(int id) {
|
||||
DPRINTF(ERR_DEBUG,"Removing item %d\n",id);
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(1,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ MP3RECORD *db_enum_begin(void) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(0,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -455,7 +455,7 @@ DB_PLAYLIST *db_playlist_enum_begin(void) {
|
||||
DB_PLAYLIST *current;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(0,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -478,7 +478,7 @@ DB_PLAYLISTENTRY *db_playlist_items_enum_begin(int playlistid) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(0,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
@ -623,7 +623,7 @@ int db_get_playlist_is_smart(int playlistid) {
|
||||
int result;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(0,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
@ -654,7 +654,7 @@ int db_get_playlist_entry_count(int playlistid) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(0,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return -1;
|
||||
}
|
||||
@ -686,7 +686,7 @@ char *db_get_playlist_name(int playlistid) {
|
||||
int err;
|
||||
|
||||
if((err=pthread_rwlock_rdlock(&db_rwlock))) {
|
||||
log_err(0,"Cannot lock rwlock\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock rwlock\n");
|
||||
errno=err;
|
||||
return NULL;
|
||||
}
|
||||
|
61
src/err.c
61
src/err.c
@ -25,6 +25,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
@ -38,6 +39,8 @@
|
||||
|
||||
int err_debuglevel=0;
|
||||
int err_logdestination=LOGDEST_STDERR;
|
||||
FILE *err_file=NULL;
|
||||
pthread_mutex_t err_mutex=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
|
||||
@ -49,7 +52,7 @@ typedef struct tag_err_leak {
|
||||
struct tag_err_leak *next;
|
||||
} ERR_LEAK;
|
||||
|
||||
pthread_mutex_t err_mutex=PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
ERR_LEAK err_leak = { NULL, NULL, 0, 0, NULL };
|
||||
#endif
|
||||
|
||||
@ -63,25 +66,45 @@ int err_unlock_mutex(void);
|
||||
/****************************************************
|
||||
* log_err
|
||||
****************************************************/
|
||||
void log_err(int quit, char *fmt, ...)
|
||||
void log_err(int level, char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
char errbuf[256];
|
||||
char timebuf[256];
|
||||
char errbuf[1024];
|
||||
struct tm tm_now;
|
||||
time_t tt_now;
|
||||
|
||||
if(level > err_debuglevel)
|
||||
return;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
err_lock_mutex(); /* atomic file writes */
|
||||
|
||||
switch(err_logdestination) {
|
||||
case LOGDEST_LOGFILE:
|
||||
tt_now=time(NULL);
|
||||
gmtime_r(&tt_now,&tm_now);
|
||||
strftime(timebuf,sizeof(timebuf),"%F %T",&tm_now);
|
||||
fprintf(err_file,"%s %s: ",timebuf,errbuf);
|
||||
if(!level) fprintf(err_file,"%s %s: Aborting\n");
|
||||
fflush(err_file);
|
||||
break;
|
||||
case LOGDEST_STDERR:
|
||||
fprintf(stderr, "%s", errbuf);
|
||||
if(!level) fprintf(stderr,"Aborting\n");
|
||||
break;
|
||||
case LOGDEST_SYSLOG:
|
||||
syslog(LOG_INFO, "%s", errbuf);
|
||||
if(!level) syslog(LOG_INFO, "Aborting\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(quit) {
|
||||
err_unlock_mutex();
|
||||
|
||||
if(!level) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -90,24 +113,34 @@ void log_err(int quit, char *fmt, ...)
|
||||
* log_setdest
|
||||
****************************************************/
|
||||
void log_setdest(char *app, int destination) {
|
||||
switch(destination) {
|
||||
if(err_logdestination == destination)
|
||||
return;
|
||||
|
||||
switch(err_logdestination) {
|
||||
case LOGDEST_SYSLOG:
|
||||
if(err_logdestination != LOGDEST_SYSLOG) {
|
||||
openlog(app,LOG_PID,LOG_DAEMON);
|
||||
closelog();
|
||||
break;
|
||||
case LOGDEST_LOGFILE:
|
||||
fclose(err_file);
|
||||
break;
|
||||
}
|
||||
|
||||
switch(destination) {
|
||||
case LOGDEST_LOGFILE:
|
||||
err_file=fopen(app,"w+");
|
||||
if(err_file==NULL) {
|
||||
fprintf(stderr,"Error opening %s: %s\n",app,strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
case LOGDEST_STDERR:
|
||||
if(err_logdestination == LOGDEST_SYSLOG) {
|
||||
/* close the syslog */
|
||||
closelog();
|
||||
}
|
||||
case LOGDEST_SYSLOG:
|
||||
openlog(app,LOG_PID,LOG_DAEMON);
|
||||
break;
|
||||
}
|
||||
|
||||
err_logdestination=destination;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
|
||||
/*
|
||||
* err_lock
|
||||
@ -144,6 +177,8 @@ int err_unlock_mutex(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
|
||||
/*
|
||||
* Let the leak detector know about a chunk of memory
|
||||
* that needs to be freed, but came from an external library
|
||||
|
10
src/err.h
10
src/err.h
@ -24,10 +24,12 @@
|
||||
|
||||
#define LOGDEST_STDERR 0
|
||||
#define LOGDEST_SYSLOG 1
|
||||
#define LOGDEST_LOGFILE 2
|
||||
|
||||
#define ERR_DEBUG 9
|
||||
#define ERR_INFO 5
|
||||
#define ERR_WARN 2
|
||||
#define ERR_LOG 1 /* should be logging at level 1 */
|
||||
#define ERR_FATAL 0
|
||||
|
||||
extern int err_debuglevel;
|
||||
@ -36,9 +38,13 @@ extern int err_logdestination;
|
||||
extern void log_err(int quit, char *fmt, ...);
|
||||
extern void log_setdest(char *app, int destination);
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
# define DPRINTF(level, fmt, arg...) \
|
||||
{ if((level) <= err_debuglevel) { log_err(0,"%s, %d: ",__FILE__,__LINE__); log_err(0,fmt,##arg); }}
|
||||
{ log_err(level,"%s, %d: ",__FILE__,__LINE__); log_err(0,fmt,##arg); }
|
||||
#else
|
||||
# define DPRINTF(level, fmt, arg...) \
|
||||
{ log_err(level,fmt,##arg); }
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
# ifndef __IN_ERR__
|
||||
|
@ -72,7 +72,7 @@ not |
|
||||
\> { yylval.ival=GREATER; return(GREATER); }
|
||||
|
||||
{qstring} { yylval.cval=strdup(yytext+1);
|
||||
if(yylval.cval[strlen(yylval.cval)-1] == '"');
|
||||
if(yylval.cval[strlen(yylval.cval)-1] == '"')
|
||||
yylval.cval[strlen(yylval.cval)-1] = '\0';
|
||||
return(ID); }
|
||||
|
||||
@ -88,7 +88,7 @@ int yywrap(void) {
|
||||
|
||||
void yyerror(char *msg) {
|
||||
pl_error=1;
|
||||
log_err(0,"Line %d: %s\n",yylineno, msg);
|
||||
DPRINTF(ERR_LOG,"Playlist error, line %d: %s\n",yylineno, msg);
|
||||
}
|
||||
|
||||
|
||||
|
77
src/main.c
77
src/main.c
@ -128,7 +128,7 @@ void daap_handler(WS_CONNINFO *pwsc) {
|
||||
root=daap_response_content_codes();
|
||||
} else if (!strcasecmp(pwsc->uri,"/login")) {
|
||||
config_set_status(pwsc,session_id,"Logging in");
|
||||
root=daap_response_login();
|
||||
root=daap_response_login(pwsc->hostname);
|
||||
} else if (!strcasecmp(pwsc->uri,"/update")) {
|
||||
if(!ws_getvar(pwsc,"delta")) { /* first check */
|
||||
clientrev=db_version() - 1;
|
||||
@ -138,6 +138,9 @@ void daap_handler(WS_CONNINFO *pwsc) {
|
||||
config_set_status(pwsc,session_id,"Waiting for DB updates");
|
||||
}
|
||||
root=daap_response_update(pwsc->fd,clientrev);
|
||||
if((!ws_getvar(pwsc,"delta")) && (root==NULL)) {
|
||||
DPRINTF(ERR_LOG,"Client %s disconnected\n",pwsc->hostname);
|
||||
}
|
||||
} else if (!strcasecmp(pwsc->uri,"/logout")) {
|
||||
config_set_status(pwsc,session_id,NULL);
|
||||
ws_returnerror(pwsc,204,"Logout Successful");
|
||||
@ -273,7 +276,8 @@ void daap_handler(WS_CONNINFO *pwsc) {
|
||||
ws_emitheaders(pwsc);
|
||||
|
||||
config_set_status(pwsc,session_id,"Streaming file '%s'",pmp3->fname);
|
||||
DPRINTF(ERR_INFO,"Streaming %s\n",pmp3->fname);
|
||||
DPRINTF(ERR_LOG,"Session %d: Streaming %s to %s\n",session_id,
|
||||
pmp3->fname, pwsc->hostname);
|
||||
|
||||
config.stats.songs_served++; /* FIXME: remove stat races */
|
||||
|
||||
@ -428,10 +432,7 @@ int main(int argc, char *argv[]) {
|
||||
int end_time;
|
||||
|
||||
config.use_mdns=1;
|
||||
|
||||
fprintf(stderr,"mt-daapd: version %s\n",VERSION);
|
||||
fprintf(stderr,"Copyright (c) 2003 Ron Pedde. All rights reserved\n");
|
||||
fprintf(stderr,"Portions Copyright (c) 1999-2001 Apple Computer, Inc. All rights Reserved.\n\n");
|
||||
err_debuglevel=1;
|
||||
|
||||
while((option=getopt(argc,argv,"d:c:mpf")) != -1) {
|
||||
switch(option) {
|
||||
@ -463,42 +464,45 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
/* read the configfile, if specified, otherwise
|
||||
* try defaults */
|
||||
|
||||
config.stats.start_time=start_time=time(NULL);
|
||||
|
||||
if(config_read(configfile)) {
|
||||
perror("config_read");
|
||||
if(errno) perror("config_read");
|
||||
else fprintf(stderr,"Error reading config file (%s)\n",configfile);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if(config.logfile) {
|
||||
log_setdest(config.logfile,LOGDEST_LOGFILE);
|
||||
} else {
|
||||
if(!foreground) {
|
||||
log_setdest("mt-daapd",LOGDEST_SYSLOG);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if((config.use_mdns) && (!parseonly)) {
|
||||
fprintf(stderr,"Starting rendezvous daemon -- indexing "
|
||||
"mp3 files... wait.\n");
|
||||
DPRINTF(ERR_LOG,"Starting rendezvous daemon\n");
|
||||
if(rend_init(config.runas)) {
|
||||
perror("rend_init");
|
||||
exit(EXIT_FAILURE);
|
||||
DPRINTF(ERR_FATAL,"Error in rend_init: %s\n",strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(db_open(config.dbdir)) {
|
||||
perror("db_open");
|
||||
exit(EXIT_FAILURE);
|
||||
DPRINTF(ERR_FATAL,"Error in db_open: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
// Drop privs here
|
||||
if(drop_privs(config.runas)) {
|
||||
perror("drop_privs");
|
||||
exit(EXIT_FAILURE);
|
||||
DPRINTF(ERR_FATAL,"Error in drop_privs: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
DPRINTF(ERR_DEBUG,"Loading playlists...\n");
|
||||
DPRINTF(ERR_LOG,"Loading playlists\n");
|
||||
|
||||
if(config.playlist)
|
||||
pl_load(config.playlist);
|
||||
|
||||
DPRINTF(ERR_DEBUG,"Initializing database\n");
|
||||
|
||||
if(parseonly) {
|
||||
if(!pl_error) {
|
||||
fprintf(stderr,"Parsed successfully.\n");
|
||||
@ -508,30 +512,30 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Initialize the database before starting */
|
||||
DPRINTF(ERR_LOG,"Initializing database\n");
|
||||
if(db_init()) {
|
||||
perror("db_init");
|
||||
exit(EXIT_FAILURE);
|
||||
DPRINTF(ERR_FATAL,"Error in db_init: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
/* will want to detach before we start scanning mp3 files */
|
||||
if(!foreground) {
|
||||
log_setdest("mt-daapd",LOGDEST_SYSLOG);
|
||||
if(!foreground)
|
||||
daemon_start(1);
|
||||
}
|
||||
|
||||
DPRINTF(ERR_LOG,"Starting mp3 scan\n");
|
||||
if(scan_init(config.mp3dir)) {
|
||||
log_err(1,"Error scanning MP3 files: %s\n",strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
DPRINTF(ERR_FATAL,"Error scanning MP3 files: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
/* start up the web server */
|
||||
ws_config.web_root=config.web_root;
|
||||
ws_config.port=config.port;
|
||||
|
||||
DPRINTF(ERR_LOG,"Starting web server from %s on port %d\n",
|
||||
config.web_root, config.port);
|
||||
|
||||
server=ws_start(&ws_config);
|
||||
if(!server) {
|
||||
log_err(1,"Error starting web server: %s\n",strerror(errno));
|
||||
return EXIT_FAILURE;
|
||||
DPRINTF(ERR_FATAL,"Error staring web server: %s\n",strerror(errno));
|
||||
}
|
||||
|
||||
ws_registerhandler(server, "^.*$",config_handler,config_auth,1);
|
||||
@ -544,14 +548,14 @@ int main(int argc, char *argv[]) {
|
||||
ws_registerhandler(server,"^/databases/.*",daap_handler,NULL,0);
|
||||
|
||||
if(config.use_mdns) { /* register services */
|
||||
DPRINTF(ERR_DEBUG,"Registering rendezvous names\n");
|
||||
DPRINTF(ERR_LOG,"Registering rendezvous names\n");
|
||||
rend_register(config.servername,"_daap._tcp",config.port);
|
||||
rend_register(config.servername,"_http._tcp",config.port);
|
||||
}
|
||||
|
||||
end_time=time(NULL);
|
||||
|
||||
log_err(0,"Scanned %d songs in %d seconds\n",db_get_song_count(),
|
||||
DPRINTF(ERR_LOG,"Scanned %d songs in %d seconds\n",db_get_song_count(),
|
||||
end_time-start_time);
|
||||
|
||||
config.stop=0;
|
||||
@ -559,17 +563,19 @@ int main(int argc, char *argv[]) {
|
||||
while(!config.stop)
|
||||
sleep(10);
|
||||
|
||||
DPRINTF(ERR_LOG,"Stopping gracefully\n");
|
||||
|
||||
if(config.use_mdns) {
|
||||
if(foreground) fprintf(stderr,"Killing rendezvous daemon\n");
|
||||
DPRINTF(ERR_LOG,"Stopping rendezvous daemon\n");
|
||||
rend_stop();
|
||||
}
|
||||
|
||||
if(foreground) fprintf(stderr,"Stopping webserver\n");
|
||||
DPRINTF(ERR_LOG,"Stopping web server\n");
|
||||
ws_stop(server);
|
||||
|
||||
config_close();
|
||||
|
||||
if(foreground) fprintf(stderr,"Closing database\n");
|
||||
DPRINTF(ERR_LOG,"Closing database\n");
|
||||
db_deinit();
|
||||
|
||||
#ifdef DEBUG_MEMORY
|
||||
@ -577,9 +583,10 @@ int main(int argc, char *argv[]) {
|
||||
err_leakcheck();
|
||||
#endif
|
||||
|
||||
if(foreground) fprintf(stderr,"\nDone\n");
|
||||
DPRINTF(ERR_LOG,"Done!\n");
|
||||
|
||||
log_setdest(NULL,LOGDEST_STDERR);
|
||||
|
||||
log_err(0,"Exiting");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) {
|
||||
int playlistid;
|
||||
struct stat sb;
|
||||
|
||||
DPRINTF(ERR_DEBUG,"Found static playlist: %s\n",pde->d_name);
|
||||
DPRINTF(ERR_WARN,"Processing static playlist: %s\n",pde->d_name);
|
||||
strcpy(m3u_path,pde->d_name);
|
||||
snprintf(playlist_path,sizeof(playlist_path),"%s/%s",path,pde->d_name);
|
||||
m3u_path[strlen(pde->d_name) - 4] = '\0';
|
||||
@ -392,7 +392,7 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) {
|
||||
fd=open(playlist_path,O_RDONLY);
|
||||
if(fd != -1) {
|
||||
db_add_playlist(playlistid,m3u_path,0);
|
||||
DPRINTF(ERR_DEBUG,"Added playlist as id %d\n",playlistid);
|
||||
DPRINTF(ERR_INFO,"Added playlist as id %d\n",playlistid);
|
||||
|
||||
while(readline(fd,linebuffer,sizeof(linebuffer)) > 0) {
|
||||
while((linebuffer[strlen(linebuffer)-1] == '\n') ||
|
||||
@ -424,6 +424,8 @@ void scan_static_playlist(char *path, struct dirent *pde, struct stat *psb) {
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
DPRINTF(ERR_WARN,"Done processing playlist\n");
|
||||
}
|
||||
|
||||
/*
|
||||
@ -455,7 +457,7 @@ void scan_music_file(char *path, struct dirent *pde, struct stat *psb) {
|
||||
db_add(&mp3file);
|
||||
pl_eval(&mp3file); /* FIXME: move to db_add? */
|
||||
} else {
|
||||
DPRINTF(ERR_INFO,"Skipping %s\n",pde->d_name);
|
||||
DPRINTF(ERR_WARN,"Skipping %s - scan_gettags failed\n",pde->d_name);
|
||||
}
|
||||
|
||||
scan_freetags(&mp3file);
|
||||
|
@ -234,7 +234,7 @@ extern int ws_stop(WSHANDLE ws) {
|
||||
|
||||
/* Wait for all the threads to die */
|
||||
if(pthread_mutex_lock(&pwsp->exit_mutex))
|
||||
log_err(1,"Cannot lock condition mutex\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n");
|
||||
|
||||
/* wait for condition */
|
||||
while(pwsp->dispatch_threads) {
|
||||
@ -269,7 +269,7 @@ void *ws_mainthread(void *arg) {
|
||||
char hostname[MAX_HOSTNAME];
|
||||
|
||||
if(pthread_mutex_lock(&pwsp->exit_mutex))
|
||||
log_err(1,"Cannot lock condition mutex\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n");
|
||||
|
||||
pwsp->dispatch_threads++;
|
||||
|
||||
@ -285,7 +285,7 @@ void *ws_mainthread(void *arg) {
|
||||
|
||||
/* decrement the number of dispatch threads */
|
||||
if(pthread_mutex_lock(&pwsp->exit_mutex))
|
||||
log_err(1,"Cannot lock condition mutex\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n");
|
||||
|
||||
pwsp->dispatch_threads--;
|
||||
pthread_cond_signal(&pwsp->exit_cond);
|
||||
@ -302,7 +302,7 @@ void *ws_mainthread(void *arg) {
|
||||
|
||||
/* decrement dispatch threads */
|
||||
if(pthread_mutex_lock(&pwsp->exit_mutex))
|
||||
log_err(1,"Cannot lock condition mutex\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n");
|
||||
|
||||
pwsp->dispatch_threads--;
|
||||
pthread_cond_signal(&pwsp->exit_cond);
|
||||
@ -326,7 +326,7 @@ void *ws_mainthread(void *arg) {
|
||||
|
||||
/* now, throw off a dispatch thread */
|
||||
if(pthread_mutex_lock(&pwsp->exit_mutex))
|
||||
log_err(1,"Cannot lock condition mutex\n");
|
||||
DPRINTF(ERR_FATAL,"Cannot lock condition mutex\n");
|
||||
|
||||
if((err=pthread_create(&tid,NULL,ws_dispatcher,(void*)pwsc))) {
|
||||
pwsc->error=err;
|
||||
@ -375,14 +375,14 @@ void ws_close(WS_CONNINFO *pwsc) {
|
||||
|
||||
/* this thread is done */
|
||||
if(pthread_mutex_lock(&pwsp->exit_mutex))
|
||||
log_err(1,"Error: cannot lock condition mutex\n");
|
||||
DPRINTF(ERR_FATAL,"Error: cannot lock condition mutex\n");
|
||||
|
||||
if(!pwsp->dispatch_threads) {
|
||||
log_err(1,"Error: Bad dispatch thread count!\n");
|
||||
DPRINTF(ERR_FATAL,"Error: Bad dispatch thread count!\n");
|
||||
} else {
|
||||
pwsp->dispatch_threads--;
|
||||
if(pthread_cond_signal(&pwsp->exit_cond))
|
||||
log_err(1,"Error: cannot signal condition\n");
|
||||
DPRINTF(ERR_FATAL,"Error: cannot signal condition\n");
|
||||
}
|
||||
pthread_mutex_unlock(&pwsp->exit_mutex);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user