I can't tell, but it looks like this could have some performance impact.

Can you rework this patch on top of Fabio's logsys rework patch and
possibly introduce a new internal but externally exported api that does
the job for this special case without sprintfing in all cases or parsing
the va args list in all cases (except when a va list is specified)?

Regards
-steve

On Tue, 2009-03-31 at 17:04 +0200, Jan Friesse wrote:
> Attached patch solves problem with ipc_log_printf, which calls
> _logsys_log_printf. Arguments for this function was va_list, so logged
> information was va_list address, instead of "what user wants".
> 
> Solution is based on adding new function _logsys_log_vprintf, which
> takes va_list as argument. Old _logsys_log_printf is implemented by new
> _logsys_log_vprintf (no code duplication).
> 
> Another problem which patch fixing is, that old logsys_log_printf used
> vsprintf to static allocated buffer. This could cause buffer owerflow,
> so vsnprintf is used now.
> 
> 
> plain text document attachment (logsys_log_vprintf.patch)
> Index: include/corosync/engine/logsys.h
> ===================================================================
> --- include/corosync/engine/logsys.h  (revision 1974)
> +++ include/corosync/engine/logsys.h  (working copy)
> @@ -155,6 +155,15 @@
>       const char *format,
>       ...) __attribute__((format(printf, 6, 7)));
>  
> +extern void _logsys_log_vprintf (
> +     int subsys,
> +     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_rec (
>       int subsys,
>       const char *function_name,
> Index: exec/logsys.c
> ===================================================================
> --- exec/logsys.c     (revision 1974)
> +++ exec/logsys.c     (working copy)
> @@ -795,18 +795,17 @@
>       records_written++;
>  }
>  
> -void _logsys_log_printf (
> +void _logsys_log_vprintf (
>          int subsys,
>          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;
> -     va_list ap;
>  
>       if (logsys_mode & LOG_MODE_NOSUBSYS) {
>               subsys = 0;
> @@ -814,9 +813,8 @@
>       if (level > logsys_loggers[subsys].priority) {
>               return;
>       }
> -     va_start (ap, format);
> -     len = vsprintf (logsys_print_buffer, format, ap);
> -     va_end (ap);
> +     len = vsnprintf (logsys_print_buffer, COMBINE_BUFFER_SIZE, format, ap);
> +
>       if (logsys_print_buffer[len - 1] == '\n') {
>               logsys_print_buffer[len - 1] = '\0';
>               len -= 1;
> @@ -849,6 +847,22 @@
>       }
>  }
>  
> +void _logsys_log_printf (
> +     int subsys,
> +     const char *function_name,
> +     const char *file_name,
> +     int file_line,
> +     unsigned int level,
> +     const char *format,
> +     ...)
> +{
> +     va_list ap;
> +
> +     va_start (ap, format);
> +     _logsys_log_vprintf(subsys, function_name, file_name, file_line, level, 
> format, ap);
> +     va_end (ap);
> +}
> +
>  /*
>   * External Configuration and Initialization API
>   */
> Index: exec/main.c
> ===================================================================
> --- exec/main.c       (revision 1974)
> +++ exec/main.c       (working copy)
> @@ -601,7 +601,7 @@
>  
>          va_start (ap, format);
>       
> -       _logsys_log_printf (ipc_subsys_id, __FUNCTION__,      
> +     _logsys_log_vprintf (ipc_subsys_id, __FUNCTION__,       
>                  __FILE__, __LINE__, LOG_LEVEL_ERROR, format, ap);
>  
>          va_end (ap);
> _______________________________________________
> Openais mailing list
> [email protected]
> https://lists.linux-foundation.org/mailman/listinfo/openais

_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to