2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2006-07-14 21:37:45 +02:00
|
|
|
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "log.h"
|
|
|
|
|
|
|
|
#include "conf.h"
|
|
|
|
#include "myfprintf.h"
|
2004-06-12 04:06:16 +02:00
|
|
|
#include "utils.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2004-06-12 04:06:16 +02:00
|
|
|
#include <stdlib.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
#include <string.h>
|
2004-06-12 04:06:16 +02:00
|
|
|
#include <stdarg.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
int logLevel = LOG_LEVEL_LOW;
|
2004-06-12 04:06:16 +02:00
|
|
|
short warningFlushed = 0;
|
|
|
|
|
|
|
|
static char * warningBuffer = NULL;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
sparse: ANSI-fy function declarations
These are just warnings from sparse, but it makes the output
easier to read. I ran this through a quick perl script, but
of course verified the output by looking at the diff and making
sure the thing still compiles.
here's the quick perl script I wrote to generate this patch:
----------- 8< -----------
use Tie::File;
defined(my $pid = open my $fh, '-|') or die $!;
if (!$pid) {
open STDERR, '>&STDOUT' or die $!;
exec 'sparse', @ARGV or die $!;
}
my $na = 'warning: non-ANSI function declaration of function';
while (<$fh>) {
print STDERR $_;
if (/^(.+?\.[ch]):(\d+):(\d+): $na '(\w+)'/o) {
my ($f, $l, $pos, $func) = ($1, $2, $3, $4);
$l--;
tie my @x, 'Tie::File', $f or die "$!: $f";
print '-', $x[$l], "\n";
$x[$l] =~ s/\b($func\s*)\(\s*\)/$1(void)/;
print '+', $x[$l], "\n";
untie @x;
}
}
git-svn-id: https://svn.musicpd.org/mpd/trunk@4378 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-17 02:15:34 +02:00
|
|
|
void initLog(void) {
|
2004-10-28 07:14:55 +02:00
|
|
|
ConfigParam * param = getConfigParam(CONF_LOG_LEVEL);
|
|
|
|
|
|
|
|
if(!param) return;
|
|
|
|
|
|
|
|
if(0 == strcmp(param->value, "default")) {
|
2004-02-24 00:41:20 +01:00
|
|
|
if(logLevel<LOG_LEVEL_LOW) logLevel = LOG_LEVEL_LOW;
|
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
else if(0 == strcmp(param->value, "secure")) {
|
2004-02-24 00:41:20 +01:00
|
|
|
if(logLevel<LOG_LEVEL_SECURE) logLevel = LOG_LEVEL_SECURE;
|
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
else if(0 == strcmp(param->value, "verbose")) {
|
2004-02-24 00:41:20 +01:00
|
|
|
if(logLevel<LOG_LEVEL_DEBUG) logLevel = LOG_LEVEL_DEBUG;
|
|
|
|
}
|
2004-10-28 07:14:55 +02:00
|
|
|
else {
|
|
|
|
ERROR("unknown log level \"%s\" at line %i\n",
|
|
|
|
param->value, param->line);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2004-06-12 04:06:16 +02:00
|
|
|
|
|
|
|
#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);
|
|
|
|
}
|
2005-03-12 04:10:09 +01:00
|
|
|
|
sparse: ANSI-fy function declarations
These are just warnings from sparse, but it makes the output
easier to read. I ran this through a quick perl script, but
of course verified the output by looking at the diff and making
sure the thing still compiles.
here's the quick perl script I wrote to generate this patch:
----------- 8< -----------
use Tie::File;
defined(my $pid = open my $fh, '-|') or die $!;
if (!$pid) {
open STDERR, '>&STDOUT' or die $!;
exec 'sparse', @ARGV or die $!;
}
my $na = 'warning: non-ANSI function declaration of function';
while (<$fh>) {
print STDERR $_;
if (/^(.+?\.[ch]):(\d+):(\d+): $na '(\w+)'/o) {
my ($f, $l, $pos, $func) = ($1, $2, $3, $4);
$l--;
tie my @x, 'Tie::File', $f or die "$!: $f";
print '-', $x[$l], "\n";
$x[$l] =~ s/\b($func\s*)\(\s*\)/$1(void)/;
print '+', $x[$l], "\n";
untie @x;
}
}
git-svn-id: https://svn.musicpd.org/mpd/trunk@4378 09075e82-0dd4-0310-85a5-a0d7c8717e4f
2006-07-17 02:15:34 +02:00
|
|
|
void flushWarningLog(void) {
|
2004-06-12 04:06:16 +02:00
|
|
|
char * s;
|
|
|
|
|
2005-03-12 04:10:09 +01:00
|
|
|
DEBUG("flushing warning messages\n");
|
|
|
|
|
2004-06-12 04:06:16 +02:00
|
|
|
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;
|
|
|
|
}
|