summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-04-15 05:07:04 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-04-15 05:07:04 +0000
commit7f29bb1a8d2eb5edc4e3ea50223370dd4ba4a96c (patch)
tree8d7850f7f6d786d8f4e7dfab0e4695e3ffef2938
parentdf3af7d4f121be6264c0ce307f4a75e844d7282c (diff)
log cycling and a few cleanups
git-svn-id: https://svn.musicpd.org/mpd/trunk@772 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--TODO17
-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
10 files changed, 80 insertions, 34 deletions
diff --git a/TODO b/TODO
index ab2841c90..d69c15aa6 100644
--- a/TODO
+++ b/TODO
@@ -6,9 +6,6 @@
e) abitility to disable resampling and audio format conversion
2) non-blocking (for other clients) update
- j) when reading new directory db, we should block some signals when
- manipulating the directorydb, so we don't receive a signal to
- quit in the middle of an update
k) when bg-update, have parent print out new old stuff to log on
reading db, not the child
n) mpd command for rereading db
@@ -17,14 +14,12 @@
and should be reread by parent process
p) set error: in status when an error occurs during update
-3) have children close all logging stuff, and redirect stdout and stderr to
-/dev/null, and set error bits in the shared log for the parent process
-to check when it receives a SIGUSR1, and print logs and then reset values of
-error bits. (don't redirect children's stdout and stderr to /dev/null if mpd is
-run with --no-daemon)
+3) cleanup main()
-4) cleanup main()
-
-5) crosslink "list" stuff, for example, artists are crosslinked to alubms and
+4) crosslink "list" stuff, for example, artists are crosslinked to alubms and
vice versa, this way you can do list album artists or list artist albums, this
will make life easier when we add genre and other metadata
+
+5) when writing combined interface for all decodes to use, be sure to add a
+common function and abstrct dealing with DecoderControl * and put
+cycleLogFiles in there, so we cycleLogFiles while decoding, not just when decoding has stopped.
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;