[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2 02/11] tools/libs/toollog: Use the default logger



On Thu, Nov 08, 2018 at 05:07:56PM +0000, Ian Jackson wrote:
> Previously xtl_log, xtl_logv and xtl_progress would all crash if
> passed logger=NULL.  Have the use the default logger instead.
> This is more convenient.
> 
> Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
> CC: Wei Liu <wei.liu2@xxxxxxxxxx>

Reviewed-by: Marek Marczykowski-Górecki <marmarek@xxxxxxxxxxxxxxxxxxxxxx>

> ---
> v2: New in this version of the series
> ---
>  tools/libs/toollog/include/xentoollog.h | 9 +++++----
>  tools/libs/toollog/xtl_core.c           | 7 +++++++
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/libs/toollog/include/xentoollog.h 
> b/tools/libs/toollog/include/xentoollog.h
> index 942eb76169..9c7725f1cd 100644
> --- a/tools/libs/toollog/include/xentoollog.h
> +++ b/tools/libs/toollog/include/xentoollog.h
> @@ -89,25 +89,26 @@ void xtl_logger_destroy(struct xentoollog_logger *logger 
> /* 0 is ok */);
>  xentoollog_logger_stdiostream *xtl_defaultlogger_stdiostream(void);
>    /* Returns pointer to a static global logger which writes to stderr.
>     * Reconfiguring it is permitted but destroying it is forbidden.
> -   * This function cannot fail. */
> +   * This function cannot fail.
> +   * This default logger is usedd by xtl_log et al when logger==NULL. */
>  
>  /*---------- facilities for generating log messages ----------*/
>  
> -void xtl_logv(struct xentoollog_logger *logger,
> +void xtl_logv(struct xentoollog_logger *logger /* NULL ok */,
>                xentoollog_level level,
>                int errnoval /* or -1 */,
>                const char *context /* eg "xc", "xenstore", "xl", may be 0 */,
>                const char *format /* does not contain \n */,
>                va_list) __attribute__((format(printf,5,0)));
>  
> -void xtl_log(struct xentoollog_logger *logger,
> +void xtl_log(struct xentoollog_logger *logger /* NULL ok */,
>               xentoollog_level level,
>               int errnoval /* or -1 */,
>               const char *context /* eg "xc", "xenstore", "xl" */,
>               const char *format /* does not contain \n */,
>               ...) __attribute__((format(printf,5,6)));
>  
> -void xtl_progress(struct xentoollog_logger *logger,
> +void xtl_progress(struct xentoollog_logger *logger /* NULL ok */,
>                    const char *context /* see above, may be 0 */,
>                    const char *doing_what,
>                    unsigned long done, unsigned long total);
> diff --git a/tools/libs/toollog/xtl_core.c b/tools/libs/toollog/xtl_core.c
> index 099d2f3095..c5da3f4f5d 100644
> --- a/tools/libs/toollog/xtl_core.c
> +++ b/tools/libs/toollog/xtl_core.c
> @@ -38,6 +38,11 @@ const char *xtl_level_to_string(xentoollog_level level) {
>      return level_strings[level];
>  }
>  
> +static void defaultlogger(xentoollog_logger **logger) {
> +    if (*logger) return;
> +    *logger = (xentoollog_logger*)xtl_defaultlogger_stdiostream();
> +}
> +
>  void xtl_logv(struct xentoollog_logger *logger,
>                xentoollog_level level,
>                int errnoval /* or -1 */,
> @@ -46,6 +51,7 @@ void xtl_logv(struct xentoollog_logger *logger,
>                va_list al) {
>      int errno_save = errno;
>      assert(level > XTL_NONE && level < XTL_NUM_LEVELS);
> +    defaultlogger(&logger);
>      logger->vmessage(logger,level,errnoval,context,format,al);
>      errno = errno_save;
>  }
> @@ -67,6 +73,7 @@ void xtl_progress(struct xentoollog_logger *logger,
>                    unsigned long done, unsigned long total) {
>      int percent = 0;
>  
> +    defaultlogger(&logger);
>      if (!logger->progress) return;
>  
>      if ( total )

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?

Attachment: signature.asc
Description: PGP signature

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.