aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-11-05 18:37:40 +0100
committerMax Kellermann <max@duempel.org>2008-11-05 18:37:40 +0100
commit08aaf57ff094632354cc54fcea90bd14a4edb76f (patch)
treec1fa9f2b1606a3ca6431eb7c564d2312599fcfdb /src
parentb35ca9e5c4d45eceba1baf355dea3349cadb73b4 (diff)
downloadmpd-08aaf57ff094632354cc54fcea90bd14a4edb76f.tar.gz
mpd-08aaf57ff094632354cc54fcea90bd14a4edb76f.tar.xz
mpd-08aaf57ff094632354cc54fcea90bd14a4edb76f.zip
log: removed warning buffer
The warning buffer is a complex piece of code for no good reason. Remove it and find a better solution, e.g. open the log file earlier.
Diffstat (limited to 'src')
-rw-r--r--src/log.c78
-rw-r--r--src/log.h2
-rw-r--r--src/main.c1
3 files changed, 2 insertions, 79 deletions
diff --git a/src/log.c b/src/log.c
index c5f94fa51..bfeea7505 100644
--- a/src/log.c
+++ b/src/log.c
@@ -36,10 +36,7 @@
#define LOG_DATE_BUF_SIZE 16
#define LOG_DATE_LEN (LOG_DATE_BUF_SIZE - 1)
static unsigned int logLevel = LOG_LEVEL_LOW;
-static int warningFlushed;
static int stdout_mode = 1;
-static char *warningBuffer;
-static pthread_mutex_t warning_buffer_lock = PTHREAD_MUTEX_INITIALIZER;
static int out_fd = -1;
static int err_fd = -1;
static const char *out_filename;
@@ -63,32 +60,6 @@ static const char *log_date(void)
return buf;
}
-#define BUFFER_LENGTH 4096
-static void buffer_warning(const char *fmt, va_list args)
-{
- char buffer[BUFFER_LENGTH];
- char *tmp = buffer;
- size_t len = BUFFER_LENGTH;
-
- if (!stdout_mode) {
- memcpy(buffer, log_date(), LOG_DATE_LEN);
- tmp += LOG_DATE_LEN;
- len -= LOG_DATE_LEN;
- }
-
- vsnprintf(tmp, len, fmt, args);
-
- if (warningBuffer == NULL)
- warningBuffer = g_strdup(tmp);
- else {
- tmp = g_strconcat(warningBuffer, tmp, NULL);
- g_free(warningBuffer);
- warningBuffer = tmp;
- }
-
- va_end(args);
-}
-
static void do_log(FILE *fp, const char *fmt, va_list args)
{
if (!stdout_mode)
@@ -96,34 +67,6 @@ static void do_log(FILE *fp, const char *fmt, va_list args)
vfprintf(fp, fmt, args);
}
-void flushWarningLog(void)
-{
- char *s;
-
- pthread_mutex_lock(&warning_buffer_lock);
- s = warningBuffer;
-
- DEBUG("flushing warning messages\n");
-
- if (warningBuffer != NULL)
- {
- while (s != NULL) {
- char *next = strchr(s, '\n');
- if (next == NULL) break;
- *next = '\0';
- next++;
- fprintf(stderr, "%s\n", s);
- s = next;
- }
-
- warningBuffer = NULL;
- }
- warningFlushed = 1;
- pthread_mutex_unlock(&warning_buffer_lock);
-
- DEBUG("done flushing warning messages\n");
-}
-
void initLog(const int verbose)
{
ConfigParam *param;
@@ -154,10 +97,8 @@ void open_log_files(const int use_stdout)
mode_t prev;
ConfigParam *param;
- if (use_stdout) {
- flushWarningLog();
+ if (use_stdout)
return;
- }
prev = umask(0066);
param = parseConfigFilePath(CONF_LOG_FILE, 1);
@@ -183,7 +124,6 @@ void setup_log_output(const int use_stdout)
if (!use_stdout) {
redirect_logs();
stdout_mode = 0;
- flushWarningLog();
}
}
@@ -199,27 +139,13 @@ mpd_printf void func(const char *fmt, ...) \
}
log_func(ERROR, 0, stderr)
+log_func(WARNING, 0, stderr)
log_func(LOG, 0, stdout)
log_func(SECURE, LOG_LEVEL_SECURE, stdout)
log_func(DEBUG, LOG_LEVEL_DEBUG, stdout)
#undef log_func
-void WARNING(const char *fmt, ...)
-{
- va_list args;
- va_start(args, fmt);
-
- pthread_mutex_lock(&warning_buffer_lock);
- if (warningFlushed)
- do_log(stderr, fmt, args);
- else
- buffer_warning(fmt, args);
- pthread_mutex_unlock(&warning_buffer_lock);
-
- va_end(args);
-}
-
mpd_printf mpd_noreturn void FATAL(const char *fmt, ...)
{
va_list args;
diff --git a/src/log.h b/src/log.h
index 2e76f0a73..c32b8e9c0 100644
--- a/src/log.h
+++ b/src/log.h
@@ -42,6 +42,4 @@ int cycle_log_files(void);
void close_log_files(void);
-void flushWarningLog(void);
-
#endif /* LOG_H */
diff --git a/src/main.c b/src/main.c
index 365d1780c..33c1125b7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -277,7 +277,6 @@ static void openDB(Options * options, char *argv0)
"\"--no-create-db\" command line option\n"
"try running \"%s --create-db\"\n", argv0);
}
- flushWarningLog();
if (db_check() < 0)
exit(EXIT_FAILURE);
db_init();