]> arthur.barton.de Git - netatalk.git/commitdiff
better errors handling in dbd
authordidg <didg>
Sun, 4 Jan 2004 21:36:20 +0000 (21:36 +0000)
committerdidg <didg>
Sun, 4 Jan 2004 21:36:20 +0000 (21:36 +0000)
etc/cnid_dbd/cnid_metad.c
etc/cnid_dbd/dbd_update.c
etc/cnid_dbd/dbif.c

index 581188bf836027cd8c50c9ccb28c765c3c4c0773..1288c82456e64af29de4d907c24b80a5705e6833 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_metad.c,v 1.1.4.8 2004-01-03 23:01:40 lenneis Exp $
+ * $Id: cnid_metad.c,v 1.1.4.9 2004-01-04 21:36:20 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -96,16 +96,19 @@ static int rqstfd;
 #define MAXSRV 128
 
 #define MAXSPAWN   3                   /* Max times respawned in.. */
-#define TESTTIME   20                  /* this much seconds */
 
 #define DEFAULTHOST  "localhost"
 #define DEFAULTPORT  4700
+#define TESTTIME   22                  /* this much seconds apfd client tries to
+                                        * to reconnect every 5 secondes, catch it
+                                        */
 
 struct server {
     char  *name;
     pid_t pid;
     time_t tm;                    /* When respawned last */
     int count;                    /* Times respawned in the last TESTTIME secondes */
+    int toofast; 
     int   sv[2];
 };
 
@@ -194,6 +197,7 @@ static int maybe_start_dbd(char *dbdpn, char *dbdir, char *usockfn)
                 free(up->name);
                 up->tm = t;
                 up->count = 0;
+                up->toofast = 0;
                 /* copy name */
                 up->name = strdup(dbdir);
                 break;
