]> arthur.barton.de Git - netatalk.git/commitdiff
Add support for automatic logfile removal to cnid_dbd.
authorlenneis <lenneis>
Thu, 29 Apr 2004 18:09:14 +0000 (18:09 +0000)
committerlenneis <lenneis>
Thu, 29 Apr 2004 18:09:14 +0000 (18:09 +0000)
etc/cnid_dbd/db_param.c
etc/cnid_dbd/db_param.h
etc/cnid_dbd/dbif.c

index 83b277f3777ae50612f9b73225c422eda340f7dc..acba65aa192ec218b785855051bcbdf48673b94b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: db_param.c,v 1.1.4.3 2004-01-09 21:05:50 lenneis Exp $
+ * $Id: db_param.c,v 1.1.4.4 2004-04-29 18:09:14 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYING.
@@ -30,7 +30,7 @@
 #define DB_PARAM_FN       "db_param"
 #define MAXKEYLEN         64
 
-#define DEFAULT_BACKLOG            20   
+#define DEFAULT_LOGFILE_AUTOREMOVE 0   
 #define DEFAULT_CACHESIZE          1024 * 4 
 #define DEFAULT_NOSYNC             0    
 #define DEFAULT_FLUSH_FREQUENCY    100  
@@ -71,7 +71,7 @@ static int make_pathname(char *path, char *dir, char *fn, int maxlen)
 
 static void default_params(struct db_param *dbp, char *dir)
 {        
-    dbp->backlog             = DEFAULT_BACKLOG;
+    dbp->logfile_autoremove  = DEFAULT_LOGFILE_AUTOREMOVE;
     dbp->cachesize           = DEFAULT_CACHESIZE;
     dbp->nosync              = DEFAULT_NOSYNC;
     dbp->flush_frequency     = DEFAULT_FLUSH_FREQUENCY;
@@ -139,8 +139,8 @@ struct db_param *db_param_read(char *dir)
             break;
         }
         
-        if (! strcmp(key, "backlog")) 
-            params.backlog = parse_int(val);
+        if (! strcmp(key, "logfile_autoremove")) 
+            params.logfile_autoremove = parse_int(val);
         else if (! strcmp(key, "cachesize"))
             params.cachesize = parse_int(val);
         else if (! strcmp(key, "nosync"))
index 6a3c7151f1101a0a55c1c4bdcfd4e3130108ea4b..15e055dab64276382c29f35d434f03b44cd29a6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: db_param.h,v 1.1.4.3 2004-01-09 21:05:50 lenneis Exp $
+ * $Id: db_param.h,v 1.1.4.4 2004-04-29 18:09:16 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYING.
@@ -13,7 +13,7 @@
 
 
 struct db_param {
-    int backlog;
+    int logfile_autoremove;
     int cachesize;
     int nosync;
     int flush_frequency;
index 34e206aa9264d6b059614d0664eb59ff2f08c513..4518f2929b91507f0ec85972e7a0d34bdb687571 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbif.c,v 1.1.4.14 2004-02-07 18:45:46 didg Exp $
+ * $Id: dbif.c,v 1.1.4.15 2004-04-29 18:09:16 lenneis Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYING.
@@ -138,6 +138,10 @@ int dbif_stamp(void *buffer, int size)
 int dbif_env_init(struct db_param *dbp)
 {
     int ret;
+#ifdef CNID_BACKEND_DBD_TXN
+    char **logfiles = NULL;
+    char **file;
+#endif
 
     /* Refuse to do anything if this is an old version of the CNID database */
     if (upgrade_required()) {
@@ -207,7 +211,21 @@ int dbif_env_init(struct db_param *dbp)
             db_strerror(ret));
         db_env->close(db_env, 0);
         db_env = NULL;
-        return -1;      
+        return -1;
+    }
+    if (dbp->logfile_autoremove && db_env->log_archive(db_env, &logfiles, 0)) {
+       LOG(log_error, logtype_cnid, "error getting list of stale logfiles: %s",
+            db_strerror(ret));
+        db_env->close(db_env, 0);
+        db_env = NULL;
+        return -1;
+    }
+    if (logfiles != NULL) {
+       for (file = logfiles; *file != NULL; file++) {
+           if (unlink(*file) < 0)
+               LOG(log_warning, logtype_cnid, "Error removing stale logfile %s: %s", *file, strerror(errno));
+       }
+       free(logfiles);
     }
 #endif
     return 0;