aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/directory.c4
-rw-r--r--src/path.c16
-rw-r--r--src/playlist.c46
3 files changed, 38 insertions, 28 deletions
diff --git a/src/directory.c b/src/directory.c
index 3249d6382..694ffc08a 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -65,9 +65,9 @@
#define DIRECTORY_RETURN_UPDATE 1
#define DIRECTORY_RETURN_ERROR -1
-static Directory * mp3rootDirectory = NULL;
+Directory * mp3rootDirectory = NULL;
-static time_t directory_dbModTime = 0;
+time_t directory_dbModTime = 0;
volatile int directory_updatePid = 0;
diff --git a/src/path.c b/src/path.c
index c35be7f04..dec9844b6 100644
--- a/src/path.c
+++ b/src/path.c
@@ -116,15 +116,15 @@ static char * appendSlash(char ** path) {
int len = strlen(temp);
if(temp[len-1] != '/') {
- temp = strdup(*path);
+ temp = malloc(len+2);
+ memset(temp, 0, len+2);
+ memcpy(temp, *path, len);
+ temp[len] = '/';
free(*path);
- *path = malloc(len+2);
- memset(*path, 0, len+2);
- memcpy(*path, temp, len);
- (*path)[len] = '/';
+ *path = temp;
}
- return * path;
+ return temp;
}
void initPaths() {
@@ -136,8 +136,8 @@ void initPaths() {
char * originalLocale;
DIR * dir;
- musicDir = appendSlash(&musicParam->value);
- playlistDir = appendSlash(&playlistParam->value);
+ musicDir = appendSlash(&(musicParam->value));
+ playlistDir = appendSlash(&(playlistParam->value));
if((dir = opendir(playlistDir)) == NULL) {
ERROR("cannot open %s \"%s\" (config line %i): %s\n",
diff --git a/src/playlist.c b/src/playlist.c
index d7a946e25..3a2bfcc78 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -88,12 +88,18 @@ static int playlist_noGoToNext = 0;
static int playlist_saveAbsolutePaths = DEFAULT_PLAYLIST_SAVE_ABSOLUTE_PATHS;
-static char * playlist_stateFile = NULL;
-
static void swapOrder(int a, int b);
static int playPlaylistOrderNumber(FILE * fp, int orderNum);
static void randomizeOrder(int start, int end);
+static char * getStateFile() {
+ ConfigParam * param = parseConfigFilePath(CONF_STATE_FILE, 0);
+
+ if(!param) return NULL;
+
+ return param->value;
+}
+
static void incrPlaylistVersion() {
static unsigned long max = ((mpd_uint32)1<<31)-1;
playlist.version++;
@@ -179,8 +185,6 @@ void initPlaylist() {
srandom(time(NULL));
- playlist_stateFile = parseConfigFilePath(CONF_STATE_FILE, 0);
-
for(i=0; i<playlist_max_length*PLAYLIST_HASH_MULT; i++) {
playlist.idToPosition[i] = -1;
}
@@ -252,13 +256,15 @@ int showPlaylist(FILE * fp) {
}
void savePlaylistState() {
- if(playlist_stateFile) {
+ char * stateFile = getStateFile();
+
+ if(stateFile) {
FILE * fp;
- while(!(fp = fopen(playlist_stateFile,"w")) && errno==EINTR);
+ while(!(fp = fopen(stateFile,"w")) && errno==EINTR);
if(!fp) {
ERROR("problems opening state file \"%s\" for "
- "writing: %s\n", playlist_stateFile,
+ "writing: %s\n", stateFile,
strerror(errno));
return;
}
@@ -303,16 +309,16 @@ void loadPlaylistFromStateFile(FILE * fp, char * buffer, int state, int current,
{
char * temp;
int song;
+ char * stateFile = getStateFile();
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
- ERROR("error parsing state file \"%s\"\n",playlist_stateFile);
+ ERROR("error parsing state file \"%s\"\n", stateFile);
exit(EXIT_FAILURE);
}
while(strcmp(buffer,PLAYLIST_STATE_FILE_PLAYLIST_END)) {
song = atoi(strtok(buffer,":"));
if(!(temp = strtok(NULL,""))) {
- ERROR("error parsing state file \"%s\"\n",
- playlist_stateFile);
+ ERROR("error parsing state file \"%s\"\n", stateFile);
exit(EXIT_FAILURE);
}
if(addToPlaylist(stderr, temp, 0)==0 && current==song) {
@@ -328,15 +334,16 @@ void loadPlaylistFromStateFile(FILE * fp, char * buffer, int state, int current,
}
}
if(!myFgets(buffer,PLAYLIST_BUFFER_SIZE,fp)) {
- ERROR("error parsing state file \"%s\"\n",
- playlist_stateFile);
+ ERROR("error parsing state file \"%s\"\n", stateFile);
exit(EXIT_FAILURE);
}
}
}
void readPlaylistState() {
- if(playlist_stateFile) {
+ char * stateFile = getStateFile();
+
+ if(stateFile) {
FILE * fp;
struct stat st;
int current = -1;
@@ -344,17 +351,20 @@ void readPlaylistState() {
int state = PLAYER_STATE_STOP;
char buffer[PLAYLIST_BUFFER_SIZE];
- if(stat(playlist_stateFile,&st)<0) return;
+ if(stat(stateFile,&st)<0) {
+ DEBUG("failed to stat state file\n");
+ return;
+ }
if(!S_ISREG(st.st_mode)) {
ERROR("state file \"%s\" is not a regular "
- "file\n",playlist_stateFile);
+ "file\n",stateFile);
exit(EXIT_FAILURE);
}
- fp = fopen(playlist_stateFile,"r");
+ fp = fopen(stateFile,"r");
if(!fp) {
ERROR("problems opening state file \"%s\" for "
- "reading: %s\n", playlist_stateFile,
+ "reading: %s\n", stateFile,
strerror(errno));
exit(EXIT_FAILURE);
}
@@ -407,7 +417,7 @@ void readPlaylistState() {
strlen(PLAYLIST_STATE_FILE_CURRENT)) {
ERROR("error parsing state "
"file \"%s\"\n",
- playlist_stateFile);
+ stateFile);
exit(EXIT_FAILURE);
}
current = atoi(&(buffer