glib-2.70.2-skip_warnings-1.patch 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Submitted By: Bruce Dubbs <bdubbs@linuxfromscratch.org>
  2. Rediffed By: Douglas R. Reno <renodr at linuxfromscratch dot org>
  3. Date: 2017-10-15
  4. Rediffed Date: 2021-04-01
  5. Initial Package Version: 2.54.0
  6. Upstream Status: Not submitted
  7. Origin: Self
  8. Description: Adds a capabiility to skip printing warning messages using
  9. an environment variable: GLIB_LOG_LEVEL. The value
  10. of the variable is a digit that correponds to:
  11. 1 Alert
  12. 2 Critical
  13. 3 Error
  14. 4 Warning
  15. 5 Notice
  16. For instance GLIB_LOG_LEVEL=4 will skip output of Warning and
  17. Notice messages (and Info/Debug messages if they are turned on).
  18. Rediffed for 2.68.0 to reduce the fuzz warnings.
  19. diff -Naurp glib-2.68.0.orig/glib/gmessages.c glib-2.68.0/glib/gmessages.c
  20. --- glib-2.68.0.orig/glib/gmessages.c 2021-03-18 08:28:31.909625000 -0500
  21. +++ glib-2.68.0/glib/gmessages.c 2021-04-01 20:32:23.517596280 -0500
  22. @@ -528,6 +528,34 @@ static GDestroyNotify log_writer_user_da
  23. /* --- functions --- */
  24. +/* skip_message
  25. + *
  26. + * This internal function queries an optional environment variable,
  27. + * GLIB_LOG_LEVEL and converts it to a value consistent
  28. + * with the type GLogLevelFlags. If the value is equal to
  29. + * or greater than the integer equivalent of the log_level,
  30. + * then the function returns a boolean that indicates that
  31. + * logging the output should be skipped.
  32. + */
  33. +
  34. +static gboolean skip_message( GLogLevelFlags log_level);
  35. +
  36. +static gboolean skip_message( GLogLevelFlags log_level)
  37. +{
  38. + char* user_log_level;
  39. + int user_log_int;
  40. + gboolean skip = FALSE;
  41. +
  42. + user_log_level = getenv( "GLIB_LOG_LEVEL" );
  43. +
  44. + user_log_int = ( user_log_level != NULL ) ? atoi( user_log_level ) : 0;
  45. + user_log_int = ( user_log_level != 0 ) ? 1 << user_log_int : 0;
  46. +
  47. + if ( user_log_int >= log_level ) skip = TRUE;
  48. +
  49. + return skip;
  50. +}
  51. +
  52. static void _g_log_abort (gboolean breakpoint);
  53. static void
  54. @@ -2591,6 +2619,9 @@ g_log_writer_standard_streams (GLogLevel
  55. g_return_val_if_fail (fields != NULL, G_LOG_WRITER_UNHANDLED);
  56. g_return_val_if_fail (n_fields > 0, G_LOG_WRITER_UNHANDLED);
  57. + /* If the user does not want this message level, just return */
  58. + if ( skip_message( log_level) ) return G_LOG_WRITER_HANDLED;
  59. +
  60. stream = log_level_to_file (log_level);
  61. if (!stream || fileno (stream) < 0)
  62. return G_LOG_WRITER_UNHANDLED;
  63. @@ -2818,6 +2849,9 @@ _g_log_writer_fallback (GLogLevelFlags
  64. FILE *stream;
  65. gsize i;
  66. + /* If the user does not want this message level, just return */
  67. + if ( skip_message( log_level) ) return G_LOG_WRITER_HANDLED;
  68. +
  69. /* we cannot call _any_ GLib functions in this fallback handler,
  70. * which is why we skip UTF-8 conversion, etc.
  71. * since we either recursed or ran out of memory, we're in a pretty