Commit 7f29bb1a authored by Warren Dukes's avatar Warren Dukes

log cycling and a few cleanups

git-svn-id: https://svn.musicpd.org/mpd/trunk@772 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent df3af7d4
...@@ -6,9 +6,6 @@ ...@@ -6,9 +6,6 @@
e) abitility to disable resampling and audio format conversion e) abitility to disable resampling and audio format conversion
2) non-blocking (for other clients) update 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 k) when bg-update, have parent print out new old stuff to log on
reading db, not the child reading db, not the child
n) mpd command for rereading db n) mpd command for rereading db
...@@ -17,14 +14,12 @@ ...@@ -17,14 +14,12 @@
and should be reread by parent process and should be reread by parent process
p) set error: in status when an error occurs during update p) set error: in status when an error occurs during update
3) have children close all logging stuff, and redirect stdout and stderr to 3) cleanup main()
/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)
4) cleanup main() 4) crosslink "list" stuff, for example, artists are crosslinked to alubms and
5) 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 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 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.
...@@ -174,6 +174,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, ...@@ -174,6 +174,10 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
} }
#define processDecodeInput() \ #define processDecodeInput() \
if(pc->cycleLogFiles) { \
myfprintfCloseAndOpenLogFile(); \
pc->cycleLogFiles = 0; \
} \
if(pc->lockQueue) { \ if(pc->lockQueue) { \
pc->queueLockState = PLAYER_QUEUE_LOCKED; \ pc->queueLockState = PLAYER_QUEUE_LOCKED; \
pc->lockQueue = 0; \ pc->lockQueue = 0; \
...@@ -277,6 +281,10 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af, ...@@ -277,6 +281,10 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
dc->stop = 0; dc->stop = 0;
} }
else if(dc->seek) dc->start = 1; else if(dc->seek) dc->start = 1;
if(dc->cycleLogFiles) {
myfprintfCloseAndOpenLogFile();
dc->cycleLogFiles = 0;
}
else my_usleep(10000); else my_usleep(10000);
} }
......
...@@ -41,12 +41,13 @@ ...@@ -41,12 +41,13 @@
#define DECODE_ERROR_FILE 2 #define DECODE_ERROR_FILE 2
typedef struct _DecoderControl { typedef struct _DecoderControl {
mpd_sint8 state; volatile mpd_sint8 state;
mpd_sint8 stop; volatile mpd_sint8 stop;
mpd_sint8 start; volatile mpd_sint8 start;
mpd_uint16 error; volatile mpd_uint16 error;
mpd_sint8 seek; volatile mpd_sint8 seek;
mpd_sint8 seekError; volatile mpd_sint8 seekError;
volatile mpd_sint8 cycleLogFiles;
double seekWhere; double seekWhere;
char file[MAXPATHLEN+1]; char file[MAXPATHLEN+1];
} DecoderControl; } DecoderControl;
......
...@@ -356,31 +356,19 @@ int main(int argc, char * argv[]) { ...@@ -356,31 +356,19 @@ int main(int argc, char * argv[]) {
exit(EXIT_FAILURE); 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) { if(dup2(fileno(out),STDOUT_FILENO)<0) {
fprintf(err,"problems dup2 stdout : %s\n", myfprintf(err,"problems dup2 stdout : %s\n",
strerror(errno)); strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(dup2(fileno(err),STDERR_FILENO)<0) { if(dup2(fileno(err),STDERR_FILENO)<0) {
fprintf(err,"problems dup2 stderr : %s\n", myfprintf(err,"problems dup2 stderr : %s\n",
strerror(errno)); strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
myfprintfStdLogMode(out,err); myfprintfStdLogMode(out,err,options.logFile,options.errorFile);
fflush(NULL); fflush(NULL);
pid = fork(); pid = fork();
......
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
#include "myfprintf.h" #include "myfprintf.h"
#include "interface.h" #include "interface.h"
#include "path.h"
#include "log.h"
#include <stdarg.h> #include <stdarg.h>
#include <sys/param.h> #include <sys/param.h>
...@@ -32,6 +34,8 @@ ...@@ -32,6 +34,8 @@
int myfprintf_stdLogMode = 0; int myfprintf_stdLogMode = 0;
FILE * myfprintf_out; FILE * myfprintf_out;
FILE * myfprintf_err; FILE * myfprintf_err;
char * myfprintf_outFilename;
char * myfprintf_errFilename;
void blockingWrite(int fd, char * string) { void blockingWrite(int fd, char * string) {
int len = strlen(string); int len = strlen(string);
...@@ -48,10 +52,14 @@ void blockingWrite(int fd, char * 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_stdLogMode = 1;
myfprintf_out = out; myfprintf_out = out;
myfprintf_err = err; myfprintf_err = err;
myfprintf_outFilename = prependCwdToPathDup(outFilename);
myfprintf_errFilename = prependCwdToPathDup(errFilename);
} }
void myfprintf(FILE * fp, char * format, ... ) { void myfprintf(FILE * fp, char * format, ... ) {
...@@ -85,4 +93,29 @@ void myfprintf(FILE * fp, char * format, ... ) { ...@@ -85,4 +93,29 @@ void myfprintf(FILE * fp, char * format, ... ) {
va_end(arglist); 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: */ /* vim:set shiftwidth=4 tabstop=8 expandtab: */
...@@ -23,9 +23,12 @@ ...@@ -23,9 +23,12 @@
#include <stdio.h> #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, ... ); void myfprintf(FILE * fp, char * format, ... );
int myfprintfCloseAndOpenLogFile();
#endif #endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */ /* vim:set shiftwidth=4 tabstop=8 expandtab: */
...@@ -116,6 +116,7 @@ int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) ...@@ -116,6 +116,7 @@ int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
} }
if(dc->stop) break; if(dc->stop) break;
else if(dc->seek) continue; else if(dc->seek) continue;
memcpy(cb->chunks+cb->end*CHUNK_SIZE, memcpy(cb->chunks+cb->end*CHUNK_SIZE,
chunk,chunkpos); chunk,chunkpos);
cb->chunkSize[cb->end] = chunkpos; cb->chunkSize[cb->end] = chunkpos;
......
...@@ -139,6 +139,10 @@ int playerInit() { ...@@ -139,6 +139,10 @@ int playerInit() {
pc->queueLockState = PLAYER_QUEUE_UNLOCKED; pc->queueLockState = PLAYER_QUEUE_UNLOCKED;
pc->unlockQueue = 0; pc->unlockQueue = 0;
} }
else if(pc->cycleLogFiles) {
myfprintfCloseAndOpenLogFile();
pc->cycleLogFiles = 0;
}
else my_usleep(10000); else my_usleep(10000);
} }
...@@ -474,4 +478,13 @@ int getPlayerChannels() { ...@@ -474,4 +478,13 @@ int getPlayerChannels() {
return pc->channels; 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: */ /* vim:set shiftwidth=4 tabstop=8 expandtab: */
...@@ -77,6 +77,7 @@ typedef struct _PlayerControl { ...@@ -77,6 +77,7 @@ typedef struct _PlayerControl {
volatile mpd_uint16 softwareVolume; volatile mpd_uint16 softwareVolume;
volatile double totalPlayTime; volatile double totalPlayTime;
volatile int decode_pid; volatile int decode_pid;
volatile mpd_sint8 cycleLogFiles;
} PlayerControl; } PlayerControl;
void clearPlayerPid(); void clearPlayerPid();
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "command.h" #include "command.h"
#include "signal_check.h" #include "signal_check.h"
#include "log.h" #include "log.h"
#include "player.h"
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -44,6 +45,8 @@ int handlePendingSignals() { ...@@ -44,6 +45,8 @@ int handlePendingSignals() {
readDirectoryDB(); readDirectoryDB();
incrPlaylistVersion(); incrPlaylistVersion();
} }
if(myfprintfCloseAndOpenLogFile()<0) return COMMAND_RETURN_KILL;
playerCycleLogFiles();
} }
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment