]> arthur.barton.de Git - netatalk.git/blobdiff - etc/cnid_dbd/cnid_metad.c
remove pre ansi declarations
[netatalk.git] / etc / cnid_dbd / cnid_metad.c
index 065e1db1d9a4b66c5a1a06b99289c94b1f6d3c68..ecc5045d75fa7007306fffb959fb12a0be9b0ac0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_metad.c,v 1.9 2009-05-18 09:54:14 franklahm Exp $
+ * $Id: cnid_metad.c,v 1.15 2009-10-13 22:55:37 didg Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYING.
 #define WTERMSIG(status)      ((status) & 0x7f)
 #endif
 
-#ifdef ATACC
-#define fork aTaC_fork
-#endif
-
 /* functions for username and group */
 #include <pwd.h>
 #include <grp.h>
@@ -99,6 +95,7 @@
 #endif
 #endif
 
+#include <atalk/util.h>
 #include <atalk/logger.h>
 #include <atalk/cnid_dbd_private.h>
 
@@ -113,26 +110,24 @@ static int rqstfd;
 volatile sig_atomic_t alarmed = 0;
 
 #define MAXSPAWN   3                   /* Max times respawned in.. */
+#define TESTTIME   42                  /* this much seconds apfd client tries to  *
+                                        * to reconnect every 5 secondes, catch it */
 #define MAXVOLS    512
 #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 control_fd;               /* file descriptor to child cnid_dbd process */
 };
 
 static struct server srv[MAXVOLS];
 
 /* Default logging config: log to syslog with level log_note */
-static char *logconfig = "default log_note";
+static char logconfig[MAXPATHLEN + 21 + 1] = "default log_note";
 
 static struct server *test_usockfn(char *dir)
 {
@@ -228,11 +223,10 @@ static int maybe_start_dbd(char *dbdpn, char *dbdir, char *usockfn)
     if (!up) {
         /* find an empty slot */
         for (i = 0; i < MAXVOLS; i++) {
-            if ( !srv[i].pid ) {
+            if ( !srv[i].name ) {
                 up = &srv[i];
                 up->tm = t;
                 up->count = 0;
-                up->toofast = 0;
                 up->name = strdup(dbdir);
                 break;
             }
@@ -246,14 +240,23 @@ static int maybe_start_dbd(char *dbdpn, char *dbdir, char *usockfn)
         /* we have a slot but no process, check for respawn too fast */
         if ( (t < (up->tm + TESTTIME)) /* We're in the respawn time window */
              &&
-             (up->count > MAXSPAWN) ) /* ...and already tried to fork too often */
+             (up->count > MAXSPAWN) ) { /* ...and already tried to fork too often */
+            LOG(log_maxdebug, logtype_cnid, "maybe_start_dbd: respawn too fast just exiting");
             return -1; /* just exit, dont sleep, because we might have work to do for another client  */
-
-        if ( t >= (up->tm + TESTTIME) ) { /* "reset" timer and count */
-             up->count = 0;
-             up->tm = t;
+        }
+        if ( t >= (up->tm + TESTTIME) ) { /* drop slot */
+            LOG(log_maxdebug, logtype_cnid, "maybe_start_dbd: respawn window ended, dropping slot");
+            free(up->name);
+            up->name = NULL;
+            return -1; /* next time we'll try again with a new slot */
         }
         up->count++;
+        LOG(log_maxdebug, logtype_cnid, "maybe_start_dbd: respawn count now is: %u", up->count);
+        if (up->count > MAXSPAWN) {
+            /* We spawned too fast. From now until the first time we tried + TESTTIME seconds
+               we will just return -1 above */
+            LOG(log_maxdebug, logtype_cnid, "maybe_start_dbd: reached MAXSPAWN threshhold");
+        }
     }
 
     /* 
@@ -340,8 +343,7 @@ static int set_dbdir(char *dbdir, int len)
 }
 
 /* ------------------ */
-uid_t user_to_uid ( username )
-    char    *username;
+uid_t user_to_uid (char *username)
 {
     struct passwd *this_passwd;
 
@@ -360,8 +362,7 @@ uid_t user_to_uid ( username )
 }
 
 /* ------------------ */
-gid_t group_to_gid ( group )
-    char    *group;
+gid_t group_to_gid ( char *group)
 {
     struct group *this_group;
 
@@ -380,7 +381,7 @@ gid_t group_to_gid ( group )
 }
 
 /* ------------------ */
-void catch_alarm(int sig) {
+void catch_alarm(int sig _U_) {
     alarmed = 1;
 }
 
@@ -402,10 +403,12 @@ int main(int argc, char *argv[])
     int    err = 0;
     int    debug = 0;
     int    ret;
+    char   *loglevel = NULL;
+    char   *logfile  = NULL;
 
     set_processname("cnid_metad");
 
-    while (( cc = getopt( argc, argv, "ds:p:h:u:g:l:")) != -1 ) {
+    while (( cc = getopt( argc, argv, "ds:p:h:u:g:l:f:")) != -1 ) {
         switch (cc) {
         case 'd':
             debug = 1;
@@ -434,7 +437,10 @@ int main(int argc, char *argv[])
             dbdpn = strdup(optarg);
             break;
         case 'l':
-            logconfig = strdup(optarg);
+            loglevel = strdup(optarg);
+            break;
+        case 'f':
+            logfile = strdup(optarg);
             break;
         default:
             err++;
@@ -442,6 +448,15 @@ int main(int argc, char *argv[])
         }
     }
 
+    if (loglevel) {
+        strlcpy(logconfig + 8, loglevel, 13);
+        free(loglevel);
+        strcat(logconfig, " ");
+    }
+    if (logfile) {
+        strlcat(logconfig, logfile, MAXPATHLEN);
+        free(logfile);
+    }
     setuplog(logconfig);
 
     if (err) {