Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/trans.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-06-24 04:02:58 -0500
committerDan McGee <dan@archlinux.org>2011-06-24 04:02:58 -0500
commit7b8f8f69f14dac2bbcd7e96fc548aa084be7cd8e (patch)
tree7d59d25daa8ffef5afce17627de0caba1902a0c6 /lib/libalpm/trans.c
parent79e98316ea89486d107466858543e965bcfbb0a9 (diff)
Move locking functions to handle
These operate on the handle, and the state is stored on the handle, so move them where they belong. Up until now only the transaction stuff calls them, but this will soon change and alpm_db_update() will handle locking all on its own. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/trans.c')
-rw-r--r--lib/libalpm/trans.c52
1 files changed, 2 insertions, 50 deletions
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 11a28e5c..507ea027 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -30,7 +30,6 @@
#include <sys/types.h>
#include <errno.h>
#include <limits.h>
-#include <fcntl.h>
/* libalpm */
#include "trans.h"
@@ -48,53 +47,6 @@
* @{
*/
-/* Create a lock file */
-static int make_lock(pmhandle_t *handle)
-{
- int fd;
- char *dir, *ptr;
-
- ASSERT(handle->lockfile != NULL, return -1);
-
- /* create the dir of the lockfile first */
- dir = strdup(handle->lockfile);
- ptr = strrchr(dir, '/');
- if(ptr) {
- *ptr = '\0';
- }
- if(_alpm_makepath(dir)) {
- FREE(dir);
- return -1;
- }
- FREE(dir);
-
- do {
- fd = open(handle->lockfile, O_WRONLY | O_CREAT | O_EXCL, 0000);
- } while(fd == -1 && errno == EINTR);
- if(fd > 0) {
- FILE *f = fdopen(fd, "w");
- fprintf(f, "%ld\n", (long)getpid());
- fflush(f);
- fsync(fd);
- handle->lckstream = f;
- return 0;
- }
- return -1;
-}
-
-/* Remove a lock file */
-static int remove_lock(pmhandle_t *handle)
-{
- if(handle->lckstream != NULL) {
- fclose(handle->lckstream);
- handle->lckstream = NULL;
- }
- if(unlink(handle->lockfile) == -1 && errno != ENOENT) {
- return -1;
- }
- return 0;
-}
-
/** Initialize the transaction. */
int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
@@ -116,7 +68,7 @@ int SYMEXPORT alpm_trans_init(pmhandle_t *handle, pmtransflag_t flags,
/* lock db */
if(!(flags & PM_TRANS_FLAG_NOLOCK)) {
- if(make_lock(handle)) {
+ if(_alpm_handle_lock(handle)) {
RET_ERR(handle, PM_ERR_HANDLE_LOCK, -1);
}
}
@@ -278,7 +230,7 @@ int SYMEXPORT alpm_trans_release(pmhandle_t *handle)
/* unlock db */
if(!nolock_flag) {
- if(remove_lock(handle)) {
+ if(_alpm_handle_unlock(handle)) {
_alpm_log(handle, PM_LOG_WARNING, _("could not remove lock file %s\n"),
alpm_option_get_lockfile(handle));
alpm_logaction(handle, "warning: could not remove lock file %s\n",