From c7d89aa5d4122731bd029b094164caa6e9974fc1 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Thu, 11 Apr 2024 14:58:53 +0200 Subject: [PATCH 1/2] Add error messages for url helper calls Rpm allows URLs as cli parameters. The files are then automatically downloaded with %_urlhelper which defaults to curl(1). For far failures have been ignored right away and error messages are generated later when the file was not found on disk. Issue a meaningful error message at least when the help program is missing. This allows not to ship curl with rpm while still giving the user a chance to find out what is going on. Related: rhbz#2216754 --- rpmio/url.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rpmio/url.c b/rpmio/url.c index ac29933c96..a980d757be 100644 --- a/rpmio/url.c +++ b/rpmio/url.c @@ -99,6 +99,7 @@ int urlGetFile(const char * url, const char * dest) char *urlhelper = NULL; int status; pid_t pid; + int res = -1; urlhelper = rpmExpand("%{?_urlhelper}", NULL); @@ -118,9 +119,15 @@ int urlGetFile(const char * url, const char * dest) execvp(argv[0], argv); exit(127); /* exit with 127 for compatibility with bash(1) */ } + + if ((waitpid(pid, &status, 0) != -1) && WIFEXITED(status)) { + if (WEXITSTATUS(status) == 127) + rpmlog(RPMLOG_ERR, _("Could not find url helper: \"%s\"\n"), urlhelper); + else if (WEXITSTATUS(status) == 0) + res = 0; + } + free(cmd); free(urlhelper); - - return ((waitpid(pid, &status, 0) != -1) && - WIFEXITED(status) && (WEXITSTATUS(status) == 0)) ? 0 : -1; + return res; } From ffcd2079e30e42857cd728d6e9653c9d2a6e3879 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Tue, 16 Apr 2024 11:32:17 +0200 Subject: [PATCH 2/2] Add error messages for url helper calls Give error message if the urlhelper failed (exited with a non zero return code). This is not quite ideal as the error message from the helper (typically curl) itself is still not shown but give the user at leat a hint what is going on. --- rpmio/url.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpmio/url.c b/rpmio/url.c index a980d757be..6f56fb5926 100644 --- a/rpmio/url.c +++ b/rpmio/url.c @@ -125,6 +125,8 @@ int urlGetFile(const char * url, const char * dest) rpmlog(RPMLOG_ERR, _("Could not find url helper: \"%s\"\n"), urlhelper); else if (WEXITSTATUS(status) == 0) res = 0; + else + rpmlog(RPMLOG_ERR, _("Executing url helper \"%s\" failed with status %i\n"), cmd, WEXITSTATUS(status)); } free(cmd);