[pacman-dev] [PATCH] Reset errno before opening archive

Allan McRae allan at archlinux.org
Sat Feb 11 01:26:25 EST 2012


Set errno to 0 at the start of _alpm_open_archive as it is not set when
archive_read_open_fd fails.  This can result in _alpm_pkg_load_internal
thinking errno == ENOENT and setting the wrong pm_errno. e.g.

Before:
> testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig
error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format
Cannot find the given file.

After:
> testpkg pacman-4.0.1-4-i686.pkg.tar.gz.sig
error: could not open file pacman-4.0.1-4-i686.pkg.tar.gz.sig: Unrecognized archive format
Cannot open the given file.

Signed-off-by: Allan McRae <allan at archlinux.org>
---

I have no idea if this is the correct fix...  But hopefully I have described the issue
well enough that someone who does know the correct fix can quickly fix it.

 lib/libalpm/util.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 1128589..5986124 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -227,6 +227,7 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path,
 {
 	int fd;
 	size_t bufsize = ALPM_BUFFER_SIZE;
+	errno = 0;
 
 	if((*archive = archive_read_new()) == NULL) {
 		RET_ERR(handle, ALPM_ERR_LIBARCHIVE, -1);
-- 
1.7.9



More information about the pacman-dev mailing list