From 0dc4aed4415ccf13e1cce23aedfdbae5d350f4d6 Mon Sep 17 00:00:00 2001 From: Jan Friesse Date: Thu, 23 Apr 2009 12:29:26 +0000 Subject: [PATCH] Make ipc_log_printf function working by adding _logsys_log_vprintf, which is mostly same as _logsys_log_printf but takes va_list as argument. git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2127 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/logsys.c | 54 ++++++++++++++++++++++++++++++++ exec/main.c | 7 +++-- include/corosync/engine/logsys.h | 9 ++++++ 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/exec/logsys.c b/exec/logsys.c index 9b6f727a..09fcd231 100644 --- a/exec/logsys.c +++ b/exec/logsys.c @@ -1065,6 +1065,60 @@ void _logsys_log_rec ( records_written++; } +void _logsys_log_vprintf ( + int subsysid, + const char *function_name, + const char *file_name, + int file_line, + unsigned int level, + const char *format, + va_list ap) +{ + char logsys_print_buffer[COMBINE_BUFFER_SIZE]; + unsigned int len; + + if (subsysid <= -1) { + subsysid = LOGSYS_MAX_SUBSYS_COUNT; + } + + if ((level > logsys_loggers[subsysid].syslog_priority) && + (level > logsys_loggers[subsysid].logfile_priority)) { + return; + } + + len = vsprintf (logsys_print_buffer, format, ap); + if (logsys_print_buffer[len - 1] == '\n') { + logsys_print_buffer[len - 1] = '\0'; + len -= 1; + } + + /* + * Create a log record + */ + _logsys_log_rec (subsysid, + function_name, + file_name, + file_line, + (level+1) << 28, + logsys_print_buffer, len + 1, + LOGSYS_REC_END); + + if ((logsys_loggers[LOGSYS_MAX_SUBSYS_COUNT].mode & LOGSYS_MODE_THREADED) == 0) { + /* + * Output (and block) if the log mode is not threaded otherwise + * expect the worker thread to output the log data once signaled + */ + log_printf_to_logs (logsys_loggers[subsysid].subsys, + file_name, function_name, file_line, level, + logsys_print_buffer); + } else { + /* + * Signal worker thread to display logging output + */ + wthread_signal (); + } +} + void _logsys_log_printf ( int subsysid, const char *function_name, diff --git a/exec/main.c b/exec/main.c index 51f87b40..87820e46 100644 --- a/exec/main.c +++ b/exec/main.c @@ -604,12 +604,13 @@ static void corosync_sending_allowed_release (void *sending_allowed_private_data static int ipc_subsys_id = -1; +static void ipc_log_printf (const char *format, ...) __attribute__((format(printf, 1, 2))); static void ipc_log_printf (const char *format, ...) { - va_list ap; + va_list ap; - va_start (ap, format); + va_start (ap, format); - _logsys_log_printf (ipc_subsys_id, __FUNCTION__, + _logsys_log_vprintf (ipc_subsys_id, __FUNCTION__, __FILE__, __LINE__, LOGSYS_LEVEL_ERROR, format, ap); va_end (ap); diff --git a/include/corosync/engine/logsys.h b/include/corosync/engine/logsys.h index 26061964..916c1388 100644 --- a/include/corosync/engine/logsys.h +++ b/include/corosync/engine/logsys.h @@ -114,6 +114,15 @@ extern unsigned int _logsys_subsys_create (const char *subsys); extern int _logsys_rec_init (unsigned int size); +extern void _logsys_log_vprintf ( + int subsysid, + const char *function_name, + const char *file_name, + int file_line, + unsigned int level, + const char *format, + va_list ap) __attribute__((format(printf, 6, 0))); + extern void _logsys_log_printf ( int subsysid, const char *function_name,