From af15744967957d4c14be9a0024475e335a2c4470 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Wed, 5 Oct 2005 21:50:58 +0000 Subject: Applied reworked patch from VMiklos (vmiklos@frugalware.org) Close the lock file descriptor upon handle release --- lib/libalpm/alpm.c | 7 ++++++- lib/libalpm/handle.c | 1 + lib/libalpm/handle.h | 1 + lib/libalpm/util.c | 5 +---- 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index ce83f664..7cf86922 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -74,7 +74,8 @@ int alpm_initialize(char *root) /* lock db */ if(handle->access == PM_ACCESS_RW) { - if(_alpm_lckmk(PM_LOCK) == -1) { + handle->lckfd = _alpm_lckmk(PM_LOCK); + if(handle->lckfd == -1) { FREE(handle); RET_ERR(PM_ERR_HANDLE_LOCK, -1); } @@ -98,6 +99,10 @@ int alpm_release() /* 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); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 883d943a..6e855793 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -50,6 +50,7 @@ pmhandle_t *handle_new() } memset(handle, 0, sizeof(pmhandle_t)); + handle->lckfd = -1; /* see if we're root or not */ handle->uid = geteuid(); diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 55894d80..5f3e8e8e 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -37,6 +37,7 @@ typedef struct __pmhandle_t { pmdb_t *db_local; PMList *dbs_sync; /* List of (pmdb_t *) */ FILE *logfd; + int lckfd; pmtrans_t *trans; /* parameters */ char *root; diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index d08af4e2..a4b9e0ff 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -212,17 +212,14 @@ int _alpm_lckmk(char *file) return(-1); } } - return(fd > 0 ? 0 : -1); - return(0); + return(fd > 0 ? fd : -1); } /* Remove a lock file */ int _alpm_lckrm(char *file) { - /* ORE - we should close the file descriptor opened by lckmk */ return(unlink(file) == -1); } -- cgit v1.2.3-70-g09d2