This makes debugging hook failures when running pacman less of a
hassle. Instead of a generic "command failed to execute correctly",
we now get the exact command and its arguments, as well as the exit
code of the command logged.

Signed-off-by: Daan De Meyer <daan.j.deme...@gmail.com>
---

Updated strv_join failure handling. I'm also not entirely sure what to
do with the translations. Do I update all the separate files with the
updated message identifier? I can fix some of the translations but
the Arabic ones are impossible for me to fix.

 lib/libalpm/util.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index ead03004..22ae48f6 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -568,6 +568,42 @@ static void _alpm_reset_signals(void)
        }
 }
 
+static char *strv_join(char *const *strv, const char *separator)
+{
+       char *const *i;
+       char *r, *p;
+       size_t size = 0;
+
+       if (!separator) {
+               separator = " ";
+       }
+
+       for (i = strv; *i; i++) {
+               if (i != strv) {
+                       size += strlen(separator);
+               }
+
+               size += strlen(*i);
+       }
+
+       r = malloc(size + 1);
+       if (r == NULL) {
+               return NULL;
+       }
+
+       p = r;
+
+       for (i = strv; *i; i++) {
+               if (i != strv) {
+                       p = stpcpy(p, separator);
+               }
+
+               p = stpcpy(p, *i);
+       }
+
+       return r;
+}
+
 /** Execute a command with arguments in a chroot.
  * @param handle the context handle
  * @param cmd command to execute
@@ -745,7 +781,14 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char 
*cmd, char *const argv[],
                if(WIFEXITED(status)) {
                        _alpm_log(handle, ALPM_LOG_DEBUG, "call to waitpid 
succeeded\n");
                        if(WEXITSTATUS(status) != 0) {
-                               _alpm_log(handle, ALPM_LOG_ERROR, _("command 
failed to execute correctly\n"));
+                               char *argv_str = strv_join(argv, NULL);
+                               if (argv_str) {
+                                       _alpm_log(handle, ALPM_LOG_ERROR,
+                                                       _("command \"%s\" 
failed to execute correctly: %i\n"),
+                                                       argv_str, 
WEXITSTATUS(status));
+                                       free(argv_str);
+                               }
+
                                retval = 1;
                        }
                } else if(WIFSIGNALED(status) != 0) {
-- 
2.26.2

Reply via email to