mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
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>
This commit is contained in:
committed by
Michael Adam
parent
138a65c12a
commit
610bb4a108
@ -761,36 +761,30 @@ void check_log_size( void )
|
|||||||
This is called by dbghdr() and format_debug_text().
|
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;
|
int old_errno = errno;
|
||||||
|
|
||||||
debug_count++;
|
debug_count++;
|
||||||
|
|
||||||
if (state.logtype == DEBUG_CALLBACK) {
|
if (state.logtype == DEBUG_CALLBACK) {
|
||||||
char *msg;
|
size_t msg_len = strlen(msg);
|
||||||
int ret;
|
char msg_copy[msg_len];
|
||||||
va_start( ap, format_str );
|
|
||||||
ret = vasprintf( &msg, format_str, ap );
|
if ((msg_len > 0) && (msg[msg_len-1] == '\n')) {
|
||||||
if (ret != -1) {
|
memcpy(msg_copy, msg, msg_len-1);
|
||||||
if (msg[ret - 1] == '\n') {
|
msg_copy[msg_len-1] = '\0';
|
||||||
msg[ret - 1] = '\0';
|
msg = msg_copy;
|
||||||
}
|
|
||||||
state.callback(state.callback_private, current_msg_level, msg);
|
|
||||||
free(msg);
|
|
||||||
}
|
}
|
||||||
va_end( ap );
|
|
||||||
|
|
||||||
|
state.callback(state.callback_private, current_msg_level, msg);
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( state.logtype != DEBUG_FILE ) {
|
if ( state.logtype != DEBUG_FILE ) {
|
||||||
va_start( ap, format_str );
|
if (state.fd > 0) {
|
||||||
if (state.fd > 0)
|
write(state.fd, msg, strlen(msg));
|
||||||
(void)vdprintf( state.fd, format_str, ap );
|
}
|
||||||
va_end( ap );
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,8 +816,6 @@ static int Debug1( const char *format_str, ... )
|
|||||||
LOG_INFO, /* 3 */
|
LOG_INFO, /* 3 */
|
||||||
};
|
};
|
||||||
int priority;
|
int priority;
|
||||||
char *msgbuf = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
if( current_msg_level >= ARRAY_SIZE(priority_map) || current_msg_level < 0)
|
if( current_msg_level >= ARRAY_SIZE(priority_map) || current_msg_level < 0)
|
||||||
priority = LOG_DEBUG;
|
priority = LOG_DEBUG;
|
||||||
@ -836,14 +828,7 @@ static int Debug1( const char *format_str, ... )
|
|||||||
*/
|
*/
|
||||||
priority |= SYSLOG_FACILITY;
|
priority |= SYSLOG_FACILITY;
|
||||||
|
|
||||||
va_start(ap, format_str);
|
syslog(priority, "%s", msg);
|
||||||
ret = vasprintf(&msgbuf, format_str, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (ret != -1) {
|
|
||||||
syslog(priority, "%s", msgbuf);
|
|
||||||
}
|
|
||||||
SAFE_FREE(msgbuf);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -853,10 +838,9 @@ static int Debug1( const char *format_str, ... )
|
|||||||
if( !state.settings.syslog_only)
|
if( !state.settings.syslog_only)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
va_start( ap, format_str );
|
if (state.fd > 0) {
|
||||||
if (state.fd > 0)
|
write(state.fd, msg, strlen(msg));
|
||||||
(void)vdprintf( state.fd, format_str, ap );
|
}
|
||||||
va_end( ap );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
@ -875,7 +859,7 @@ static int Debug1( const char *format_str, ... )
|
|||||||
static void bufr_print( void )
|
static void bufr_print( void )
|
||||||
{
|
{
|
||||||
format_bufr[format_pos] = '\0';
|
format_bufr[format_pos] = '\0';
|
||||||
(void)Debug1( "%s", format_bufr );
|
(void)Debug1(format_bufr);
|
||||||
format_pos = 0;
|
format_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1045,7 +1029,7 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
|
|||||||
"%s(%s)\n", location, func);
|
"%s(%s)\n", location, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)Debug1("%s", header_str);
|
(void)Debug1(header_str);
|
||||||
|
|
||||||
errno = old_errno;
|
errno = old_errno;
|
||||||
return( true );
|
return( true );
|
||||||
|
Reference in New Issue
Block a user