log cycling and a few cleanups

git-svn-id: https://svn.musicpd.org/mpd/trunk@772 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-04-15 05:07:04 +00:00
parent df3af7d4f1
commit 7f29bb1a8d
10 changed files with 80 additions and 34 deletions

17
TODO
View File

@ -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.

View File

@ -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);
}

View File

@ -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;

View File

@ -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();

View File

@ -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: */

View File

@ -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: */

View File

@ -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;

View File

@ -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: */

View File

@ -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();

View File

@ -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;