diff options
author | Gaël Bonithon <gael@xfce.org> | 2021-12-27 12:53:45 +0100 |
---|---|---|
committer | Gaël Bonithon <gael@xfce.org> | 2021-12-27 13:11:20 +0100 |
commit | 3ea0a2d0f93f71e69c7b5db39e7c3a72dfea918a (patch) | |
tree | 0109a3ffaee681a20f9d2964a112a95508109714 | |
parent | 32fb595aff6fbc6e37656d510bbccb46e9c1af9e (diff) | |
download | tumbler-3ea0a2d0f93f71e69c7b5db39e7c3a72dfea918a.tar.gz |
Reserve some third-party API messages to debug logging
FFmpegthumbnailer is known to be really verbose, and we don't have a
priori control on the messages that can be displayed by external
thumbnailers (it can be in particular FFmpegthumbnailer).
Fixes #10, related to #29.
-rw-r--r-- | docs/reference/tumbler/tumbler-sections.txt | 1 | ||||
-rw-r--r-- | plugins/desktop-thumbnailer/desktop-thumbnailer.c | 14 | ||||
-rw-r--r-- | plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c | 6 | ||||
-rw-r--r-- | tumbler/tumbler-util.c | 37 | ||||
-rw-r--r-- | tumbler/tumbler-util.h | 2 |
5 files changed, 56 insertions, 4 deletions
diff --git a/docs/reference/tumbler/tumbler-sections.txt b/docs/reference/tumbler/tumbler-sections.txt index 8a39e48..1d41b50 100644 --- a/docs/reference/tumbler/tumbler-sections.txt +++ b/docs/reference/tumbler/tumbler-sections.txt @@ -259,6 +259,7 @@ tumbler_thumbnailer_provider_get_type <FILE>tumbler-util</FILE> tumbler_util_is_debug_logging_enabled tumbler_util_dump_strv +tumbler_util_toggle_stderr tumbler_util_get_supported_uri_schemes tumbler_util_get_settings tumbler_util_guess_is_sparse diff --git a/plugins/desktop-thumbnailer/desktop-thumbnailer.c b/plugins/desktop-thumbnailer/desktop-thumbnailer.c index 96e357e..05c4433 100644 --- a/plugins/desktop-thumbnailer/desktop-thumbnailer.c +++ b/plugins/desktop-thumbnailer/desktop-thumbnailer.c @@ -263,7 +263,7 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer, { GFileIOStream *stream; GFile *tmpfile; - gchar *exec; + gchar *exec, *std_err; gchar **cmd_argv; const gchar *tmpfilepath; gboolean res; @@ -271,6 +271,7 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer, gint size; gchar *working_directory = NULL; GdkPixbuf *source, *pixbuf = NULL; + gboolean verbose; g_object_get (G_OBJECT (thumbnailer), "exec", &exec, NULL); @@ -295,13 +296,20 @@ desktop_thumbnailer_load_thumbnail (DesktopThumbnailer *thumbnailer, { working_directory = g_path_get_dirname (path); + verbose = tumbler_util_is_debug_logging_enabled (G_LOG_DOMAIN); res = g_spawn_sync (working_directory, cmd_argv, NULL, - G_SPAWN_SEARCH_PATH, - NULL, NULL, + verbose ? G_SPAWN_SEARCH_PATH + : G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, + NULL, verbose ? &std_err : NULL, NULL, error); + if (verbose) + { + g_printerr ("%s", std_err); + g_free (std_err); + } if (G_LIKELY (res)) { diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c index 3b3494e..c6bf337 100644 --- a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c +++ b/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer.c @@ -143,6 +143,7 @@ ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, gint dest_height; gchar *path; const gchar *uri; + gint res; g_return_if_fail (IS_FFMPEG_THUMBNAILER (thumbnailer)); g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); @@ -206,7 +207,10 @@ ffmpeg_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer, } /* try to generate a thumbnail */ - if (video_thumbnailer_generate_thumbnail_to_buffer (ffmpeg_thumbnailer->video, path, v_data) != 0) + tumbler_util_toggle_stderr (G_LOG_DOMAIN); + res = video_thumbnailer_generate_thumbnail_to_buffer (ffmpeg_thumbnailer->video, path, v_data); + tumbler_util_toggle_stderr (G_LOG_DOMAIN); + if (res != 0) { /* there was an error, emit error signal */ g_set_error (&error, TUMBLER_ERROR, TUMBLER_ERROR_INVALID_FORMAT, diff --git a/tumbler/tumbler-util.c b/tumbler/tumbler-util.c index 04c434d..cfc1172 100644 --- a/tumbler/tumbler-util.c +++ b/tumbler/tumbler-util.c @@ -85,6 +85,43 @@ tumbler_util_dump_strv (const gchar *log_domain, +/* + * This is intended to be used around too verbose third-party APIs we can't silence by + * another means: + * tumbler_util_toggle_stderr (G_LOG_DOMAIN); + * … = too_verbose_api (…); + * tumbler_util_toggle_stderr (G_LOG_DOMAIN); + * When debug logging is enabled, it does nothing. + */ +void +tumbler_util_toggle_stderr (const gchar *log_domain) +{ + static gint stderr_save = -2; + + /* do nothing in case of previous error or if debug logging is enabled */ + if (stderr_save == -1 || tumbler_util_is_debug_logging_enabled (log_domain)) + return; + + /* redirect stderr to /dev/null */ + if (stderr_save == -2) + { + fflush (stderr); + stderr_save = dup (STDERR_FILENO); + if (stderr_save != -1 && freopen ("/dev/null", "a", stderr) == NULL) + stderr_save = -1; + } + /* restore stderr to stderr_save */ + else + { + fflush (stderr); + stderr_save = dup2 (stderr_save, STDERR_FILENO); + if (stderr_save != -1) + stderr_save = -2; + } +} + + + gchar ** tumbler_util_get_supported_uri_schemes (void) { diff --git a/tumbler/tumbler-util.h b/tumbler/tumbler-util.h index 20a0cc3..24c7d29 100644 --- a/tumbler/tumbler-util.h +++ b/tumbler/tumbler-util.h @@ -34,6 +34,8 @@ void tumbler_util_dump_strv (const gchar *log_domain, const gchar *label, const gchar *const *strv); +void tumbler_util_toggle_stderr (const gchar *log_domain); + gchar **tumbler_util_get_supported_uri_schemes (void) G_GNUC_MALLOC; GKeyFile *tumbler_util_get_settings (void) G_GNUC_MALLOC; |