From 85c3fe47292f4e4e47a1f58f1347cb1f6d03b37e Mon Sep 17 00:00:00 2001 From: Manuel Bentele Date: Tue, 20 Oct 2020 15:31:52 +0200 Subject: [BUILD] add option to build the dnbd3-server with afl-fuzz support The afl-fuzz support for the dnbd3-server requires an AFL C compiler like afl-gcc and can be enabled with the CMake option DNBD3_SERVER_AFL. --- src/shared/log.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/shared') diff --git a/src/shared/log.c b/src/shared/log.c index f2cab85..374bed1 100644 --- a/src/shared/log.c +++ b/src/shared/log.c @@ -36,6 +36,7 @@ static _Atomic logmask_t maskCon = 15; static char *logFile = NULL; static int logFd = -1; +static FILE *logOutStream; static bool consoleTimestamps = false; @@ -43,6 +44,10 @@ static bool consoleTimestamps = false; static int writeLevel(char *buffer, logmask_t level); +void log_init(void) { + logOutStream = stdout; +} + bool log_hasMask(const logmask_t mask) { return ( ( maskFile | maskCon ) & mask ) == mask; @@ -63,6 +68,15 @@ void log_setConsoleTimestamps(bool on) consoleTimestamps = on; } +int log_setConsoleOutputStream(FILE *outputStream) +{ + if ( outputStream != stdout && outputStream != stderr ) + return -EINVAL; + + logOutStream = outputStream; + return 0; +} + bool log_openLogFile(const char *path) { pthread_mutex_lock( &logLock ); @@ -93,10 +107,10 @@ void logadd(const logmask_t mask, const char *fmt, ...) struct tm timeinfo; char buffer[LINE_LEN]; bool toFile = maskFile & mask; - bool toStdout = maskCon & mask; + bool toOutStream = maskCon & mask; size_t offset; - if ( toFile || ( toStdout && consoleTimestamps ) ) { + if ( toFile || ( toOutStream && consoleTimestamps ) ) { time( &rawtime ); localtime_r( &rawtime, &timeinfo ); offset = strftime( buffer, LINE_LEN, "[%d.%m. %H:%M:%S] ", &timeinfo ); @@ -134,15 +148,11 @@ void logadd(const logmask_t mask, const char *fmt, ...) } pthread_mutex_unlock( &logLock ); } - if ( toStdout ) { - if ( consoleTimestamps ) stdoutLine = buffer; -#ifdef DNBD3_SERVER_AFL - fputs( stdoutLine, stderr ); - fflush( stderr ); -#else - fputs( stdoutLine, stdout ); - fflush( stdout ); -#endif + if ( toOutStream ) { + if ( consoleTimestamps ) + stdoutLine = buffer; + fputs( stdoutLine, logOutStream ); + fflush( logOutStream ); } } -- cgit v1.2.3-55-g7522