Просмотр исходного кода

libdpkg: Move database lock functions to the modstatdb module

Guillem Jover лет назад: 16
Родитель
Сommit
19f7a159d5
2 измененных файлов с 35 добавлено и 30 удалено
  1. 35 0
      lib/dpkg/dbmodify.c
  2. 0 30
      lib/dpkg/lock.c

+ 35 - 0
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;
   

+ 0 - 30
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);
-}