diff options
author | Dave Reisner <d@falconindy.com> | 2011-06-24 20:55:32 +0200 |
---|---|---|
committer | Dave Reisner <d@falconindy.com> | 2011-06-24 20:55:32 +0200 |
commit | 2d32a9a3a348d25d6d0f3d12752399bf7fdf6570 (patch) | |
tree | bb330206ea0caa95c9d337a6c5b4b99b6034e756 /lib/libalpm/handle.c | |
parent | 8581694ceb63f4ed2854206b38574599c3d9df28 (diff) | |
parent | e06586ceb49a0dc7e59996ae3a1483337d2ada05 (diff) | |
download | pacman-2d32a9a3a348d25d6d0f3d12752399bf7fdf6570.tar.gz pacman-2d32a9a3a348d25d6d0f3d12752399bf7fdf6570.tar.xz |
Merge branch 'master' of git://projects.archlinux.org/pacman
* 'master' of git://projects.archlinux.org/pacman:
pactree: carry a list of databases for dep resolution
makepkg: Remove a lone quotation mark
makepkg: remove the cleancache option
Don't require a transaction for sync DB updates
Move locking functions to handle
Add a 'valid' flag to the database object
Move database 'version' check to registration time
Do database signature checking at load time
Diffstat (limited to 'lib/libalpm/handle.c')
-rw-r--r-- | lib/libalpm/handle.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index b535e0f3..acd35409 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -22,12 +22,14 @@ #include "config.h" +#include <errno.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include <sys/types.h> #include <syslog.h> #include <sys/stat.h> +#include <fcntl.h> /* libalpm */ #include "handle.h" @@ -86,6 +88,58 @@ void _alpm_handle_free(pmhandle_t *handle) FREE(handle); } +/** Lock the database */ +int _alpm_handle_lock(pmhandle_t *handle) +{ + int fd; + char *dir, *ptr; + + ASSERT(handle->lockfile != NULL, return -1); + ASSERT(handle->lckstream == NULL, return 0); + + /* 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 */ +int _alpm_handle_unlock(pmhandle_t *handle) +{ + ASSERT(handle->lockfile != NULL, return -1); + ASSERT(handle->lckstream != NULL, return 0); + + if(handle->lckstream != NULL) { + fclose(handle->lckstream); + handle->lckstream = NULL; + } + if(unlink(handle->lockfile) && errno != ENOENT) { + return -1; + } + return 0; +} + + alpm_cb_log SYMEXPORT alpm_option_get_logcb(pmhandle_t *handle) { CHECK_HANDLE(handle, return NULL); |