aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/directory.c6
-rw-r--r--src/interface.c9
-rw-r--r--src/myfprintf.c39
-rw-r--r--src/player.c2
-rw-r--r--src/playlist.c8
-rw-r--r--src/song.c2
-rw-r--r--src/tag.c1
7 files changed, 36 insertions, 31 deletions
diff --git a/src/directory.c b/src/directory.c
index ec0d24ba7..8f2765d26 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -553,7 +553,6 @@ int printDirectoryInfo(FILE * fp, char * name) {
return 0;
}
-/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */
void writeDirectoryInfo(FILE * fp, Directory * directory) {
ListNode * node = (directory->subDirectories)->firstNode;
Directory * subDirectory;
@@ -685,17 +684,12 @@ int writeDirectoryDB() {
while(!(fp=fopen(directorydb,"w")) && errno==EINTR);
if(!fp) return -1;
- /* block signals so we ensure the db doesn't get corrupted */
- /* no functions that writeDirectoryInfoCalls should mess with
- signals or signal blocking! */
- blockSignals();
myfprintf(fp,"%s\n",DIRECTORY_INFO_BEGIN);
myfprintf(fp,"%s%s\n",DIRECTORY_MPD_VERSION,VERSION);
myfprintf(fp,"%s%s\n",DIRECTORY_FS_CHARSET,getFsCharset());
myfprintf(fp,"%s\n",DIRECTORY_INFO_END);
writeDirectoryInfo(fp,mp3rootDirectory);
- unblockSignals();
while(fclose(fp) && errno==EINTR);
diff --git a/src/interface.c b/src/interface.c
index 9499d1049..83699e2f0 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -84,14 +84,13 @@ void openInterface(Interface * interface, int fd) {
assert(interface->open==0);
- blockSignals();
interface->bufferLength = 0;
interface->fd = fd;
/* fcntl(interface->fd,F_SETOWN,(int)getpid()); */
- flags = fcntl(fd,F_GETFL);
+ while((flags = fcntl(fd,F_GETFL))<0 && errno==EINTR);
flags|=O_NONBLOCK;
- fcntl(interface->fd,F_SETFL,flags);
- interface->fp = fdopen(fd,"rw");
+ while(fcntl(interface->fd,F_SETFL,flags)<0 && errno==EINTR);
+ while((interface->fp = fdopen(fd,"rw"))==NULL && errno==EINTR);
interface->open = 1;
interface->lastTime = time(NULL);
interface->commandList = NULL;
@@ -121,8 +120,6 @@ void openInterface(Interface * interface, int fd) {
#endif
interface->outBuffer = malloc(interface->outBufSize);
- unblockSignals();
-
myfprintf(interface->fp,"%s %s %s\n",COMMAND_RESPOND_OK,GREETING,
VERSION);
printInterfaceOutBuffer(interface);
diff --git a/src/myfprintf.c b/src/myfprintf.c
index 588e5df2f..77c11a297 100644
--- a/src/myfprintf.c
+++ b/src/myfprintf.c
@@ -33,6 +33,21 @@ int myfprintf_stdLogMode = 0;
FILE * myfprintf_out;
FILE * myfprintf_err;
+void blockingWrite(int fd, char * string) {
+ int len = strlen(string);
+ int ret;
+
+ while(len) {
+ ret = write(fd,string,len);
+ if(ret<0) {
+ if(errno==EAGAIN || errno==EINTR) continue;
+ return;
+ }
+ len-= ret;
+ string+= ret;
+ }
+}
+
void myfprintfStdLogMode(FILE * out, FILE * err) {
myfprintf_stdLogMode = 1;
myfprintf_out = out;
@@ -40,31 +55,33 @@ void myfprintfStdLogMode(FILE * out, FILE * err) {
}
void myfprintf(FILE * fp, char * format, ... ) {
+ char buffer[BUFFER_LENGTH+1];
va_list arglist;
int fd = fileno(fp);
int fcntlret;
+ memset(buffer,0,BUFFER_LENGTH+1);
+
va_start(arglist,format);
while((fcntlret=fcntl(fd,F_GETFL))==-1 && errno==EINTR);
if(myfprintf_stdLogMode && (fd==1 || fd==2)) {
- char str[15];
time_t t = time(NULL);
if(fd==1) fp = myfprintf_out;
else fp = myfprintf_err;
- strftime(str,14,"%b %e %R",localtime(&t));
- fprintf(fp,"%s : ",str);
- vfprintf(fp,format,arglist);
+ strftime(buffer,14,"%b %e %R",localtime(&t));
+ blockingWrite(fd,buffer);
+ blockingWrite(fd," : ");
+ vsnprintf(buffer,BUFFER_LENGTH,format,arglist);
+ blockingWrite(fd,buffer);
}
- else if(fcntlret & O_NONBLOCK) {
- char buffer[BUFFER_LENGTH+1];
+ else {
vsnprintf(buffer,BUFFER_LENGTH,format,arglist);
- if(interfacePrintWithFD(fd,buffer)<0) {
- /* not a fd from a interface */
- vfprintf(fp,format,arglist);
+ if((fcntlret & O_NONBLOCK) &&
+ interfacePrintWithFD(fd,buffer)==0)
+ {
}
+ else blockingWrite(fd,buffer);
}
- else vfprintf(fp,format,arglist);
- fflush(fp);
va_end(arglist);
}
diff --git a/src/player.c b/src/player.c
index 9376d01b3..b7c495979 100644
--- a/src/player.c
+++ b/src/player.c
@@ -397,7 +397,7 @@ int playerSeek(FILE * fp, char * utf8file, float time) {
if(strcmp(pc->file,file)!=0) {
decodeType = playerGetDecodeType(utf8file);
if(decodeType < 0) {
- printf("%s unknown file type: %s\n",
+ myfprintf(fp,"%s unknown file type: %s\n",
COMMAND_RESPOND_ERROR, utf8file);
return -1;
}
diff --git a/src/playlist.c b/src/playlist.c
index cf064047f..8bd5241bb 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -501,12 +501,12 @@ int swapSongsInPlaylist(FILE * fp, int song1, int song2) {
int currentSong = -1;
if(song1<0 || song1>=playlist.length) {
- fprintf(fp,"%s \"%i\" is not in the playlist\n",
+ myfprintf(fp,"%s \"%i\" is not in the playlist\n",
COMMAND_RESPOND_ERROR,song1);
return -1;
}
if(song2<0 || song2>=playlist.length) {
- fprintf(fp,"%s \"%i\" is not in the playlist\n",
+ myfprintf(fp,"%s \"%i\" is not in the playlist\n",
COMMAND_RESPOND_ERROR,song2);
return -1;
}
@@ -796,13 +796,13 @@ int moveSongInPlaylist(FILE * fp, int from, int to) {
int currentSong = -1;
if(from<0 || from>=playlist.length) {
- fprintf(fp,"%s \"%i\" is not a song in the playlist\n",
+ myfprintf(fp,"%s \"%i\" is not a song in the playlist\n",
COMMAND_RESPOND_ERROR,from);
return -1;
}
if(to<0 || to>=playlist.length) {
- fprintf(fp,"%s \"%i\" is not a song in the playlist\n",
+ myfprintf(fp,"%s \"%i\" is not a song in the playlist\n",
COMMAND_RESPOND_ERROR,to);
return -1;
}
diff --git a/src/song.c b/src/song.c
index 1c3d53ad2..d9b28284c 100644
--- a/src/song.c
+++ b/src/song.c
@@ -132,7 +132,6 @@ void freeSongList(SongList * list) {
freeList(list);
}
-/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */
int printSongInfo(FILE * fp, Song * song) {
myfprintf(fp,"%s%s\n",SONG_FILE,song->utf8file);
@@ -152,7 +151,6 @@ int printSongInfoFromList(FILE * fp, SongList * list) {
return 0;
}
-/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */
void writeSongInfoFromList(FILE * fp, SongList * list) {
ListNode * tempNode = list->firstNode;
diff --git a/src/tag.c b/src/tag.c
index c4623bb58..23128ae16 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -51,7 +51,6 @@
#include "mp4ff/mp4ff.h"
#endif
-/* DON'T BLOCK SIGNALS IN THIS FUNCTION, called by writeDirectoryDB() */
void printMpdTag(FILE * fp, MpdTag * tag) {
if(tag->artist) myfprintf(fp,"Artist: %s\n",tag->artist);
if(tag->album) myfprintf(fp,"Album: %s\n",tag->album);