aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decode.c8
-rw-r--r--src/decode.h13
-rw-r--r--src/main.c18
-rw-r--r--src/myfprintf.c35
-rw-r--r--src/myfprintf.h5
-rw-r--r--src/ogg_decode.c1
-rw-r--r--src/player.c13
-rw-r--r--src/player.h1
-rw-r--r--src/sig_handlers.c3
9 files changed, 74 insertions, 23 deletions
diff --git a/src/decode.c b/src/decode.c
index baea58e4b..fc0bd84af 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -174,6 +174,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
}
#define processDecodeInput() \
+ if(pc->cycleLogFiles) { \
+ myfprintfCloseAndOpenLogFile(); \
+ pc->cycleLogFiles = 0; \
+ } \
if(pc->lockQueue) { \
pc->queueLockState = PLAYER_QUEUE_LOCKED; \
pc->lockQueue = 0; \
@@ -277,6 +281,10 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
dc->stop = 0;
}
else if(dc->seek) dc->start = 1;
+ if(dc->cycleLogFiles) {
+ myfprintfCloseAndOpenLogFile();
+ dc->cycleLogFiles = 0;
+ }
else my_usleep(10000);
}
diff --git a/src/decode.h b/src/decode.h
index fc56ca5f0..8d4168a62 100644
--- a/src/decode.h
+++ b/src/decode.h
@@ -41,12 +41,13 @@
#define DECODE_ERROR_FILE 2
typedef struct _DecoderControl {
- mpd_sint8 state;
- mpd_sint8 stop;
- mpd_sint8 start;
- mpd_uint16 error;
- mpd_sint8 seek;
- mpd_sint8 seekError;
+ volatile mpd_sint8 state;
+ volatile mpd_sint8 stop;
+ volatile mpd_sint8 start;
+ volatile mpd_uint16 error;
+ volatile mpd_sint8 seek;
+ volatile mpd_sint8 seekError;
+ volatile mpd_sint8 cycleLogFiles;
double seekWhere;
char file[MAXPATHLEN+1];
} DecoderControl;
diff --git a/src/main.c b/src/main.c
index 69560dbf3..944c1af76 100644
--- a/src/main.c
+++ b/src/main.c
@@ -356,31 +356,19 @@ int main(int argc, char * argv[]) {
exit(EXIT_FAILURE);
}
- if(close(STDOUT_FILENO)) {
- fprintf(err,"problems closing stdout : %s\n",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
-
- if(close(STDERR_FILENO)) {
- fprintf(err,"problems closing stderr : %s\n",
- strerror(errno));
- exit(EXIT_FAILURE);
- }
-
if(dup2(fileno(out),STDOUT_FILENO)<0) {
- fprintf(err,"problems dup2 stdout : %s\n",
+ myfprintf(err,"problems dup2 stdout : %s\n",
strerror(errno));
exit(EXIT_FAILURE);
}
if(dup2(fileno(err),STDERR_FILENO)<0) {
- fprintf(err,"problems dup2 stderr : %s\n",
+ myfprintf(err,"problems dup2 stderr : %s\n",
strerror(errno));
exit(EXIT_FAILURE);
}
- myfprintfStdLogMode(out,err);
+ myfprintfStdLogMode(out,err,options.logFile,options.errorFile);
fflush(NULL);
pid = fork();
diff --git a/src/myfprintf.c b/src/myfprintf.c
index a975a3c94..0947531bb 100644
--- a/src/myfprintf.c
+++ b/src/myfprintf.c
@@ -18,6 +18,8 @@
#include "myfprintf.h"
#include "interface.h"
+#include "path.h"
+#include "log.h"
#include <stdarg.h>
#include <sys/param.h>
@@ -32,6 +34,8 @@
int myfprintf_stdLogMode = 0;
FILE * myfprintf_out;
FILE * myfprintf_err;
+char * myfprintf_outFilename;
+char * myfprintf_errFilename;
void blockingWrite(int fd, char * string) {
int len = strlen(string);
@@ -48,10 +52,14 @@ void blockingWrite(int fd, char * string) {
}
}
-void myfprintfStdLogMode(FILE * out, FILE * err) {
+void myfprintfStdLogMode(FILE * out, FILE * err, char * outFilename,
+ char * errFilename)
+{
myfprintf_stdLogMode = 1;
myfprintf_out = out;
myfprintf_err = err;
+ myfprintf_outFilename = prependCwdToPathDup(outFilename);
+ myfprintf_errFilename = prependCwdToPathDup(errFilename);
}
void myfprintf(FILE * fp, char * format, ... ) {
@@ -85,4 +93,29 @@ void myfprintf(FILE * fp, char * format, ... ) {
va_end(arglist);
}
+
+int myfprintfCloseAndOpenLogFile() {
+ if(myfprintf_stdLogMode) {
+ while(fclose(myfprintf_out)<0 && errno==EINTR);
+ while(fclose(myfprintf_err)<0 && errno==EINTR);
+ while((myfprintf_out = fopen(myfprintf_outFilename,"a+"))==NULL
+ && errno==EINTR);
+ if(!myfprintf_out) {
+ ERROR("error re-opening log file: %s\n",
+ myfprintf_out);
+ return -1;
+ }
+ while((myfprintf_err = fopen(myfprintf_errFilename,"a+"))==NULL
+ && errno==EINTR);
+ if(!myfprintf_out) {
+ ERROR("error re-opening log file: %s\n",
+ myfprintf_out);
+ return -1;
+ }
+ while(dup2(fileno(myfprintf_out),1)<0 && errno==EINTR);
+ while(dup2(fileno(myfprintf_err),2)<0 && errno==EINTR);
+ }
+
+ return 0;
+}
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/myfprintf.h b/src/myfprintf.h
index 5f21296bf..31d1c88c0 100644
--- a/src/myfprintf.h
+++ b/src/myfprintf.h
@@ -23,9 +23,12 @@
#include <stdio.h>
-void myfprintfStdLogMode(FILE * out, FILE * err);
+void myfprintfStdLogMode(FILE * out, FILE * err, char * outFilename,
+ char * errFilename);
void myfprintf(FILE * fp, char * format, ... );
+int myfprintfCloseAndOpenLogFile();
+
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/ogg_decode.c b/src/ogg_decode.c
index 6a12dbe07..7d673d462 100644
--- a/src/ogg_decode.c
+++ b/src/ogg_decode.c
@@ -116,6 +116,7 @@ int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
}
if(dc->stop) break;
else if(dc->seek) continue;
+
memcpy(cb->chunks+cb->end*CHUNK_SIZE,
chunk,chunkpos);
cb->chunkSize[cb->end] = chunkpos;
diff --git a/src/player.c b/src/player.c
index a9ab8fe1d..b73652bb6 100644
--- a/src/player.c
+++ b/src/player.c
@@ -139,6 +139,10 @@ int playerInit() {
pc->queueLockState = PLAYER_QUEUE_UNLOCKED;
pc->unlockQueue = 0;
}
+ else if(pc->cycleLogFiles) {
+ myfprintfCloseAndOpenLogFile();
+ pc->cycleLogFiles = 0;
+ }
else my_usleep(10000);
}
@@ -474,4 +478,13 @@ int getPlayerChannels() {
return pc->channels;
}
+
+void playerCycleLogFiles() {
+ PlayerControl * pc = &(getPlayerData()->playerControl);
+ DecoderControl * dc = &(getPlayerData()->decoderControl);
+
+ pc->cycleLogFiles = 1;
+ dc->cycleLogFiles = 1;
+}
+
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/player.h b/src/player.h
index e92e14a8b..d4c2c1811 100644
--- a/src/player.h
+++ b/src/player.h
@@ -77,6 +77,7 @@ typedef struct _PlayerControl {
volatile mpd_uint16 softwareVolume;
volatile double totalPlayTime;
volatile int decode_pid;
+ volatile mpd_sint8 cycleLogFiles;
} PlayerControl;
void clearPlayerPid();
diff --git a/src/sig_handlers.c b/src/sig_handlers.c
index 06f7bf765..c3f1d787b 100644
--- a/src/sig_handlers.c
+++ b/src/sig_handlers.c
@@ -23,6 +23,7 @@
#include "command.h"
#include "signal_check.h"
#include "log.h"
+#include "player.h"
#include <signal.h>
#include <sys/types.h>
@@ -44,6 +45,8 @@ int handlePendingSignals() {
readDirectoryDB();
incrPlaylistVersion();
}
+ if(myfprintfCloseAndOpenLogFile()<0) return COMMAND_RETURN_KILL;
+ playerCycleLogFiles();
}
return 0;