The following commit has been merged in the master branch: commit 19f7a159d50b4f8ddadda1ede34c9fb9feed1526 Author: Guillem Jover <guil...@debian.org> Date: Thu Feb 25 18:46:13 2010 +0100
libdpkg: Move database lock functions to the modstatdb module diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c index 13af195..beffdac 100644 --- a/lib/dpkg/dbmodify.c +++ b/lib/dpkg/dbmodify.c @@ -32,6 +32,7 @@ #include <ctype.h> #include <string.h> #include <time.h> +#include <fcntl.h> #include <dirent.h> #include <unistd.h> #include <stdlib.h> @@ -138,6 +139,40 @@ static const struct fni { { NULL, NULL } }; +void +lockdatabase(const char *admindir) +{ + static int dblockfd = -1; + int n; + char *dblockfile = NULL; + + n = strlen(admindir); + dblockfile = m_malloc(n + sizeof(LOCKFILE) + 2); + strcpy(dblockfile, admindir); + strcpy(dblockfile + n, "/" LOCKFILE); + + if (dblockfd == -1) { + dblockfd = open(dblockfile, O_RDWR | O_CREAT | O_TRUNC, 0660); + if (dblockfd == -1) { + if (errno == EPERM) + ohshit(_("you do not have permission to lock the dpkg status database")); + ohshite(_("unable to open/create status database lockfile")); + } + } + + lock_file(&dblockfd, dblockfile, + _("unable to lock dpkg status database"), + _("status database area is locked by another process")); + + free(dblockfile); +} + +void +unlockdatabase(void) +{ + unlock_file(); +} + enum modstatdb_rw modstatdb_init(const char *adir, enum modstatdb_rw readwritereq) { const struct fni *fnip; diff --git a/lib/dpkg/lock.c b/lib/dpkg/lock.c index c9353fc..84ff69d 100644 --- a/lib/dpkg/lock.c +++ b/lib/dpkg/lock.c @@ -79,33 +79,3 @@ lock_file(int *lockfd, const char *filename, push_cleanup(cu_unlock_file, ~0, NULL, 0, 1, lockfd); } -void -unlockdatabase(void) -{ - unlock_file(); -} - -void lockdatabase(const char *admindir) { - static int dblockfd = -1; - int n; - char *dblockfile= NULL; - - n= strlen(admindir); - dblockfile= m_malloc(n+sizeof(LOCKFILE)+2); - strcpy(dblockfile,admindir); - strcpy(dblockfile+n, "/" LOCKFILE); - if (dblockfd == -1) { - dblockfd= open(dblockfile, O_RDWR|O_CREAT|O_TRUNC, 0660); - if (dblockfd == -1) { - if (errno == EPERM) - ohshit(_("you do not have permission to lock the dpkg status database")); - ohshite(_("unable to open/create status database lockfile")); - } - } - - lock_file(&dblockfd, dblockfile, - _("unable to lock dpkg status database"), - _("status database area is locked by another process")); - - free(dblockfile); -} -- dpkg's main repository -- To UNSUBSCRIBE, email to debian-dpkg-cvs-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org