From 16867251179fd3742e576d4c3f6dd956d6058f75 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Tue, 10 Nov 2020 11:03:18 +0000 Subject: [PATCH] block annoying INFO messages on some older glibs Some old glibs can display INFO messages by default. Block these ourselves. See https://github.com/libvips/libvips/issues/1876 --- ChangeLog | 1 + libvips/iofuncs/init.c | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2a3a01b..5d17d315 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ - fix out of bounds read in tiffload - fix tiffsave region shrink mode [imgifty] - add missing flushes on write to target [harukizaemon] +- hide info messages you could get with some older glibs [kleisauke] 6/9/20 started 8.10.2 - update magicksave/load profile handling [kelilevi] diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index aa1b5901..ecdc2f36 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -284,6 +284,24 @@ empty_log_handler( const gchar *log_domain, GLogLevelFlags log_level, { } +#if !GLIB_CHECK_VERSION( 2, 31, 0 ) +static void +default_log_handler( const gchar *log_domain, GLogLevelFlags log_level, + const gchar *message, gpointer user_data ) +{ + if( log_level & (G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_INFO) ) { + const char *domains = g_getenv( "G_MESSAGES_DEBUG" ); + + if( !domains || + (!g_str_equal( domains, "all" ) && + !g_strrstr( domains, log_domain )) ) + return; + } + + g_log_default_handler( log_domain, log_level, message, user_data ); +} +#endif /*!GLIB_CHECK_VERSION( 2, 31, 0 )*/ + /* Attempt to set a minimum stacksize. This can be important on systems with a * very low default, like musl. */ @@ -318,17 +336,12 @@ set_stacksize( guint64 size ) static void vips_verbose( void ) { - /* Older glibs were showing G_LOG_LEVEL_{INFO,DEBUG} messages - * by default - */ -#if GLIB_CHECK_VERSION ( 2, 31, 0 ) const char *old; old = g_getenv( "G_MESSAGES_DEBUG" ); - if( !old ) { + if( !old ) g_setenv( "G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE ); - } else if( !g_str_equal( old, "all" ) && !g_strrstr( old, G_LOG_DOMAIN ) ) { char *new; @@ -338,7 +351,6 @@ vips_verbose( void ) g_free( new ); } -#endif /*GLIB_CHECK_VERSION( 2, 31, 0 )*/ } /** @@ -590,6 +602,18 @@ vips_init( const char *argv0 ) g_log_set_handler( G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, empty_log_handler, NULL ); +#if !GLIB_CHECK_VERSION( 2, 31, 0 ) + /* Older glibs can sometimes show G_LOG_LEVEL_{INFO,DEBUG} messages. + * Block them ourselves. We test the env var inside the handler since + * vips_verbose() can be toggled at runtime. + * + * Again, we should not call g_log_set_handler(), but this is the only + * convenient way to fix this behaviour. + */ + g_log_set_handler( G_LOG_DOMAIN, G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, + default_log_handler, NULL ); +#endif /*!GLIB_CHECK_VERSION( 2, 31, 0 )*/ + /* Set a minimum stacksize, if we can. */ if( (vips_min_stack_size = g_getenv( "VIPS_MIN_STACK_SIZE" )) )