Skip to content

Commit

Permalink
Add error messages for url helper calls
Browse files Browse the repository at this point in the history
Rpm allows URLs as cli parameters. The files are then automatically
downloaded with %_urlhelper which defaults to curl(1). So 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 when the help program is failing or missing
completely. This allows not to ship curl with rpm while still giving the
user a chance to find out what is going on. This is not quite ideal as
the operation continues and creates a second error message later on, but
as good as it gets without redesigning the whole code.

Related: rhbz#2216754
Resolves: rpm-software-management#2683
  • Loading branch information
ffesti committed Jun 14, 2024
1 parent 8e1f55c commit 7d80250
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rpmio/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -118,9 +119,17 @@ 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;
else
rpmlog(RPMLOG_ERR, _("Executing url helper \"%s\" failed with status %i\n"), cmd, WEXITSTATUS(status));
}

free(cmd);
free(urlhelper);

return ((waitpid(pid, &status, 0) != -1) &&
WIFEXITED(status) && (WEXITSTATUS(status) == 0)) ? 0 : -1;
return res;
}
27 changes: 27 additions & 0 deletions tests/rpmgeneral.at
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,30 @@ runroot_other rpm2archive "${RPMTEST}"/data/SRPMS/hello-1.0-1.src.rpm | tar tzf
])

RPMTEST_CLEANUP

AT_SETUP([urlhelper missing])
AT_KEYWORDS([urlhelper])
RPMDB_INIT
RPMTEST_CHECK([
# runroot rpm --define "_urlhelper /not/there" --root /srv/test -qp https://example.com/foo-0.1-1.noarch.rpm
runroot rpm --define "_urlhelper /not/there" -qp https://www.example.com/foo-1.0-1.x86_64.rpm
],
[1],
[],
[error: Could not find url helper: "/not/there"
error: open of https://www.example.com/foo-1.0-1.x86_64.rpm failed: No such file or directory
])
RPMTEST_CLEANUP

AT_SETUP([urlhelper fails])
AT_KEYWORDS([urlhelper])
RPMDB_INIT
RPMTEST_CHECK([
runroot rpm --define "_urlhelper /bin/false" --root /srv/test -qp https://example.com/foo-0.1-1.noarch.rpm 2> >(sed 's|rpm-tmp.* https|rpm-tmp https|' >&2)
],
[1],
[],
[error: Executing url helper "/bin/false /usr/local/var/tmp/rpm-tmp https://example.com/foo-0.1-1.noarch.rpm" failed with status 1
error: open of https://example.com/foo-0.1-1.noarch.rpm failed: No such file or directory
])
RPMTEST_CLEANUP

0 comments on commit 7d80250

Please sign in to comment.