log: improve handling of use-before-init
Rather than segfaulting by attempting to traverse an initially null log handler pointer, explicitly print a message and abort. Signed-off-by: Matt Hoosier <matt.hoosier@gmail.com> Reviewed-by: Ian Ray <ian.ray@ge.com> [Pekka: coding style fix] Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
parent
577b346412
commit
74742e0525
|
@ -36,8 +36,28 @@
|
|||
|
||||
#include "compositor.h"
|
||||
|
||||
static log_func_t log_handler = 0;
|
||||
static log_func_t log_continue_handler = 0;
|
||||
static int
|
||||
default_log_handler(const char *fmt, va_list ap);
|
||||
|
||||
static log_func_t log_handler = default_log_handler;
|
||||
static log_func_t log_continue_handler = default_log_handler;
|
||||
|
||||
/** Sentinel log message handler
|
||||
*
|
||||
* This function is used as the default handler for log messages. It
|
||||
* exists only to issue a noisy reminder to the user that a real handler
|
||||
* must be installed prior to issuing logging calls. The process is
|
||||
* immediately aborted after the reminder is printed.
|
||||
*
|
||||
* \param fmt The format string. Ignored.
|
||||
* \param va The variadic argument list. Ignored.
|
||||
*/
|
||||
static int
|
||||
default_log_handler(const char *fmt, va_list ap)
|
||||
{
|
||||
fprintf(stderr, "weston_log_set_handler() must be called before using of weston_log().\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
/** Install the log handler
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue