summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2015-01-22 06:29:53 +0100
committerAndrew Gregory <andrew.gregory.8@gmail.com>2017-05-11 06:45:30 +0200
commit2e63d6aa7fcdfd89f02758f02f5799a291405b40 (patch)
tree03a2661f903afdbc6539b6530bf90aece2b4e55a
parent4143760a944470d50975ee27da9e3380223e88b9 (diff)
downloadpacman-2e63d6aa7fcdfd89f02758f02f5799a291405b40.tar.gz
pacman-2e63d6aa7fcdfd89f02758f02f5799a291405b40.tar.xz
make pm_errno thread-local
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
-rw-r--r--lib/libalpm/add.c8
-rw-r--r--lib/libalpm/alpm.c2
-rw-r--r--lib/libalpm/be_local.c8
-rw-r--r--lib/libalpm/be_package.c38
-rw-r--r--lib/libalpm/be_sync.c8
-rw-r--r--lib/libalpm/conflict.c4
-rw-r--r--lib/libalpm/db.c18
-rw-r--r--lib/libalpm/deps.c6
-rw-r--r--lib/libalpm/dload.c10
-rw-r--r--lib/libalpm/error.c5
-rw-r--r--lib/libalpm/handle.c20
-rw-r--r--lib/libalpm/handle.h14
-rw-r--r--lib/libalpm/log.c6
-rw-r--r--lib/libalpm/package.c82
-rw-r--r--lib/libalpm/remove.c2
-rw-r--r--lib/libalpm/signing.c22
-rw-r--r--lib/libalpm/sync.c28
-rw-r--r--lib/libalpm/util.h6
18 files changed, 161 insertions, 126 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 0beed01c..fa33c7b6 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -478,7 +478,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(oldpkg) {
/* set up fake remove transaction */
if(_alpm_remove_single_package(handle, oldpkg, newpkg, 0, 0) == -1) {
- handle->pm_errno = ALPM_ERR_TRANS_ABORT;
+ _alpm_set_errno(handle, ALPM_ERR_TRANS_ABORT);
ret = -1;
goto cleanup;
}
@@ -490,7 +490,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
alpm_logaction(handle, ALPM_CALLER_PREFIX,
"error: could not create database entry %s-%s\n",
newpkg->name, newpkg->version);
- handle->pm_errno = ALPM_ERR_DB_WRITE;
+ _alpm_set_errno(handle, ALPM_ERR_DB_WRITE);
ret = -1;
goto cleanup;
}
@@ -601,7 +601,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
alpm_logaction(handle, ALPM_CALLER_PREFIX,
"error: could not update database entry %s-%s\n",
newpkg->name, newpkg->version);
- handle->pm_errno = ALPM_ERR_DB_WRITE;
+ _alpm_set_errno(handle, ALPM_ERR_DB_WRITE);
ret = -1;
goto cleanup;
}
@@ -678,7 +678,7 @@ int _alpm_upgrade_packages(alpm_handle_t *handle)
if(commit_single_pkg(handle, newpkg, pkg_current, pkg_count)) {
/* something screwed up on the commit, abort the trans */
trans->state = STATE_INTERRUPTED;
- handle->pm_errno = ALPM_ERR_TRANS_ABORT;
+ _alpm_set_errno(handle, ALPM_ERR_TRANS_ABORT);
/* running ldconfig at this point could possibly screw system */
skip_ldconfig = 1;
ret = -1;
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index d3f951d5..552c1ad7 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -79,7 +79,7 @@ alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
snprintf(myhandle->lockfile, lockfilelen, "%s%s", myhandle->dbpath, lf);
if(_alpm_db_register_local(myhandle) == NULL) {
- myerr = myhandle->pm_errno;
+ myerr = alpm_errno(myhandle);
goto cleanup;
}
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 97a49688..bd7e2b89 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -244,7 +244,7 @@ static struct archive *_cache_mtree_open(alpm_pkg_t *pkg)
}
if((mtree = archive_read_new()) == NULL) {
- pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
@@ -254,7 +254,7 @@ static struct archive *_cache_mtree_open(alpm_pkg_t *pkg)
if((r = _alpm_archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) {
_alpm_log(pkg->handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"),
mtfile, archive_error_string(mtree));
- pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_LIBARCHIVE);
_alpm_archive_read_free(mtree);
goto error;
}
@@ -494,7 +494,7 @@ version_error:
closedir(dbdir);
db->status &= ~DB_STATUS_VALID;
db->status |= DB_STATUS_INVALID;
- db->handle->pm_errno = ALPM_ERR_DB_VERSION;
+ _alpm_set_errno(db->handle, ALPM_ERR_DB_VERSION);
return -1;
}
@@ -1147,7 +1147,7 @@ alpm_db_t *_alpm_db_register_local(alpm_handle_t *handle)
db = _alpm_db_new("local", 1);
if(db == NULL) {
- handle->pm_errno = ALPM_ERR_DB_CREATE;
+ _alpm_set_errno(handle, ALPM_ERR_DB_CREATE);
return NULL;
}
db->ops = &local_db_ops;
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 7e8b7920..9bea295e 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -76,7 +76,7 @@ static void *_package_changelog_open(alpm_pkg_t *pkg)
if(strcmp(entry_name, ".CHANGELOG") == 0) {
changelog = malloc(sizeof(struct package_changelog));
if(!changelog) {
- pkg->handle->pm_errno = ALPM_ERR_MEMORY;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_MEMORY);
_alpm_archive_read_free(archive);
close(fd);
return NULL;
@@ -276,7 +276,7 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle,
alpm_siglist_t **sigdata, int *validation)
{
int has_sig;
- handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(handle, ALPM_ERR_OK);
if(pkgfile == NULL || strlen(pkgfile) == 0) {
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1);
@@ -285,11 +285,11 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle,
/* attempt to access the package file, ensure it exists */
if(_alpm_access(handle, NULL, pkgfile, R_OK) != 0) {
if(errno == ENOENT) {
- handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_NOT_FOUND);
} else if(errno == EACCES) {
- handle->pm_errno = ALPM_ERR_BADPERMS;
+ _alpm_set_errno(handle, ALPM_ERR_BADPERMS);
} else {
- handle->pm_errno = ALPM_ERR_PKG_OPEN;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_OPEN);
}
return -1;
}
@@ -337,13 +337,13 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle,
const char *sig = syncpkg ? syncpkg->base64_sig : NULL;
_alpm_log(handle, ALPM_LOG_DEBUG, "sig data: %s\n", sig ? sig : "<from .sig>");
if(!has_sig && !(level & ALPM_SIG_PACKAGE_OPTIONAL)) {
- handle->pm_errno = ALPM_ERR_PKG_MISSING_SIG;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_MISSING_SIG);
return -1;
}
if(_alpm_check_pgp_helper(handle, pkgfile, sig,
level & ALPM_SIG_PACKAGE_OPTIONAL, level & ALPM_SIG_PACKAGE_MARGINAL_OK,
level & ALPM_SIG_PACKAGE_UNKNOWN_OK, sigdata)) {
- handle->pm_errno = ALPM_ERR_PKG_INVALID_SIG;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_INVALID_SIG);
return -1;
}
if(validation && has_sig) {
@@ -458,7 +458,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
/* create a new archive to parse the mtree and load it from archive into memory */
/* TODO: split this into a function */
if((mtree = archive_read_new()) == NULL) {
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
@@ -478,7 +478,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
if(size < 0) {
_alpm_log(handle, ALPM_LOG_DEBUG, _("error while reading package %s: %s\n"),
pkg->filename, archive_error_string(archive));
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
if(size == 0) {
@@ -492,7 +492,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
_alpm_log(handle, ALPM_LOG_DEBUG,
_("error while reading mtree of package %s: %s\n"),
pkg->filename, archive_error_string(mtree));
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
@@ -516,7 +516,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */
_alpm_log(handle, ALPM_LOG_DEBUG, _("error while reading mtree of package %s: %s\n"),
pkg->filename, archive_error_string(mtree));
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
@@ -571,22 +571,22 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
fd = _alpm_open_archive(handle, pkgfile, &st, &archive, ALPM_ERR_PKG_OPEN);
if(fd < 0) {
if(errno == ENOENT) {
- handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_NOT_FOUND);
} else if(errno == EACCES) {
- handle->pm_errno = ALPM_ERR_BADPERMS;
+ _alpm_set_errno(handle, ALPM_ERR_BADPERMS);
} else {
- handle->pm_errno = ALPM_ERR_PKG_OPEN;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_OPEN);
}
return NULL;
}
newpkg = _alpm_pkg_new();
if(newpkg == NULL) {
- handle->pm_errno = ALPM_ERR_MEMORY;
+ _alpm_set_errno(handle, ALPM_ERR_MEMORY);
goto error;
}
STRDUP(newpkg->filename, pkgfile,
- handle->pm_errno = ALPM_ERR_MEMORY; goto error);
+ _alpm_set_errno(handle, ALPM_ERR_MEMORY); goto error);
newpkg->size = st.st_size;
_alpm_log(handle, ALPM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
@@ -636,7 +636,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
if(archive_read_data_skip(archive)) {
_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
@@ -649,7 +649,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
if(ret != ARCHIVE_EOF && ret != ARCHIVE_OK) { /* An error occurred */
_alpm_log(handle, ALPM_LOG_ERROR, _("error while reading package %s: %s\n"),
pkgfile, archive_error_string(archive));
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ _alpm_set_errno(handle, ALPM_ERR_LIBARCHIVE);
goto error;
}
@@ -686,7 +686,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
return newpkg;
pkg_invalid:
- handle->pm_errno = ALPM_ERR_PKG_INVALID;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_INVALID);
error:
_alpm_pkg_free(newpkg);
_alpm_archive_read_free(archive);
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 46959298..cf91e3c9 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -78,7 +78,7 @@ static int sync_db_validate(alpm_db_t *db)
return 0;
}
if(db->status & DB_STATUS_INVALID) {
- db->handle->pm_errno = ALPM_ERR_DB_INVALID_SIG;
+ _alpm_set_errno(db->handle, ALPM_ERR_DB_INVALID_SIG);
return -1;
}
@@ -126,7 +126,7 @@ static int sync_db_validate(alpm_db_t *db)
if(ret) {
db->status &= ~DB_STATUS_VALID;
db->status |= DB_STATUS_INVALID;
- db->handle->pm_errno = ALPM_ERR_DB_INVALID_SIG;
+ _alpm_set_errno(db->handle, ALPM_ERR_DB_INVALID_SIG);
return 1;
}
}
@@ -186,7 +186,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* Sanity checks */
ASSERT(db != NULL, return -1);
handle = db->handle;
- handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(handle, ALPM_ERR_OK);
ASSERT(db != handle->db_local, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, -1));
ASSERT(db->servers != NULL, RET_ERR(handle, ALPM_ERR_SERVER_NONE, -1));
@@ -501,7 +501,7 @@ static int sync_db_populate(alpm_db_t *db)
db->pkgcache = _alpm_pkghash_create(est_count);
if(db->pkgcache == NULL) {
- db->handle->pm_errno = ALPM_ERR_MEMORY;
+ _alpm_set_errno(db->handle, ALPM_ERR_MEMORY);
ret = -1;
goto cleanup;
}
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index d52f8942..43210db3 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -479,7 +479,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
}
conflicts = add_fileconflict(handle, conflicts, path, p1, p2);
- if(handle->pm_errno == ALPM_ERR_MEMORY) {
+ if(alpm_errno(handle) == ALPM_ERR_MEMORY) {
alpm_list_free_inner(conflicts,
(alpm_list_fn_free) alpm_conflict_free);
alpm_list_free(conflicts);
@@ -684,7 +684,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(alpm_handle_t *handle,
if(!resolved_conflict) {
conflicts = add_fileconflict(handle, conflicts, path, p1,
_alpm_find_file_owner(handle, relative_path));
- if(handle->pm_errno == ALPM_ERR_MEMORY) {
+ if(alpm_errno(handle) == ALPM_ERR_MEMORY) {
alpm_list_free_inner(conflicts,
(alpm_list_fn_free) alpm_conflict_free);
alpm_list_free(conflicts);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 789478e8..5d31f156 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -112,7 +112,7 @@ int SYMEXPORT alpm_db_unregister(alpm_db_t *db)
ASSERT(db != NULL, return -1);
/* Do not unregister a database if a transaction is on-going */
handle = db->handle;
- handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(handle, ALPM_ERR_OK);
ASSERT(handle->trans == NULL, RET_ERR(handle, ALPM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) {
@@ -179,7 +179,7 @@ int SYMEXPORT alpm_db_add_server(alpm_db_t *db, const char *url)
/* Sanity checks */
ASSERT(db != NULL, return -1);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url);
@@ -206,7 +206,7 @@ int SYMEXPORT alpm_db_remove_server(alpm_db_t *db, const char *url)
/* Sanity checks */
ASSERT(db != NULL, return -1);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
ASSERT(url != NULL && strlen(url) != 0, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
newurl = sanitize_url(url);
@@ -249,7 +249,7 @@ int SYMEXPORT alpm_db_get_siglevel(alpm_db_t *db)
int SYMEXPORT alpm_db_get_valid(alpm_db_t *db)
{
ASSERT(db != NULL, return -1);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
return db->ops->validate(db);
}
@@ -258,7 +258,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name)
{
alpm_pkg_t *pkg;
ASSERT(db != NULL, return NULL);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
ASSERT(name != NULL && strlen(name) != 0,
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
@@ -273,7 +273,7 @@ alpm_pkg_t SYMEXPORT *alpm_db_get_pkg(alpm_db_t *db, const char *name)
alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db)
{
ASSERT(db != NULL, return NULL);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
return _alpm_db_get_pkgcache(db);
}
@@ -281,7 +281,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_pkgcache(alpm_db_t *db)
alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name)
{
ASSERT(db != NULL, return NULL);
- db->handle->pm_errno = 0;
+ _alpm_set_errno(db->handle, 0);
ASSERT(name != NULL && strlen(name) != 0,
RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, NULL));
@@ -292,7 +292,7 @@ alpm_group_t SYMEXPORT *alpm_db_get_group(alpm_db_t *db, const char *name)
alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db)
{
ASSERT(db != NULL, return NULL);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
return _alpm_db_get_groupcache(db);
}
@@ -301,7 +301,7 @@ alpm_list_t SYMEXPORT *alpm_db_get_groupcache(alpm_db_t *db)
alpm_list_t SYMEXPORT *alpm_db_search(alpm_db_t *db, const alpm_list_t *needles)
{
ASSERT(db != NULL, return NULL);
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
return _alpm_db_search(db, needles);
}
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 96f91739..3aead3a9 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -759,9 +759,9 @@ static alpm_pkg_t *resolvedep(alpm_handle_t *handle, alpm_depend_t *dep,
}
if(ignored) { /* resolvedeps will override these */
- handle->pm_errno = ALPM_ERR_PKG_IGNORED;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_IGNORED);
} else {
- handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
+ _alpm_set_errno(handle, ALPM_ERR_PKG_NOT_FOUND);
}
return NULL;
}
@@ -863,7 +863,7 @@ int _alpm_resolvedeps(alpm_handle_t *handle, alpm_list_t *localpkgs,
} else if(resolvedep(handle, missdep, (targ = alpm_list_add(NULL, handle->db_local)), rem, 0)) {
alpm_depmissing_free(miss);
} else {
- handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
+ _alpm_set_errno(handle, ALPM_ERR_UNSATISFIED_DEPS);
char *missdepstring = alpm_dep_compute_string(missdep);
_alpm_log(handle, ALPM_LOG_WARNING,
_("cannot resolve \"%s\", a dependency of \"%s\"\n"),
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 875b689c..9afcbfcf 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -374,7 +374,7 @@ static int curl_download_internal(struct dload_payload *payload,
/* shortcut to our handle within the payload */
alpm_handle_t *handle = payload->handle;
CURL *curl = get_libcurl_handle(handle);
- handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(handle, ALPM_ERR_OK);
/* make sure these are NULL */
FREE(payload->tempfile_name);
@@ -414,7 +414,7 @@ static int curl_download_internal(struct dload_payload *payload,
if(localf == NULL) {
localf = fopen(payload->tempfile_name, payload->tempfile_openmode);
if(localf == NULL) {
- handle->pm_errno = ALPM_ERR_RETRIEVE;
+ _alpm_set_errno(handle, ALPM_ERR_RETRIEVE);
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not open file %s: %s\n"),
payload->tempfile_name, strerror(errno));
@@ -467,7 +467,7 @@ static int curl_download_internal(struct dload_payload *payload,
if(dload_interrupted == ABORT_OVER_MAXFILESIZE) {
payload->curlerr = CURLE_FILESIZE_EXCEEDED;
payload->unlink_on_fail = 1;
- handle->pm_errno = ALPM_ERR_LIBCURL;
+ _alpm_set_errno(handle, ALPM_ERR_LIBCURL);
_alpm_log(handle, ALPM_LOG_ERROR,
_("failed retrieving file '%s' from %s : expected download size exceeded\n"),
payload->remote_name, hostname);
@@ -479,7 +479,7 @@ static int curl_download_internal(struct dload_payload *payload,
payload->unlink_on_fail = 1;
}
if(!payload->errors_ok) {
- handle->pm_errno = ALPM_ERR_LIBCURL;
+ _alpm_set_errno(handle, ALPM_ERR_LIBCURL);
_alpm_log(handle, ALPM_LOG_ERROR,
_("failed retrieving file '%s' from %s : %s\n"),
payload->remote_name, hostname, error_buffer);
@@ -516,7 +516,7 @@ static int curl_download_internal(struct dload_payload *payload,
* as actually being transferred during curl_easy_perform() */
if(!DOUBLE_EQ(remote_size, -1) && !DOUBLE_EQ(bytes_dl, -1) &&
!DOUBLE_EQ(bytes_dl, remote_size)) {
- handle->pm_errno = ALPM_ERR_RETRIEVE;
+ _alpm_set_errno(handle, ALPM_ERR_RETRIEVE);
_alpm_log(handle, ALPM_LOG_ERROR, _("%s appears to be truncated: %jd/%jd bytes\n"),
payload->remote_name, (intmax_t)bytes_dl, (intmax_t)remote_size);
goto cleanup;
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index b87c3f2e..38e087bf 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -29,7 +29,12 @@
alpm_errno_t SYMEXPORT alpm_errno(alpm_handle_t *handle)
{
+#ifdef HAVE_PTHREAD
+ int *err = pthread_getspecific(handle->tkey_err);
+ return err ? *err : 0;
+#else
return handle->pm_errno;
+#endif
}
const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 941bdd25..c58718fc 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -50,8 +50,13 @@ alpm_handle_t *_alpm_handle_new(void)
#ifdef HAVE_PTHREAD
pthread_mutex_init(&(handle->tlock_cb), NULL);
pthread_mutex_init(&(handle->tlock_log), NULL);
+ pthread_mutex_init(&(handle->tlock_task), NULL);
+ pthread_key_create(&(handle->tkey_err), free);
+ pthread_setspecific(handle->tkey_err, malloc(sizeof(int)));
#endif
+ _alpm_set_errno(handle, 0);
+
return handle;
}
@@ -539,7 +544,7 @@ int SYMEXPORT alpm_option_set_logfile(alpm_handle_t *handle, const char *logfile
CHECK_HANDLE(handle, return -1);
if(!logfile) {
- handle->pm_errno = ALPM_ERR_WRONG_ARGS;
+ _alpm_set_errno(handle, ALPM_ERR_WRONG_ARGS);
return -1;
}
@@ -887,4 +892,17 @@ int SYMEXPORT alpm_option_set_disable_dl_timeout(alpm_handle_t *handle,
return 0;
}
+void _alpm_set_errno(alpm_handle_t *handle, alpm_errno_t err) {
+#ifdef HAVE_PTHREAD
+ alpm_errno_t *err_key = pthread_getspecific(handle->tkey_err);
+ if(!err_key) {
+ err_key = malloc(sizeof(alpm_errno_t));
+ pthread_setspecific(handle->tkey_err, err_key);
+ }
+ *err_key = err;
+#else
+ handle->pm_errno = err;
+#endif
+}
+
/* vim: set noet: */
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 9cf396ce..10a430ac 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -28,6 +28,10 @@
#include "alpm.h"
#include "thread.h"
+#ifdef HAVE_PTHREAD
+#include <pthread.h>
+#endif
+
#ifdef HAVE_LIBCURL
#include <curl/curl.h>
#endif
@@ -112,9 +116,6 @@ struct __alpm_handle_t {
int remotefilesiglevel; /* Signature verification level for remote file
upgrade operations */
- /* error code */
- alpm_errno_t pm_errno;
-
/* lock file descriptor */
int lockfd;
@@ -125,6 +126,11 @@ struct __alpm_handle_t {
#ifdef HAVE_PTHREAD
pthread_mutex_t tlock_cb;
pthread_mutex_t tlock_log;
+ pthread_mutex_t tlock_task;
+ pthread_key_t tkey_err;
+#else
+ /* error code */
+ alpm_errno_t pm_errno;
#endif
};
@@ -137,6 +143,8 @@ int _alpm_handle_unlock(alpm_handle_t *handle);
alpm_errno_t _alpm_set_directory_option(const char *value,
char **storage, int must_exist);
+void _alpm_set_errno(alpm_handle_t *handle, alpm_errno_t err);
+
#endif /* ALPM_HANDLE_H */
/* vim: set noet: */
diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c
index 82c0edad..26f811e5 100644
--- a/lib/libalpm/log.c
+++ b/lib/libalpm/log.c
@@ -76,11 +76,11 @@ int SYMEXPORT alpm_logaction(alpm_handle_t *handle, const char *prefix,
/* if we couldn't open it, we have an issue */
if(fd < 0 || (handle->logstream = fdopen(fd, "a")) == NULL) {
if(errno == EACCES) {
- handle->pm_errno = ALPM_ERR_BADPERMS;
+ _alpm_set_errno(handle, ALPM_ERR_BADPERMS);
} else if(errno == ENOENT) {
- handle->pm_errno = ALPM_ERR_NOT_A_DIR;
+ _alpm_set_errno(handle, ALPM_ERR_NOT_A_DIR);
} else {
- handle->pm_errno = ALPM_ERR_SYSTEM;
+ _alpm_set_errno(handle, ALPM_ERR_SYSTEM);
}
ret = -1;
}
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index e9ecc178..528b18e5 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -60,7 +60,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
int retval;
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
/* We only inspect packages from sync repositories */
ASSERT(pkg->origin == ALPM_PKG_FROM_SYNCDB,
RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1));
@@ -72,7 +72,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
FREE(fpath);
if(retval == 1) {
- pkg->handle->pm_errno = ALPM_ERR_PKG_INVALID;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_PKG_INVALID);
retval = -1;
}
@@ -188,154 +188,154 @@ struct pkg_operations default_pkg_ops = {
const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->filename;
}
const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_base(pkg);
}
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->name;
}
const char SYMEXPORT *alpm_pkg_get_version(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->version;
}
alpm_pkgfrom_t SYMEXPORT alpm_pkg_get_origin(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->origin;
}
const char SYMEXPORT *alpm_pkg_get_desc(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_desc(pkg);
}
const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_url(pkg);
}
alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_builddate(pkg);
}
alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_installdate(pkg);
}
const char SYMEXPORT *alpm_pkg_get_packager(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_packager(pkg);
}
const char SYMEXPORT *alpm_pkg_get_md5sum(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->md5sum;
}
const char SYMEXPORT *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->sha256sum;
}
const char SYMEXPORT *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->base64_sig;
}
const char SYMEXPORT *alpm_pkg_get_arch(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_arch(pkg);
}
off_t SYMEXPORT alpm_pkg_get_size(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->size;
}
off_t SYMEXPORT alpm_pkg_get_isize(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_isize(pkg);
}
alpm_pkgreason_t SYMEXPORT alpm_pkg_get_reason(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_reason(pkg);
}
int SYMEXPORT alpm_pkg_get_validation(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_validation(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_licenses(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_licenses(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_groups(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_groups(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_depends(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_depends(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_optdepends(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_optdepends(pkg);
}
@@ -356,42 +356,42 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_makedepends(alpm_pkg_t *pkg)
alpm_list_t SYMEXPORT *alpm_pkg_get_conflicts(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_conflicts(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_provides(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_provides(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_replaces(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_replaces(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_deltas(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->deltas;
}
alpm_filelist_t SYMEXPORT *alpm_pkg_get_files(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_files(pkg);
}
alpm_list_t SYMEXPORT *alpm_pkg_get_backup(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->get_backup(pkg);
}
@@ -400,7 +400,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg)
/* Sanity checks */
ASSERT(pkg != NULL, return NULL);
ASSERT(pkg->origin != ALPM_PKG_FROM_FILE, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->origin_data.db;
}
@@ -409,7 +409,7 @@ alpm_db_t SYMEXPORT *alpm_pkg_get_db(alpm_pkg_t *pkg)
void SYMEXPORT *alpm_pkg_changelog_open(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->changelog_open(pkg);
}
@@ -418,7 +418,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size,
const alpm_pkg_t *pkg, void *fp)
{
ASSERT(pkg != NULL, return 0);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->changelog_read(ptr, size, pkg, fp);
}
@@ -426,7 +426,7 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size,
int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->changelog_close(pkg, fp);
}
@@ -434,7 +434,7 @@ int SYMEXPORT alpm_pkg_changelog_close(const alpm_pkg_t *pkg, void *fp)
struct archive SYMEXPORT *alpm_pkg_mtree_open(alpm_pkg_t * pkg)
{
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->mtree_open(pkg);
}
@@ -443,7 +443,7 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv
struct archive_entry **entry)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->mtree_next(pkg, archive, entry);
}
@@ -451,14 +451,14 @@ int SYMEXPORT alpm_pkg_mtree_next(const alpm_pkg_t * pkg, struct archive *archiv
int SYMEXPORT alpm_pkg_mtree_close(const alpm_pkg_t * pkg, struct archive *archive)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->mtree_close(pkg, archive);
}
int SYMEXPORT alpm_pkg_has_scriptlet(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return pkg->ops->has_scriptlet(pkg);
}
@@ -466,7 +466,7 @@ static void find_requiredby(alpm_pkg_t *pkg, alpm_db_t *db, alpm_list_t **reqs,
int optional)
{
const alpm_list_t *i;
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
for(i = _alpm_db_get_pkgcache(db); i; i = i->next) {
alpm_pkg_t *cachepkg = i->data;
@@ -496,7 +496,7 @@ static alpm_list_t *compute_requiredby(alpm_pkg_t *pkg, int optional)
alpm_db_t *db;
ASSERT(pkg != NULL, return NULL);
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
if(pkg->origin == ALPM_PKG_FROM_FILE) {
/* The sane option; search locally for things that require this. */
@@ -586,7 +586,7 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
_("could not fully load metadata for package %s-%s\n"),
pkg->name, pkg->version);
ret = 1;
- pkg->handle->pm_errno = ALPM_ERR_PKG_INVALID;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_PKG_INVALID);
}
CALLOC(newpkg, 1, sizeof(alpm_pkg_t), goto cleanup);
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index ffe92518..36136949 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -763,7 +763,7 @@ int _alpm_remove_packages(alpm_handle_t *handle, int run_ldconfig)
if(_alpm_remove_single_package(handle, pkg, NULL,
targ_count, pkg_count) == -1) {
- handle->pm_errno = ALPM_ERR_TRANS_ABORT;
+ _alpm_set_errno(handle, ALPM_ERR_TRANS_ABORT);
/* running ldconfig at this point could possibly screw system */
run_ldconfig = 0;
ret = -1;
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 95cb3280..b7587d1c 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -165,7 +165,7 @@ static int init_gpgme(alpm_handle_t *handle)
if(_alpm_access(handle, sigdir, "pubring.gpg", R_OK)
|| _alpm_access(handle, sigdir, "trustdb.gpg", R_OK)) {
- handle->pm_errno = ALPM_ERR_NOT_A_FILE;
+ _alpm_set_errno(handle, ALPM_ERR_NOT_A_FILE);
_alpm_log(handle, ALPM_LOG_DEBUG, "Signature verification will fail!\n");
_alpm_log(handle, ALPM_LOG_WARNING,
_("Public keyring not found; have you run '%s'?\n"),
@@ -520,7 +520,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
|| (sigfile = fopen(sigpath, "rb")) == NULL) {
_alpm_log(handle, ALPM_LOG_DEBUG, "sig path %s could not be opened\n",
sigpath);
- handle->pm_errno = ALPM_ERR_SIG_MISSING;
+ _alpm_set_errno(handle, ALPM_ERR_SIG_MISSING);
goto error;
}
}
@@ -528,7 +528,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
/* does the file we are verifying exist? */
file = fopen(path, "rb");
if(file == NULL) {
- handle->pm_errno = ALPM_ERR_NOT_A_FILE;
+ _alpm_set_errno(handle, ALPM_ERR_NOT_A_FILE);
goto error;
}
@@ -557,7 +557,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
int decode_ret = alpm_decode_signature(base64_sig,
&decoded_sigdata, &data_len);
if(decode_ret) {
- handle->pm_errno = ALPM_ERR_SIG_INVALID;
+ _alpm_set_errno(handle, ALPM_ERR_SIG_INVALID);
goto gpg_error;
}
gpg_err = gpgme_data_new_from_mem(&sigdata,
@@ -575,7 +575,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
CHECK_ERR();
if(!verify_result || !verify_result->signatures) {
_alpm_log(handle, ALPM_LOG_DEBUG, "no signatures returned\n");
- handle->pm_errno = ALPM_ERR_SIG_MISSING;
+ _alpm_set_errno(handle, ALPM_ERR_SIG_MISSING);
goto gpg_error;
}
for(gpgsig = verify_result->signatures, sigcount = 0;
@@ -583,7 +583,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
_alpm_log(handle, ALPM_LOG_DEBUG, "%d signatures returned\n", sigcount);
CALLOC(siglist->results, sigcount, sizeof(alpm_sigresult_t),
- handle->pm_errno = ALPM_ERR_MEMORY; goto gpg_error);
+ _alpm_set_errno(handle, ALPM_ERR_MEMORY); goto gpg_error);
siglist->count = sigcount;
for(gpgsig = verify_result->signatures, sigcount = 0; gpgsig;
@@ -620,7 +620,7 @@ int _alpm_gpgme_checksig(alpm_handle_t *handle, const char *path,
gpg_err = GPG_ERR_NO_ERROR;
/* we dupe the fpr in this case since we have no key to point at */
STRDUP(result->key.fingerprint, gpgsig->fpr,
- handle->pm_errno = ALPM_ERR_MEMORY; goto gpg_error);
+ _alpm_set_errno(handle, ALPM_ERR_MEMORY); goto gpg_error);
} else {
CHECK_ERR();
if(key->uids) {
@@ -772,10 +772,10 @@ int _alpm_check_pgp_helper(alpm_handle_t *handle, const char *path,
RET_ERR(handle, ALPM_ERR_MEMORY, -1));
ret = _alpm_gpgme_checksig(handle, path, base64_sig, siglist);
- if(ret && handle->pm_errno == ALPM_ERR_SIG_MISSING) {
+ if(ret && alpm_errno(handle) == ALPM_ERR_SIG_MISSING) {
if(optional) {
_alpm_log(handle, ALPM_LOG_DEBUG, "missing optional signature\n");
- handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(handle, ALPM_ERR_OK);
ret = 0;
} else {
_alpm_log(handle, ALPM_LOG_DEBUG, "missing required signature\n");
@@ -935,7 +935,7 @@ int SYMEXPORT alpm_pkg_check_pgp_signature(alpm_pkg_t *pkg,
{
ASSERT(pkg != NULL, return -1);
ASSERT(siglist != NULL, RET_ERR(pkg->handle, ALPM_ERR_WRONG_ARGS, -1));
- pkg->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
return _alpm_gpgme_checksig(pkg->handle, pkg->filename,
pkg->base64_sig, siglist);
@@ -952,7 +952,7 @@ int SYMEXPORT alpm_db_check_pgp_signature(alpm_db_t *db,
{
ASSERT(db != NULL, return -1);
ASSERT(siglist != NULL, RET_ERR(db->handle, ALPM_ERR_WRONG_ARGS, -1));
- db->handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(db->handle, ALPM_ERR_OK);
return _alpm_gpgme_checksig(db->handle, _alpm_db_path(db), NULL, siglist);
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index ae0f1e49..c1579753 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -57,7 +57,11 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_syn
alpm_pkg_t *spkg = NULL;
ASSERT(pkg != NULL, return NULL);
+<<<<<<< HEAD
pkg->handle->pm_errno = ALPM_ERR_OK;
+=======
+ _alpm_set_errno(pkg->handle, ALPM_ERR_OK);
+>>>>>>> make pm_errno thread-local
for(i = dbs_sync; !spkg && i; i = i->next) {
alpm_db_t *db = i->data;
@@ -460,7 +464,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
transaction. The packages will be removed from the actual
transaction when the transaction packages are replaced with a
dependency-reordered list below */
- handle->pm_errno = ALPM_ERR_OK;
+ _alpm_set_errno(handle, ALPM_ERR_OK);
if(data) {
alpm_list_free_inner(*data,
(alpm_list_fn_free)alpm_depmissing_free);
@@ -469,7 +473,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
}
} else {
/* pm_errno was set by resolvedeps, callback may have overwrote it */
- handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
+ _alpm_set_errno(handle, ALPM_ERR_UNSATISFIED_DEPS);
alpm_list_free(resolved);
alpm_list_free(unresolvable);
ret = -1;
@@ -534,7 +538,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
sync = sync2;
} else {
_alpm_log(handle, ALPM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
- handle->pm_errno = ALPM_ERR_CONFLICTING_DEPS;
+ _alpm_set_errno(handle, ALPM_ERR_CONFLICTING_DEPS);
ret = -1;
if(data) {
alpm_conflict_t *newconflict = _alpm_conflict_dup(conflict);
@@ -604,7 +608,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
sync->removes = alpm_list_add(sync->removes, local);
} else { /* abort */
_alpm_log(handle, ALPM_LOG_ERROR, _("unresolvable package conflicts detected\n"));
- handle->pm_errno = ALPM_ERR_CONFLICTING_DEPS;
+ _alpm_set_errno(handle, ALPM_ERR_CONFLICTING_DEPS);
ret = -1;
if(data) {
alpm_conflict_t *newconflict = _alpm_conflict_dup(conflict);
@@ -644,7 +648,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
deps = alpm_checkdeps(handle, _alpm_db_get_pkgcache(handle->db_local),
trans->remove, trans->add, 1);
if(deps) {
- handle->pm_errno = ALPM_ERR_UNSATISFIED_DEPS;
+ _alpm_set_errno(handle, ALPM_ERR_UNSATISFIED_DEPS);
ret = -1;
if(data) {
*data = deps;
@@ -785,7 +789,7 @@ static int apply_deltas(alpm_handle_t *handle)
/* one delta failed for this package, cancel the remaining ones */
event.type = ALPM_EVENT_DELTA_PATCH_FAILED;
EVENT(handle, &event);
- handle->pm_errno = ALPM_ERR_DLT_PATCHFAILED;
+ _alpm_set_errno(handle, ALPM_ERR_DLT_PATCHFAILED);
ret = 1;
break;
}
@@ -855,7 +859,7 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
FREE(filepath);
}
alpm_list_free(errors);
- handle->pm_errno = ALPM_ERR_DLT_INVALID;
+ _alpm_set_errno(handle, ALPM_ERR_DLT_INVALID);
return -1;
}
return 0;
@@ -885,9 +889,9 @@ static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t
alpm_list_t *delta_path = spkg->delta_path;
if(!repo->servers) {
- handle->pm_errno = ALPM_ERR_SERVER_NONE;
+ _alpm_set_errno(handle, ALPM_ERR_SERVER_NONE);
_alpm_log(handle, ALPM_LOG_ERROR, "%s: %s\n",
- alpm_strerror(handle->pm_errno), repo->treename);
+ alpm_strerror(alpm_errno(handle)), repo->treename);
return 1;
}
@@ -1154,7 +1158,7 @@ static int check_validity(alpm_handle_t *handle,
if(_alpm_pkg_validate_internal(handle, v.path, v.pkg,
v.siglevel, &v.siglist, &v.validation) == -1) {
struct validity *invalid;
- v.error = handle->pm_errno;
+ v.error = alpm_errno(handle);
MALLOC(invalid, sizeof(struct validity), return -1);
memcpy(invalid, &v, sizeof(struct validity));
errors = alpm_list_add(errors, invalid);
@@ -1193,7 +1197,7 @@ static int check_validity(alpm_handle_t *handle,
}
alpm_list_free(errors);
- if(handle->pm_errno == ALPM_ERR_OK) {
+ if(alpm_errno(handle) == ALPM_ERR_OK) {
RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1);
}
return -1;
@@ -1278,7 +1282,7 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
EVENT(handle, &event);
if(errors) {
- if(handle->pm_errno == ALPM_ERR_OK) {
+ if(alpm_errno(handle) == ALPM_ERR_OK) {
RET_ERR(handle, ALPM_ERR_PKG_INVALID, -1);
}
return -1;
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index e1423ce3..d63cca74 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -63,12 +63,12 @@ void _alpm_alloc_fail(size_t size);
#define RET_ERR_VOID(handle, err) do { \
_alpm_log(handle, ALPM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(err)); \
- (handle)->pm_errno = (err); \
+ _alpm_set_errno(handle, err); \
return; } while(0)
#define RET_ERR(handle, err, ret) do { \
_alpm_log(handle, ALPM_LOG_DEBUG, "returning error %d from %s : %s\n", err, __func__, alpm_strerror(err)); \
- (handle)->pm_errno = (err); \
+ _alpm_set_errno(handle, err); \
return (ret); } while(0)
#define RET_ERR_ASYNC_SAFE(handle, err, ret) do { \
@@ -77,7 +77,7 @@ void _alpm_alloc_fail(size_t size);
#define DOUBLE_EQ(x, y) (fabs((x) - (y)) < DBL_EPSILON)
-#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } (handle)->pm_errno = ALPM_ERR_OK; } while(0)
+#define CHECK_HANDLE(handle, action) do { if(!(handle)) { action; } _alpm_set_errno(handle, ALPM_ERR_OK); } while(0)
/** Standard buffer size used throughout the library. */
#ifdef BUFSIZ