From 9be280f5626eb081a540c3b20dd62814d83906b3 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Mon, 9 Aug 2021 12:28:17 +0100 Subject: [PATCH] pv-adverb: Expand error message if we cannot regenerate ld.so cache We can make it easier to diagnose ldconfig failures by including the stderr from the failing ldconfig command in our error message. Signed-off-by: Simon McVittie <smcv@collabora.com> --- pressure-vessel/adverb.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pressure-vessel/adverb.c b/pressure-vessel/adverb.c index d255b587a..ac73b67d9 100644 --- a/pressure-vessel/adverb.c +++ b/pressure-vessel/adverb.c @@ -638,6 +638,7 @@ regenerate_ld_so_cache (const GPtrArray *ld_so_cache_paths, const char *dir, GError **error) { + g_autoptr(GError) local_error = NULL; g_autoptr(GPtrArray) argv = g_ptr_array_new (); g_autoptr(GString) conf = g_string_new (""); g_autofree gchar *child_stdout = NULL; @@ -723,15 +724,34 @@ regenerate_ld_so_cache (const GPtrArray *ld_so_cache_paths, error)) return glnx_prefix_error (error, "Cannot run /sbin/ldconfig"); + if (!g_spawn_check_exit_status (wait_status, &local_error)) + { + if (child_stderr != NULL && child_stderr[0] != '\0') + { + g_set_error (error, local_error->domain, local_error->code, + ("Unable to generate %s: %s.\n" + "Diagnostic output:\n%s"), + new_path, + local_error->message, + child_stderr); + } + else + { + g_set_error (error, local_error->domain, local_error->code, + "Unable to generate %s: %s", + new_path, + local_error->message); + } + + return FALSE; + } + if (child_stdout != NULL && child_stdout[0] != '\0') g_debug ("Output:\n%s", child_stdout); if (child_stderr != NULL && child_stderr[0] != '\0') g_debug ("Diagnostic output:\n%s", child_stderr); - if (!g_spawn_check_exit_status (wait_status, error)) - return glnx_prefix_error (error, "Unable to generate %s", new_path); - /* Atomically replace ld.so.cache with new-ld.so.cache. */ if (!glnx_renameat (AT_FDCWD, new_path, AT_FDCWD, replace_path, error)) return glnx_prefix_error (error, "Cannot move %s to %s", -- GitLab