diff options
author | Aurelien Foret <aurelien@archlinux.org> | 2006-01-26 23:16:57 +0100 |
---|---|---|
committer | Aurelien Foret <aurelien@archlinux.org> | 2006-01-26 23:16:57 +0100 |
commit | 831ff882ae70e83af0369a6c9a6faf825b8a884a (patch) | |
tree | ed34617626d708927a7d9a36873149e71fd126d1 /lib/libalpm/alpm.c | |
parent | 18986b1805feb805e3d4da1d94c98ec518836431 (diff) | |
download | pacman-831ff882ae70e83af0369a6c9a6faf825b8a884a.tar.gz pacman-831ff882ae70e83af0369a6c9a6faf825b8a884a.tar.xz |
reworked lock handling (patch from VMiklos <vmiklos@frugalware.org>)
Diffstat (limited to 'lib/libalpm/alpm.c')
-rw-r--r-- | lib/libalpm/alpm.c | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 33faab82..09f8f707 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -50,8 +50,6 @@ #include "handle.h" #include "alpm.h" -#define PM_LOCK "/tmp/pacman.lck" - /* Globals */ pmhandle_t *handle = NULL; enum __pmerrno_t pm_errno; @@ -76,15 +74,6 @@ int alpm_initialize(char *root) RET_ERR(PM_ERR_MEMORY, -1); } - /* lock db */ - if(handle->access == PM_ACCESS_RW) { - handle->lckfd = _alpm_lckmk(PM_LOCK); - if(handle->lckfd == -1) { - FREE(handle); - RET_ERR(PM_ERR_HANDLE_LOCK, -1); - } - } - STRNCPY(str, (root) ? root : PM_ROOT, PATH_MAX); /* add a trailing '/' if there isn't one */ if(str[strlen(str)-1] != '/') { @@ -105,15 +94,13 @@ int alpm_release() ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); /* unlock db */ - if(handle->access == PM_ACCESS_RW) { - if(handle->lckfd != -1) { - close(handle->lckfd); - handle->lckfd = -1; - } - if(_alpm_lckrm(PM_LOCK)) { - _alpm_log(PM_LOG_WARNING, "could not remove lock file %s", PM_LOCK); - alpm_logaction("warning: could not remove lock file %s", PM_LOCK); - } + if(handle->lckfd != -1) { + close(handle->lckfd); + handle->lckfd = -1; + } + if(_alpm_lckrm(PM_LOCK) == -1) { + _alpm_log(PM_LOG_WARNING, "could not remove lock file %s", PM_LOCK); + alpm_logaction("warning: could not remove lock file %s", PM_LOCK); } /* close local database */ @@ -664,6 +651,12 @@ int alpm_trans_init(unsigned char type, unsigned char flags, alpm_trans_cb_event * perform sanity checks on type and flags: * for instance, we can't set UPGRADE and FRESHEN at the same time */ + /* lock db */ + handle->lckfd = _alpm_lckmk(PM_LOCK); + if(handle->lckfd == -1) { + RET_ERR(PM_ERR_HANDLE_LOCK, -1); + } + handle->trans = trans_new(); if(handle->trans == NULL) { RET_ERR(PM_ERR_MEMORY, -1); @@ -765,6 +758,16 @@ int alpm_trans_release() FREETRANS(handle->trans); + /* unlock db */ + if(handle->lckfd != -1) { + close(handle->lckfd); + handle->lckfd = -1; + } + if(_alpm_lckrm(PM_LOCK) == -1) { + _alpm_log(PM_LOG_WARNING, "could not remove lock file %s", PM_LOCK); + alpm_logaction("warning: could not remove lock file %s", PM_LOCK); + } + return(0); } /** @} */ |