]> arthur.barton.de Git - netatalk.git/commitdiff
do some sanity checks on dbd params read from config file
authordidg <didg>
Mon, 19 Oct 2009 05:38:22 +0000 (05:38 +0000)
committerdidg <didg>
Mon, 19 Oct 2009 05:38:22 +0000 (05:38 +0000)
etc/cnid_dbd/db_param.c
etc/cnid_dbd/main.c

index f291ed188a5e25cb42cc80aa4b2814ca272f35d0..82a9d35b52e12d1323d5a5fc37e0c8e107ba4474 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: db_param.c,v 1.7 2009-10-19 05:02:35 didg Exp $
+ * $Id: db_param.c,v 1.8 2009-10-19 05:38:22 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * Copyright (c) Frank Lahm 2009
 #define MAXKEYLEN         64
 
 #define DEFAULT_LOGFILE_AUTOREMOVE 1
-#define DEFAULT_CACHESIZE          8 * 1024 
-#define DEFAULT_FLUSH_FREQUENCY    100
+#define DEFAULT_CACHESIZE          (8 * 1024)
+#define DEFAULT_FLUSH_FREQUENCY    1000
 #define DEFAULT_FLUSH_INTERVAL     1800
 #define DEFAULT_USOCK_FILE         "usock"
 #define DEFAULT_FD_TABLE_SIZE      512
-#define DEFAULT_IDLE_TIMEOUT       10 * 60
+#define DEFAULT_IDLE_TIMEOUT       (10 * 60)
 
 static struct db_param params;
 static int parse_err;
@@ -186,8 +186,22 @@ struct db_param *db_param_read(char *dir, enum identity id)
     }
 
     fclose(fp);
-    if (! parse_err)
+    if (! parse_err) {
+        /* sanity checks */
+        if (params.flush_frequency <= 0) 
+            params.flush_frequency = 86400;
+
+        if (params.flush_interval <= 0)
+            params.flush_interval = 1000000;
+
+        if (params.fd_table_size <= 2)
+            params.fd_table_size = 32;
+
+        if (params.idle_timeout <= 0)
+            params.idle_timeout = 86400;
+
         return &params;
+    }
     else
         return NULL;
 }
index 5b7c8a7d9866dbd4c487e054e70da77269ea5e23..eb99102668dc0d1a1f34ea54a7145faa0de12695 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.13 2009-10-19 05:38:22 didg 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
@@ -133,9 +134,16 @@ static int loop(struct db_param *dbp)
             if (exit_sig)
                 /* Received signal (TERM|INT) */
                 return 0;
-            if (dbp->idle_timeout && comm_nbe() <= 0 && (now - time_last_rqst) > dbp->idle_timeout)
-                /* Idle timeout */
-                return 0;
+            if (now - time_last_rqst > dbp->idle_timeout) {
+                if (comm_nbe() <= 0) {
+                    /* Idle timeout */
+                    return 0;
+                }
+                else {
+                    /* still active connections, reset time_last_rqst */
+                    time_last_rqst = now;
+                }
+            }
         } else {
             /* We got a request */
             time_last_rqst = now;