Applied reworked patch from VMiklos (vmiklos@frugalware.org)

Close the lock file descriptor upon handle release
This commit is contained in:
Aurelien Foret 2005-10-05 21:50:58 +00:00
parent d7e781a54b
commit af15744967
4 changed files with 9 additions and 5 deletions

View file

@ -74,7 +74,8 @@ int alpm_initialize(char *root)
/* lock db */ /* lock db */
if(handle->access == PM_ACCESS_RW) { if(handle->access == PM_ACCESS_RW) {
if(_alpm_lckmk(PM_LOCK) == -1) { handle->lckfd = _alpm_lckmk(PM_LOCK);
if(handle->lckfd == -1) {
FREE(handle); FREE(handle);
RET_ERR(PM_ERR_HANDLE_LOCK, -1); RET_ERR(PM_ERR_HANDLE_LOCK, -1);
} }
@ -98,6 +99,10 @@ int alpm_release()
/* unlock db */ /* unlock db */
if(handle->access == PM_ACCESS_RW) { if(handle->access == PM_ACCESS_RW) {
if(handle->lckfd != -1) {
close(handle->lckfd);
handle->lckfd = -1;
}
if(_alpm_lckrm(PM_LOCK)) { if(_alpm_lckrm(PM_LOCK)) {
_alpm_log(PM_LOG_WARNING, "could not remove lock file %s", 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); alpm_logaction("warning: could not remove lock file %s", PM_LOCK);

View file

@ -50,6 +50,7 @@ pmhandle_t *handle_new()
} }
memset(handle, 0, sizeof(pmhandle_t)); memset(handle, 0, sizeof(pmhandle_t));
handle->lckfd = -1;
/* see if we're root or not */ /* see if we're root or not */
handle->uid = geteuid(); handle->uid = geteuid();

View file

@ -37,6 +37,7 @@ typedef struct __pmhandle_t {
pmdb_t *db_local; pmdb_t *db_local;
PMList *dbs_sync; /* List of (pmdb_t *) */ PMList *dbs_sync; /* List of (pmdb_t *) */
FILE *logfd; FILE *logfd;
int lckfd;
pmtrans_t *trans; pmtrans_t *trans;
/* parameters */ /* parameters */
char *root; char *root;

View file

@ -212,17 +212,14 @@ int _alpm_lckmk(char *file)
return(-1); return(-1);
} }
} }
return(fd > 0 ? 0 : -1);
return(0); return(fd > 0 ? fd : -1);
} }
/* Remove a lock file /* Remove a lock file
*/ */
int _alpm_lckrm(char *file) int _alpm_lckrm(char *file)
{ {
/* ORE
we should close the file descriptor opened by lckmk */
return(unlink(file) == -1); return(unlink(file) == -1);
} }