@@ -207,12 +211,18 @@ static int maybe_start_dbd(char *dbdpn, char *dbdir, char *usockfn)
     else {
         /* we have a slot but no process, check for respawn too fast */
         if (up->tm + TESTTIME > t) {
+            if (up->toofast) {
+                /* silently exit */
+                return -1;
+            }
             up->count++;
         } else {
             up->count = 0;
+           up->toofast = 0;
             up->tm = t;
         }
-        if (up->count >= MAXSPAWN) {
+        if (up->count > MAXSPAWN) {
+           up->toofast = 1;
             up->tm = t;
            LOG(log_error, logtype_cnid, "respawn too fast %s", up->name);
            /* FIXME should we sleep a little ? */
@@ -233,6 +243,7 @@ static int maybe_start_dbd(char *dbdpn, char *dbdir, char *usockfn)
        return -1;
     }    
     if (pid == 0) {
+        int ret;
        /*
         *  Child. Close descriptors and start the daemon. If it fails
         *  just log it. The client process will fail connecting
@@ -252,7 +263,17 @@ static int maybe_start_dbd(char *dbdpn, char *dbdir, char *usockfn)
        sprintf(buf1, "%i", up->sv[1]);
        sprintf(buf2, "%i", rqstfd);
        
-       if (execlp(dbdpn, dbdpn, dbdir, buf1, buf2, NULL) < 0) {
+       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->name);
+           ret = execlp(dbdpn, dbdpn, "-d", dbdir, buf1, buf2, NULL);
+       }
+       else {
+           ret = execlp(dbdpn, dbdpn, dbdir, buf1, buf2, NULL);
+       }
+       if (ret < 0) {
            LOG(log_error, logtype_cnid, "Fatal error in exec: %s", strerror(errno));
            exit(0);
        }
@@ -441,6 +462,7 @@ int main(int argc, char *argv[])
     signal(SIGPIPE, SIG_IGN);
 
     while (1) {
+        rqstfd = usockfd_check(srvfd, 10000000);
        /* Collect zombie processes and log what happened to them */       
         while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
            for (i = 1; i <= MAXSRV; i++) {
@@ -465,7 +487,7 @@ int main(int argc, char *argv[])
            /* FIXME should */
            
        }
-        if ((rqstfd = usockfd_check(srvfd, 10000000)) <= 0)
+        if (rqstfd <= 0)
             continue;
         /* TODO: Check out read errors, broken pipe etc. in libatalk. Is
            SIGIPE ignored there? Answer: Ignored for dsi, but not for asp ... */
index e94138bfbaba9bd8bfcdb024cd87cd4ffb001eaa..5c6c679c1bc81333b4383bfc46e0c493cd7bb36e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbd_update.c,v 1.1.4.7 2003-12-12 19:27:57 didg Exp $
+ * $Id: dbd_update.c,v 1.1.4.8 2004-01-04 21:36:20 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -55,10 +55,13 @@ int dbd_update(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     if ((rc = dbif_pget(DBIF_IDX_DEVINO, &key, &pkey, &data, 0)) < 0 ) {
         goto err_db;
     }
-    else if  (rc > 0) { 
+    else if  (rc > 0) {
         if ((rc = dbif_del(DBIF_IDX_CNID, &pkey, 0)) < 0 ) {
             goto err_db;
         }
+        else if (!rc) {
+               LOG(log_error, logtype_cnid, "dbd_update: delete DEVINO %u %s", ntohl(rqst->cnid), db_strerror(errno));
+        }
     }
     if (!rc) {
        notfound = 1;
@@ -76,6 +79,9 @@ int dbd_update(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
         if ((rc = dbif_del(DBIF_IDX_CNID, &pkey, 0)) < 0) {
             goto err_db;
         }
+        else if (!rc) {
+               LOG(log_error, logtype_cnid, "dbd_update: delete DIDNAME %u %s",ntohl(rqst->cnid), db_strerror(errno));
+        }
     }
     if (!rc) {
        notfound |= 2;
@@ -98,8 +104,8 @@ int dbd_update(struct cnid_dbd_rqst *rqst, struct cnid_dbd_rply *rply)
     return 1;
 
 err_db:
-    LOG(log_error, logtype_cnid, "dbd_update: Unable to update CNID %u",
-        ntohl(rqst->cnid));
+    LOG(log_error, logtype_cnid, "dbd_update: Unable to update CNID %u inode %llx, DID %x:%s",
+        ntohl(rqst->cnid), rqst->ino, rqst->did, rqst->name);
     rply->result = CNID_DBD_RES_ERR_DB;
     return -1;
 }
index 0f7e3af020b0dcb07a9f7654bbdf5a85a13402f6..fe9f77c137d18793b4a2ec48d81835c9898b4420 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbif.c,v 1.1.4.8 2003-12-16 23:06:32 lenneis Exp $
+ * $Id: dbif.c,v 1.1.4.9 2004-01-04 21:36:20 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYRIGHT.
@@ -162,6 +162,7 @@ int dbif_env_init(struct db_param *dbp)
         LOG(log_error, logtype_cnid, "error opening DB environment: %s", 
             db_strerror(ret));
         db_env->close(db_env, 0);
+        db_env = NULL;
         return -1;
     }
 
@@ -171,6 +172,7 @@ int dbif_env_init(struct db_param *dbp)
     if (ret = db_env->close(db_env, 0)) {
         LOG(log_error, logtype_cnid, "error closing DB environment after recovery: %s", 
             db_strerror(ret));
+        db_env = NULL;
         return -1;
     }
 #endif
@@ -183,6 +185,7 @@ int dbif_env_init(struct db_param *dbp)
         LOG(log_error, logtype_cnid, "error setting DB environment cachesize to %i: %s",
             dbp->cachesize, db_strerror(ret));
         db_env->close(db_env, 0);
+        db_env = NULL;
         return -1;
     }
     
@@ -192,6 +195,7 @@ int dbif_env_init(struct db_param *dbp)
         LOG(log_error, logtype_cnid, "error opening DB environment after recovery: %s",
             db_strerror(ret));
         db_env->close(db_env, 0);
+        db_env = NULL;
         return -1;      
     }
 
@@ -200,6 +204,7 @@ int dbif_env_init(struct db_param *dbp)
         LOG(log_error, logtype_cnid, "error setting TXN_NOSYNC flag: %s",
             db_strerror(ret));
         db_env->close(db_env, 0);
+        db_env = NULL;
         return -1;      
     }
 #endif