diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-04-15 05:07:04 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-04-15 05:07:04 +0000 |
commit | 7f29bb1a8d2eb5edc4e3ea50223370dd4ba4a96c (patch) | |
tree | 8d7850f7f6d786d8f4e7dfab0e4695e3ffef2938 /src/myfprintf.c | |
parent | df3af7d4f121be6264c0ce307f4a75e844d7282c (diff) | |
download | mpd-7f29bb1a8d2eb5edc4e3ea50223370dd4ba4a96c.tar.gz mpd-7f29bb1a8d2eb5edc4e3ea50223370dd4ba4a96c.tar.xz mpd-7f29bb1a8d2eb5edc4e3ea50223370dd4ba4a96c.zip |
log cycling and a few cleanups
git-svn-id: https://svn.musicpd.org/mpd/trunk@772 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/myfprintf.c')
-rw-r--r-- | src/myfprintf.c | 35 |
1 files changed, 34 insertions, 1 deletions
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: */ |