The following commit has been merged in the master branch:
commit 972d84487ace85a7f547c5b9d74be1a4253d1e79
Author: Guillem Jover <[email protected]>
Date: Fri Feb 26 00:01:28 2010 +0100
libdpkg: Move generic file locking from lock.c to file.c
diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am
index 2412365..e9b54ba 100644
--- a/lib/dpkg/Makefile.am
+++ b/lib/dpkg/Makefile.am
@@ -34,7 +34,6 @@ libdpkg_a_SOURCES = \
file.c \
fields.c \
i18n.h \
- lock.c \
log.c \
md5.c md5.h \
mlib.c \
diff --git a/lib/dpkg/dbmodify.c b/lib/dpkg/dbmodify.c
index 8b835dd..a642453 100644
--- a/lib/dpkg/dbmodify.c
+++ b/lib/dpkg/dbmodify.c
@@ -41,6 +41,7 @@
#include <dpkg/i18n.h>
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
+#include <dpkg/file.h>
char *statusfile=NULL, *availablefile=NULL;
char *triggersdir, *triggersfilefile, *triggersnewfilefile;
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 3d4fe7f..749c172 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -173,12 +173,6 @@ void cu_closepipe(int argc, void **argv);
void cu_closedir(int argc, void **argv);
void cu_closefd(int argc, void **argv);
-/*** lock.c ***/
-
-void file_lock(int *lockfd, const char *filename,
- const char *emsg, const char *emsg_eagain);
-void file_unlock(void);
-
/*** from mlib.c ***/
void setcloexec(int fd, const char* fn);
diff --git a/lib/dpkg/file.c b/lib/dpkg/file.c
index 3533245..f46d8e7 100644
--- a/lib/dpkg/file.c
+++ b/lib/dpkg/file.c
@@ -2,7 +2,7 @@
* libdpkg - Debian packaging suite library routines
* file.c - file handling functions
*
- * Copyright © 1995 Ian Jackson <[email protected]>
+ * Copyright © 1994, 1995 Ian Jackson <[email protected]>
* Copyright © 2008 Guillem Jover <[email protected]>
*
* This is free software; you can redistribute it and/or modify
@@ -25,7 +25,9 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <assert.h>
#include <errno.h>
+#include <fcntl.h>
#include <unistd.h>
#include <dpkg/dpkg.h>
@@ -51,3 +53,48 @@ file_copy_perms(const char *src, const char *dst)
ohshite(_("unable to set mode of target file '%.250s'"), dst);
}
+static void
+file_unlock_cleanup(int argc, void **argv)
+{
+ int lockfd = *(int*)argv[0];
+ struct flock fl;
+
+ assert(lockfd >= 0);
+ fl.l_type = F_UNLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+ if (fcntl(lockfd, F_SETLK, &fl) == -1)
+ ohshite(_("unable to unlock dpkg status database"));
+}
+
+void
+file_unlock(void)
+{
+ pop_cleanup(ehflag_normaltidy); /* Calls file_unlock_cleanup. */
+}
+
+/* lockfd must be allocated statically as its addresses is passed to
+ * a cleanup handler. */
+void
+file_lock(int *lockfd, const char *filename,
+ const char *emsg, const char *emsg_eagain)
+{
+ struct flock fl;
+
+ setcloexec(*lockfd, filename);
+
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+
+ if (fcntl(*lockfd, emsg_eagain ? F_SETLK : F_SETLKW, &fl) == -1) {
+ if (emsg_eagain && (errno == EACCES || errno == EAGAIN))
+ ohshit(emsg_eagain);
+ ohshite(emsg);
+ }
+
+ push_cleanup(file_unlock_cleanup, ~0, NULL, 0, 1, lockfd);
+}
+
diff --git a/lib/dpkg/file.h b/lib/dpkg/file.h
index dc54f09..ee14206 100644
--- a/lib/dpkg/file.h
+++ b/lib/dpkg/file.h
@@ -30,6 +30,10 @@ DPKG_BEGIN_DECLS
*/
void file_copy_perms(const char *src, const char *dst);
+void file_lock(int *lockfd, const char *filename,
+ const char *emsg, const char *emsg_eagain);
+void file_unlock(void);
+
DPKG_END_DECLS
#endif /* LIBDPKG_FILE_H */
diff --git a/lib/dpkg/lock.c b/lib/dpkg/lock.c
deleted file mode 100644
index 0ed1d7b..0000000
--- a/lib/dpkg/lock.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * libdpkg - Debian packaging suite library routines
- * lock.c - packages database locking
- *
- * Copyright © 1994,1995 Ian Jackson <[email protected]>
- *
- * This is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-#include <compat.h>
-
-#include <sys/file.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
-#include <dpkg/i18n.h>
-#include <dpkg/dpkg.h>
-#include <dpkg/dpkg-db.h>
-
-static void
-file_unlock_cleanup(int argc, void **argv)
-{
- int lockfd = *(int*)argv[0];
- struct flock fl;
-
- assert(lockfd >= 0);
- fl.l_type= F_UNLCK;
- fl.l_whence= SEEK_SET;
- fl.l_start= 0;
- fl.l_len= 0;
- if (fcntl(lockfd, F_SETLK, &fl) == -1)
- ohshite(_("unable to unlock dpkg status database"));
-}
-
-void
-file_unlock(void)
-{
- pop_cleanup(ehflag_normaltidy); /* Calls file_unlock_cleanup. */
-}
-
-/* lockfd must be allocated statically as its addresses is passed to
- * a cleanup handler. */
-void
-file_lock(int *lockfd, const char *filename,
- const char *emsg, const char *emsg_eagain)
-{
- struct flock fl;
-
- setcloexec(*lockfd, filename);
-
- fl.l_type = F_WRLCK;
- fl.l_whence = SEEK_SET;
- fl.l_start = 0;
- fl.l_len = 0;
-
- if (fcntl(*lockfd, emsg_eagain ? F_SETLK : F_SETLKW, &fl) == -1) {
- if (emsg_eagain && (errno == EACCES || errno == EAGAIN))
- ohshit(emsg_eagain);
- ohshite(emsg);
- }
-
- push_cleanup(file_unlock_cleanup, ~0, NULL, 0, 1, lockfd);
-}
-
diff --git a/lib/dpkg/trigdeferred.l b/lib/dpkg/trigdeferred.l
index 93cb8d6..9d3ca45 100644
--- a/lib/dpkg/trigdeferred.l
+++ b/lib/dpkg/trigdeferred.l
@@ -43,6 +43,7 @@
#include <dpkg/i18n.h>
#include <dpkg/dpkg.h>
#include <dpkg/dpkg-db.h>
+#include <dpkg/file.h>
#define YY_NO_INPUT
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 053b985..673573c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,7 +11,6 @@ lib/dpkg/dump.c
lib/dpkg/ehandle.c
lib/dpkg/fields.c
lib/dpkg/file.c
-lib/dpkg/lock.c
lib/dpkg/log.c
lib/dpkg/md5.c
lib/dpkg/mlib.c
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]