]> arthur.barton.de Git - netatalk.git/commitdiff
Implement cnid_dbd option -d, deletes CNID db
authorFrank Lahm <franklahm@googlemail.com>
Tue, 28 Jun 2011 12:35:51 +0000 (14:35 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Tue, 28 Jun 2011 12:35:51 +0000 (14:35 +0200)
NEWS
etc/cnid_dbd/cnid_metad.c
etc/cnid_dbd/main.c

diff --git a/NEWS b/NEWS
index 512d9adc05271b830aed05d74e04e1d1c7be8405..53791e3d8984830f25d5d30c68d84c16ecdd577e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,9 @@
 Changes in 2.2.1
 ================
 
-* FIX: cnid_dbd: increase BerkeleyDB locks and lockobjs
 * FIX: afpd: increase BerkeleyDB locks and lockobjs
+* FIX: cnid_dbd: increase BerkeleyDB locks and lockobjs
+* FIX: cnid_dbd: implement -d option, deletes CNID db
 * FIX: suse: initscript return better status
 * FIX: Sourcecode distribution: add missing headers
 * FIX: Solaris 10: missing dirfd replacement function
index 19d0737351bf5e18b286bb84b592e08e7b50d41f..201902d66af1019f44f25adea5c0e82729449f1d 100644 (file)
@@ -252,13 +252,12 @@ static int maybe_start_dbd(char *dbdpn, struct volinfo *volinfo)
         sprintf(buf2, "%i", rqstfd);
 
         if (up->count == MAXSPAWN) {
-            /* there's a pb with the db inform child
-             * it will run recover, delete the db whatever
-             */
-            LOG(log_error, logtype_cnid, "try with -d %s", up->volinfo->v_path);
+            /* there's a pb with the db inform child, it will delete the db */
+            LOG(log_warning, logtype_cnid,
+                "Multiple attempts to start CNID db daemon for \"%s\" failed, wiping the slate clean...",
+                up->volinfo->v_path);
             ret = execlp(dbdpn, dbdpn, "-d", volpath, buf1, buf2, logconfig, NULL);
-        }
-        else {
+        } else {
             ret = execlp(dbdpn, dbdpn, volpath, buf1, buf2, logconfig, NULL);
         }
         /* Yikes! We're still here, so exec failed... */
index 64734396d34f6d7d8cfd1758c68d1b663db8455e..e2f8e98e8fca82e400e39a0cb3ceb61af54df628 100644 (file)
@@ -282,25 +282,27 @@ static void set_signal(void)
 int main(int argc, char *argv[])
 {
     struct db_param *dbp;
-    int err = 0;
+    int err = 0, ret, delete_bdb = 0;
     int ctrlfd, clntfd;
     char *logconfig;
 
     set_processname("cnid_dbd");
 
-    /* FIXME: implement -d from cnid_metad */
-    if (argc  != 5) {
-        LOG(log_error, logtype_cnid, "main: not enough arguments");
-        exit(1);
+    while (( ret = getopt( argc, argv, "d")) != -1 ) {
+        switch (ret) {
+        case 'd':
+            delete_bdb = 1;
+            break;
+        }
     }
 
-    ctrlfd = atoi(argv[2]);
-    clntfd = atoi(argv[3]);
-    logconfig = strdup(argv[4]);
-    setuplog(logconfig);
+    if (argc - optind != 4) {
+        LOG(log_error, logtype_cnid, "main: not enough arguments");
+        exit(EXIT_FAILURE);
+    }
 
     /* Load .volinfo file */
-    if (loadvolinfo(argv[1], &volinfo) == -1) {
+    if (loadvolinfo(argv[optind], &volinfo) == -1) {
         LOG(log_error, logtype_cnid, "Cant load volinfo for \"%s\"", argv[1]);
         exit(EXIT_FAILURE);
     }
@@ -313,6 +315,11 @@ int main(int argc, char *argv[])
     strncpy(dbpath, volinfo.v_dbpath, MAXPATHLEN - strlen("/.AppleDB"));
     strcat(dbpath, "/.AppleDB");
 
+    ctrlfd = atoi(argv[optind + 1]);
+    clntfd = atoi(argv[optind + 2]);
+    logconfig = strdup(argv[optind + 3]);
+    setuplog(logconfig);
+
     if (vol_load_charsets(&volinfo) == -1) {
         LOG(log_error, logtype_cnid, "Error loading charsets!");
         exit(EXIT_FAILURE);
@@ -334,6 +341,16 @@ int main(int argc, char *argv[])
         }
     }
 
+    if (delete_bdb && (db_locked == LOCK_EXCL)) {
+        LOG(log_warning, logtype_cnid, "main: too many CNID db opening attempts, wiping the slate clean");
+        chdir(dbpath);
+        system("rm -f cnid2.db lock log.* __db.*");
+        if ((db_locked = get_lock(LOCK_EXCL, dbpath)) != LOCK_EXCL) {
+            LOG(log_error, logtype_cnid, "main: fatal db lock error");
+            exit(EXIT_FAILURE);
+        }
+    }
+
     set_signal();
 
     /* SIGINT and SIGTERM are always off, unless we are in pselect */