aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-06-12 02:06:16 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-06-12 02:06:16 +0000
commit43b355734cf192129f2906789185301a61f4cd8a (patch)
tree35a3a56a085fc590b1864347d49660d421157305
parent43255a7f63af65d88bbead4c0d6429ef2008ada8 (diff)
downloadmpd-43b355734cf192129f2906789185301a61f4cd8a.tar.gz
mpd-43b355734cf192129f2906789185301a61f4cd8a.tar.xz
mpd-43b355734cf192129f2906789185301a61f4cd8a.zip
Add WARNING log method. it's the same as ERROR, except that when mpd starts,
warnings are buffered until the error log is opened, and then flushed to the error log. git-svn-id: https://svn.musicpd.org/mpd/trunk@1442 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--TODO2
-rw-r--r--src/audio.c3
-rw-r--r--src/directory.c7
-rw-r--r--src/log.c41
-rw-r--r--src/log.h11
-rw-r--r--src/main.c8
-rw-r--r--src/myfprintf.h1
-rw-r--r--src/path.c18
-rw-r--r--src/utils.c20
-rw-r--r--src/utils.h3
-rw-r--r--src/volume.c30
11 files changed, 106 insertions, 38 deletions
diff --git a/TODO b/TODO
index 5f8dc8c93..11994d6a9 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,5 @@
*) put some sort of error reporting for streaming/inputStream!
-*) Fix charset errors so they don't goto stderr/out
-
Post-1.0
--------
1) crosslink "list" stuff, for example, artists are crosslinked to alubms and
diff --git a/src/audio.c b/src/audio.c
index afea52734..e677f8768 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -256,7 +256,7 @@ int playAudio(char * playChunk, int size) {
int send;
if(audio_device==NULL) {
- ERROR("trying to play w/ the audio device being open!\n");
+ ERROR("trying to play w/o the audio device being open!\n");
return -1;
}
@@ -302,4 +302,3 @@ void audioError() {
}
#endif
}
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/directory.c b/src/directory.c
index 959ade487..0d1b0ee2b 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -931,7 +931,7 @@ int readDirectoryDB() {
char * tempCharset;
if(foundFsCharset) {
- ERROR("already found "
+ WARNING("already found "
"fs charset in db\n");
exit(EXIT_FAILURE);
}
@@ -944,11 +944,11 @@ int readDirectoryDB() {
getConf()[CONF_FS_CHARSET]) &&
strcmp(fsCharset,tempCharset))
{
- ERROR("Using \"%s\" for the "
+ WARNING("Using \"%s\" for the "
"filesystem charset "
"instead of \"%s\"\n",
fsCharset,tempCharset);
- ERROR("maybe you need to "
+ WARNING("maybe you need to "
"recreate the db?\n");
setFsCharset(fsCharset);
}
@@ -1275,4 +1275,3 @@ Song * getSongFromDB(char * file) {
time_t getDbModTime() {
return directory_dbModTime;
}
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/log.c b/src/log.c
index bdc7cf935..835fa9e00 100644
--- a/src/log.c
+++ b/src/log.c
@@ -20,10 +20,16 @@
#include "conf.h"
#include "myfprintf.h"
+#include "utils.h"
+#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
int logLevel = LOG_LEVEL_LOW;
+short warningFlushed = 0;
+
+static char * warningBuffer = NULL;
void initLog() {
if(strcmp(getConf()[CONF_LOG_LEVEL],"default")==0) {
@@ -37,4 +43,37 @@ void initLog() {
}
else ERROR("unknown log level \"%s\"\n",getConf()[CONF_LOG_LEVEL]);
}
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
+
+#define BUFFER_LENGTH 4096
+
+void bufferWarning(char * format, ... ) {
+ va_list arglist;
+ char temp[BUFFER_LENGTH+1];
+
+ memset(temp, 0, BUFFER_LENGTH+1);
+
+ va_start(arglist, format);
+
+ vsnprintf(temp, BUFFER_LENGTH, format, arglist);
+
+ warningBuffer = appendToString(warningBuffer, temp);
+
+ va_end(arglist);
+}
+void flushWarningLog() {
+ char * s;
+
+ if(warningBuffer == NULL) return;
+
+ s = strtok(warningBuffer, "\n");
+ while ( s != NULL ) {
+ myfprintf(stderr, "%s\n", s);
+
+ s = strtok(NULL, "\n");
+ }
+
+ free(warningBuffer);
+ warningBuffer = NULL;
+
+ warningFlushed = 1;
+}
diff --git a/src/log.h b/src/log.h
index ccb407a07..3bda616b6 100644
--- a/src/log.h
+++ b/src/log.h
@@ -28,6 +28,7 @@
#define LOG_LEVEL_DEBUG 2
extern int logLevel;
+extern short warningFlushed;
#define ERROR(...) myfprintf(stderr, __VA_ARGS__)
@@ -40,7 +41,15 @@ extern int logLevel;
#define DEBUG(...) if(logLevel>=LOG_LEVEL_DEBUG) \
myfprintf(stdout, __VA_ARGS__)
+#define WARNING(...) { \
+ if(warningFlushed) myfprintf(stderr, __VA_ARGS__); \
+ else bufferWarning(__VA_ARGS__); \
+}
+
void initLog();
+void bufferWarning(char * format, ... );
+
+void flushWarningLog();
+
#endif
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/main.c b/src/main.c
index 58eb8d98a..c65d00e1c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -289,7 +289,10 @@ void changeToUser(Options * options) {
}
void openLogFiles(Options * options, FILE ** out, FILE ** err) {
- if(options->stdOutput) return;
+ if(options->stdOutput) {
+ flushWarningLog();
+ return;
+ }
if(NULL==(*out=fopen(options->logFile,"a"))) {
ERROR("problem opening file \"%s\" for writing\n",
@@ -316,6 +319,7 @@ void openDB(Options * options, char * argv0) {
argv0);
exit(EXIT_FAILURE);
}
+ flushWarningLog();
initMp3Directory();
if(writeDirectoryDB()<0) {
ERROR("problem opening db for reading or writing\n");
@@ -324,6 +328,7 @@ void openDB(Options * options, char * argv0) {
if(options->createDB) exit(EXIT_SUCCESS);
}
if(options->updateDB) {
+ flushWarningLog();
updateMp3Directory();
exit(EXIT_SUCCESS);
}
@@ -379,6 +384,7 @@ void setupLogOutput(Options * options, FILE * out, FILE * err) {
myfprintfStdLogMode(out, err, options->logFile,
options->errorFile);
+ flushWarningLog();
}
/* lets redirect stdin to dev null as a work around for libao bug */
diff --git a/src/myfprintf.h b/src/myfprintf.h
index 31d1c88c0..ad42ec794 100644
--- a/src/myfprintf.h
+++ b/src/myfprintf.h
@@ -31,4 +31,3 @@ void myfprintf(FILE * fp, char * format, ... );
int myfprintfCloseAndOpenLogFile();
#endif
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/path.c b/src/path.c
index d7b08d6be..61c9f7040 100644
--- a/src/path.c
+++ b/src/path.c
@@ -86,13 +86,13 @@ void setFsCharset(char * charset) {
DEBUG("setFsCharset: fs charset is: %s\n",fsCharset);
if(setCharSetConversion("UTF-8",fsCharset)!=0) {
- ERROR("fs charset conversion problem: "
+ WARNING("fs charset conversion problem: "
"not able to convert from \"%s\" to \"%s\"\n",
fsCharset,"UTF-8");
error = 1;
}
if(setCharSetConversion(fsCharset,"UTF-8")!=0) {
- ERROR("fs charset conversion problem: "
+ WARNING("fs charset conversion problem: "
"not able to convert from \"%s\" to \"%s\"\n",
"UTF-8",fsCharset);
error = 1;
@@ -100,7 +100,7 @@ void setFsCharset(char * charset) {
if(error) {
free(fsCharset);
- ERROR("setting fs charset to ISO-8859-1!\n");
+ WARNING("setting fs charset to ISO-8859-1!\n");
fsCharset = strdup("ISO-8859-1");
}
}
@@ -145,28 +145,28 @@ void initPaths(char * playlistDirArg, char * musicDirArg) {
originalLocale = strdup(originalLocale);
if(!(currentLocale = setlocale(LC_CTYPE,""))) {
- ERROR("problems setting current locale with "
+ WARNING("problems setting current locale with "
"setlocale()\n");
}
else {
if(strcmp(currentLocale,"C")==0 ||
strcmp(currentLocale,"POSIX")==0)
{
- ERROR("current locale is \"%s\"\n",
+ WARNING("current locale is \"%s\"\n",
currentLocale);
}
else if((temp = nl_langinfo(CODESET))) {
charset = strdup(temp);
}
- else ERROR("problems getting charset for locale\n");
+ else WARNING("problems getting charset for locale\n");
if(!setlocale(LC_CTYPE,originalLocale)) {
- ERROR("problems resetting locale with setlocale()\n");
+ WARNING("problems resetting locale with setlocale()\n");
}
}
free(originalLocale);
}
- else ERROR("problems getting locale with setlocale()\n");
+ else WARNING("problems getting locale with setlocale()\n");
#endif
#endif
@@ -175,7 +175,7 @@ void initPaths(char * playlistDirArg, char * musicDirArg) {
free(charset);
}
else {
- ERROR("setting filesystem charset to ISO-8859-1\n");
+ WARNING("setting filesystem charset to ISO-8859-1\n");
setFsCharset("ISO-8859-1");
}
}
diff --git a/src/utils.c b/src/utils.c
index ece410b2c..fbcf3d9dd 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -70,4 +70,22 @@ int ipv6Supported() {
return 0;
}
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
+char * appendToString(char * dest, const char * src) {
+ int destlen;
+ int srclen = strlen(src);
+
+ if(dest == NULL) {
+ dest = malloc(srclen+1);
+ memset(dest, 0, srclen+1);
+ destlen = 0;
+ }
+ else {
+ destlen = strlen(dest);
+ dest = realloc(dest, destlen+srclen+1);
+ }
+
+ memcpy(dest+destlen, src, srclen);
+ dest[destlen+srclen] = '\0';
+
+ return dest;
+}
diff --git a/src/utils.h b/src/utils.h
index fd03915f9..545f1653d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -33,5 +33,6 @@ void my_usleep(long usec);
int ipv6Supported();
+char * appendToString(char * dest, const char * src);
+
#endif
-/* vim:set shiftwidth=4 tabstop=8 expandtab: */
diff --git a/src/volume.c b/src/volume.c
index 42f72ba48..4a1370b2f 100644
--- a/src/volume.c
+++ b/src/volume.c
@@ -68,7 +68,7 @@ int prepOssMixer(char * device) {
int devmask = 0;
if((volume_ossFd = open(device,O_RDONLY))<0) {
- ERROR("unable to open oss mixer \"%s\"\n",device);
+ WARNING("unable to open oss mixer \"%s\"\n",device);
return -1;
}
@@ -78,7 +78,7 @@ int prepOssMixer(char * device) {
int i,j;
if(ioctl(volume_ossFd,SOUND_MIXER_READ_DEVMASK,&devmask)<0) {
- ERROR("errors getting read_devmask for oss mixer\n");
+ WARNING("errors getting read_devmask for oss mixer\n");
close(volume_ossFd);
return -1;
}
@@ -96,13 +96,13 @@ int prepOssMixer(char * device) {
}
if(i>=SOUND_MIXER_NRDEVICES) {
- ERROR("mixer control \"%s\" not found\n",
+ WARNING("mixer control \"%s\" not found\n",
getConf()[CONF_MIXER_CONTROL]);
close(volume_ossFd);
return -1;
}
else if(!( ( 1 << i ) & devmask )) {
- ERROR("mixer control \"%s\" not usable\n",
+ WARNING("mixer control \"%s\" not usable\n",
getConf()[CONF_MIXER_CONTROL]);
close(volume_ossFd);
return -1;
@@ -122,7 +122,7 @@ int getOssVolumeLevel() {
int left, right, level;
if(ioctl(volume_ossFd,MIXER_READ(volume_ossControl),&level) < 0) {
- ERROR("unable to read volume\n");
+ WARNING("unable to read volume\n");
return -1;
}
@@ -130,7 +130,7 @@ int getOssVolumeLevel() {
right = (level & 0xff00) >> 8;
if(left!=right) {
- ERROR("volume for left and right is not the same, \"%i\" and "
+ WARNING("volume for left and right is not the same, \"%i\" and "
"\"%i\"\n",left,right);
}
@@ -174,27 +174,27 @@ int prepAlsaMixer(char * card) {
char * controlName = VOLUME_MIXER_ALSA_CONTROL_DEFAULT;
if((err = snd_mixer_open(&volume_alsaMixerHandle,0))<0) {
- ERROR("problems opening alsa mixer: %s\n",snd_strerror(err));
+ WARNING("problems opening alsa mixer: %s\n",snd_strerror(err));
return -1;
}
if((err = snd_mixer_attach(volume_alsaMixerHandle,card))<0) {
snd_mixer_close(volume_alsaMixerHandle);
- ERROR("problems problems attaching alsa mixer: %s\n",
+ WARNING("problems problems attaching alsa mixer: %s\n",
snd_strerror(err));
return -1;
}
if((err = snd_mixer_selem_register(volume_alsaMixerHandle,NULL,NULL))<0) {
snd_mixer_close(volume_alsaMixerHandle);
- ERROR("problems snd_mixer_selem_register'ing: %s\n",
+ WARNING("problems snd_mixer_selem_register'ing: %s\n",
snd_strerror(err));
return -1;
}
if((err = snd_mixer_load(volume_alsaMixerHandle))<0) {
snd_mixer_close(volume_alsaMixerHandle);
- ERROR("problems snd_mixer_selem_register'ing: %s\n",
+ WARNING("problems snd_mixer_selem_register'ing: %s\n",
snd_strerror(err));
return -1;
}
@@ -223,7 +223,7 @@ int prepAlsaMixer(char * card) {
return 0;
}
- ERROR("can't find alsa mixer_control \"%s\"\n",controlName);
+ WARNING("can't find alsa mixer_control \"%s\"\n",controlName);
snd_mixer_close(volume_alsaMixerHandle);
return -1;
@@ -244,7 +244,7 @@ int getAlsaVolumeLevel() {
if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem,
SND_MIXER_SCHN_FRONT_LEFT,&level))<0) {
- ERROR("problems getting alsa volume: %s\n",snd_strerror(err));
+ WARNING("problems getting alsa volume: %s\n",snd_strerror(err));
return -1;
}
@@ -272,7 +272,7 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) {
if((err = snd_mixer_selem_get_playback_volume(volume_alsaElem,
SND_MIXER_SCHN_FRONT_LEFT,&level))<0) {
commandError(fp, ACK_ERROR_SYSTEM, "problems getting volume");
- ERROR("problems getting alsa volume: %s\n",snd_strerror(err));
+ WARNING("problems getting alsa volume: %s\n",snd_strerror(err));
return -1;
}
@@ -298,7 +298,7 @@ int changeAlsaVolumeLevel(FILE * fp, int change, int rel) {
if((err = snd_mixer_selem_set_playback_volume_all(
volume_alsaElem,level))<0) {
commandError(fp, ACK_ERROR_SYSTEM, "problems setting volume");
- ERROR("problems setting alsa volume: %s\n",snd_strerror(err));
+ WARNING("problems setting alsa volume: %s\n",snd_strerror(err));
return -1;
}
@@ -365,7 +365,7 @@ void initVolume() {
void openVolumeDevice() {
if(prepMixer(volume_mixerDevice)<0) {
- ERROR("using software volume\n");
+ WARNING("using software volume\n");
volume_mixerType = VOLUME_MIXER_TYPE_SOFTWARE;
}
}