]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/main.c
Refine CNID salvatio strategies
[netatalk.git] / etc / cnid_dbd / main.c
index 5b7c8a7d9866dbd4c487e054e70da77269ea5e23..42cf28489f14e61c055a73a73eb9a75a74742347 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.12 2009-10-18 17:50:13 didg Exp $
+ * $Id: main.c,v 1.16 2009-11-25 14:59:15 franklahm Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * Copyright (c) Frank Lahm 2009
@@ -77,7 +77,8 @@ static void block_sigs_onoff(int block)
 
   1: Success, if transactions are used commit.
   0: Failure, but we continue to serve requests. If transactions are used abort/rollback.
-  -1: Fatal error, either from the database or from the socket. Abort the transaction if applicable
+  -1: Fatal error, either from t
+  he database or from the socket. Abort the transaction if applicable
   (which might fail as well) and then exit.
 
   We always try to notify the client process about the outcome, the result field
@@ -123,19 +124,21 @@ static int loop(struct db_param *dbp)
         else
             timeout = 1;
 
-        if ((cret = comm_rcv(&rqst, timeout, &set)) < 0)
+        if ((cret = comm_rcv(&rqst, timeout, &set, &now)) < 0)
             return -1;
 
-        now = time(NULL);
-
         if (cret == 0) {
             /* comm_rcv returned from select without receiving anything. */
-            if (exit_sig)
+            if (exit_sig) {
                 /* Received signal (TERM|INT) */
                 return 0;
-            if (dbp->idle_timeout && comm_nbe() <= 0 && (now - time_last_rqst) > dbp->idle_timeout)
+            }
+            if (now - time_last_rqst >= dbp->idle_timeout && comm_nbe() <= 0) {
                 /* Idle timeout */
                 return 0;
+            }
+            /* still active connections, reset time_last_rqst */
+            time_last_rqst = now;
         } else {
             /* We got a request */
             time_last_rqst = now;
@@ -150,7 +153,7 @@ static int loop(struct db_param *dbp)
                 ret = 1;
                 break;
             case CNID_DBD_OP_ADD:
-                ret = dbd_add(dbd, &rqst, &rply);
+                ret = dbd_add(dbd, &rqst, &rply, 0);
                 break;
             case CNID_DBD_OP_GET:
                 ret = dbd_get(dbd, &rqst, &rply);
@@ -159,7 +162,7 @@ static int loop(struct db_param *dbp)
                 ret = dbd_resolve(dbd, &rqst, &rply);
                 break;
             case CNID_DBD_OP_LOOKUP:
-                ret = dbd_lookup(dbd, &rqst, &rply);
+                ret = dbd_lookup(dbd, &rqst, &rply, 0);
                 break;
             case CNID_DBD_OP_UPDATE:
                 ret = dbd_update(dbd, &rqst, &rply);
@@ -201,7 +204,7 @@ static int loop(struct db_param *dbp)
           Shall we checkpoint bdb ?
           "flush_interval" seconds passed ?
         */
-        if (now > time_next_flush) {
+        if (now >= time_next_flush) {
             LOG(log_info, logtype_cnid, "Checkpointing BerkeleyDB for volume '%s'", dbp->dir);
             if (dbif_txn_checkpoint(dbd, 0, 0, 0) < 0)
                 return -1;