diff options
author | Volker Lendecke <vl@samba.org> | 2014-07-29 16:04:25 +0000 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2014-07-31 18:49:47 +0200 |
commit | 610bb4a1085681bd850d17735d499798fb3c627f (patch) | |
tree | f3055fb00c45e3fe9911123c1886e3542df659c4 /lib | |
parent | 138a65c12a8dd4a59b503180fa5aaff7386c1e4b (diff) | |
download | samba-610bb4a1085681bd850d17735d499798fb3c627f.tar.gz samba-610bb4a1085681bd850d17735d499798fb3c627f.tar.xz samba-610bb4a1085681bd850d17735d499798fb3c627f.zip |
debug: Simplify Debug1() -- no va_args
All callers just have "%s" as format string now, so we don't need to
vasprintf anymore.
This could speed up DEBUG a bit, we don't do a separate copy and the
printf logic
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/debug.c | 52 |
1 files changed, 18 insertions, 34 deletions
diff --git a/lib/util/debug.c b/lib/util/debug.c index 6f2c3099d4..faa5492c16 100644 --- a/lib/util/debug.c +++ b/lib/util/debug.c @@ -761,36 +761,30 @@ void check_log_size( void ) This is called by dbghdr() and format_debug_text(). ************************************************************************/ -static int Debug1( const char *format_str, ... ) +static int Debug1(const char *msg) { - va_list ap; int old_errno = errno; debug_count++; if (state.logtype == DEBUG_CALLBACK) { - char *msg; - int ret; - va_start( ap, format_str ); - ret = vasprintf( &msg, format_str, ap ); - if (ret != -1) { - if (msg[ret - 1] == '\n') { - msg[ret - 1] = '\0'; - } - state.callback(state.callback_private, current_msg_level, msg); - free(msg); + size_t msg_len = strlen(msg); + char msg_copy[msg_len]; + + if ((msg_len > 0) && (msg[msg_len-1] == '\n')) { + memcpy(msg_copy, msg, msg_len-1); + msg_copy[msg_len-1] = '\0'; + msg = msg_copy; } - va_end( ap ); + state.callback(state.callback_private, current_msg_level, msg); goto done; - } if ( state.logtype != DEBUG_FILE ) { - va_start( ap, format_str ); - if (state.fd > 0) - (void)vdprintf( state.fd, format_str, ap ); - va_end( ap ); + if (state.fd > 0) { + write(state.fd, msg, strlen(msg)); + } goto done; } @@ -822,8 +816,6 @@ static int Debug1( const char *format_str, ... ) LOG_INFO, /* 3 */ }; int priority; - char *msgbuf = NULL; - int ret; if( current_msg_level >= ARRAY_SIZE(priority_map) || current_msg_level < 0) priority = LOG_DEBUG; @@ -836,14 +828,7 @@ static int Debug1( const char *format_str, ... ) */ priority |= SYSLOG_FACILITY; - va_start(ap, format_str); - ret = vasprintf(&msgbuf, format_str, ap); - va_end(ap); - - if (ret != -1) { - syslog(priority, "%s", msgbuf); - } - SAFE_FREE(msgbuf); + syslog(priority, "%s", msg); } #endif @@ -853,10 +838,9 @@ static int Debug1( const char *format_str, ... ) if( !state.settings.syslog_only) #endif { - va_start( ap, format_str ); - if (state.fd > 0) - (void)vdprintf( state.fd, format_str, ap ); - va_end( ap ); + if (state.fd > 0) { + write(state.fd, msg, strlen(msg)); + } } done: @@ -875,7 +859,7 @@ static int Debug1( const char *format_str, ... ) static void bufr_print( void ) { format_bufr[format_pos] = '\0'; - (void)Debug1( "%s", format_bufr ); + (void)Debug1(format_bufr); format_pos = 0; } @@ -1045,7 +1029,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func) "%s(%s)\n", location, func); } - (void)Debug1("%s", header_str); + (void)Debug1(header_str); errno = old_errno; return( true ); |