From: Kern Sibbald Date: Sat, 6 Feb 2010 17:18:04 +0000 (+0100) Subject: Move msg trace into subroutine X-Git-Tag: Release-7.0.0~2269 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f437578dfe34605e2cd0e048266d6f7176474954;p=bacula%2Fbacula Move msg trace into subroutine --- diff --git a/bacula/src/lib/message.c b/bacula/src/lib/message.c index 5791f6b51b..2f73d8064e 100644 --- a/bacula/src/lib/message.c +++ b/bacula/src/lib/message.c @@ -841,6 +841,34 @@ get_basename(const char *pathname) #endif } +/* + * print or write output to trace file + */ +static void pt_out(char *buf) +{ + /* + * Used the "trace on" command in the console to turn on + * output to the trace file. "trace off" will close the file. + */ + if (trace) { + if (!trace_fd) { + char fn[200]; + bsnprintf(fn, sizeof(fn), "%s/%s.trace", working_directory ? working_directory : "./", my_name); + trace_fd = fopen(fn, "a+b"); + } + if (trace_fd) { + fputs(buf, trace_fd); + fflush(trace_fd); + } else { + /* Some problem, turn off tracing */ + trace = false; + } + } else { /* not tracing */ + fputs(buf, stdout); + fflush(stdout); + } +} + /********************************************************************* * * This subroutine prints a debug message if the level number @@ -889,27 +917,7 @@ d_msg(const char *file, int line, int level, const char *fmt,...) bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); va_end(arg_ptr); - /* - * Used the "trace on" command in the console to turn on - * output to the trace file. "trace off" will close the file. - */ - if (trace) { - if (!trace_fd) { - char fn[200]; - bsnprintf(fn, sizeof(fn), "%s/%s.trace", working_directory ? working_directory : "./", my_name); - trace_fd = fopen(fn, "a+b"); - } - if (trace_fd) { - fputs(buf, trace_fd); - fflush(trace_fd); - } else { - /* Some problem, turn off tracing */ - trace = false; - } - } else { /* not tracing */ - fputs(buf, stdout); - fflush(stdout); - } + pt_out(buf); } } @@ -964,8 +972,8 @@ p_msg(const char *file, int line, int level, const char *fmt,...) va_start(arg_ptr, fmt); bvsnprintf(buf+len, sizeof(buf)-len, (char *)fmt, arg_ptr); va_end(arg_ptr); - fputs(buf, stdout); - fflush(stdout); + + pt_out(buf); }