]> arthur.barton.de Git - netatalk.git/commitdiff
Fix regression in cnid_metad.c: respawn throttling was not working anymore.
authorfranklahm <franklahm>
Mon, 18 May 2009 09:54:14 +0000 (09:54 +0000)
committerfranklahm <franklahm>
Mon, 18 May 2009 09:54:14 +0000 (09:54 +0000)
Hopefully fix all remaing absolute/relative pathname issues in dbif.c.

etc/cnid_dbd/cnid_metad.c
etc/cnid_dbd/dbif.c

index daa70c641af14fc0c728c947dd35b0e4cc601f44..065e1db1d9a4b66c5a1a06b99289c94b1f6d3c68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: cnid_metad.c,v 1.8 2009-04-21 08:55:44 franklahm Exp $
+ * $Id: cnid_metad.c,v 1.9 2009-05-18 09:54:14 franklahm Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * All Rights Reserved.  See COPYING.
@@ -508,8 +508,6 @@ int main(int argc, char *argv[])
             for (i = 0; i < MAXVOLS; i++) {
                 if (srv[i].pid == pid) {
                     srv[i].pid = 0;
-                    free(srv[i].name);
-                    srv[i].name = NULL;
                     close(srv[i].control_fd);
                     break;
                 }
index ea378ad696c70b0e127e085412bb46c02f92a7eb..726c958087de06cec2c35eb877a3c6b6ddd3a3a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: dbif.c,v 1.10 2009-05-14 13:46:08 franklahm Exp $
+ * $Id: dbif.c,v 1.11 2009-05-18 09:54:14 franklahm Exp $
  *
  * Copyright (C) Joerg Lenneis 2003
  * Copyright (C) Frank Lahm 2009
@@ -112,17 +112,31 @@ DBD *dbif_init(const char *envhome, const char *filename)
     return dbd;
 }
 
-/* --------------- */
-/*
- *  We assume our current directory is already the BDB homedir. Otherwise
- *  opening the databases will not work as expected.
- */
+/* 
+   We must open the db_env with an absolute pathname, as `dbd` keeps chdir'ing, which
+   breaks e.g. bdb logfile-rotation with relative pathnames.
+   But still we use relative paths with upgrade_required() and the DB_ERRLOGFILE
+   in order to avoid creating absolute paths by copying. Both have no problem with
+   a relative path.
+*/
 int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
 {
-    int ret;
+    int ret, cwd;
     char **logfiles = NULL;
     char **file;
 
+    /* Remember cwd */
+    if ((cwd = open(".", O_RDONLY)) < 0) {
+        LOG(log_error, logtype_cnid, "error opening cwd: %s", strerror(errno));
+        return -1;
+    }
+
+    /* chdir to db_envhome. makes it easier checking for old db files and creating db_errlog file  */
+    if ((chdir(dbd->db_envhome)) != 0) {
+        LOG(log_error, logtype_cnid, "error chdiring to db_env '%s': %s", dbd->db_envhome, strerror(errno));        
+        return -1;
+    }
+
     /* Refuse to do anything if this is an old version of the CNID database */
     if (upgrade_required()) {
         LOG(log_error, logtype_cnid, "Found version 1 of the CNID database. Please upgrade to version 2");
@@ -132,6 +146,11 @@ int dbif_env_open(DBD *dbd, struct db_param *dbp, uint32_t dbenv_oflags)
     if ((dbd->db_errlog = fopen(DB_ERRLOGFILE, "a")) == NULL)
         LOG(log_warning, logtype_cnid, "error creating/opening DB errlogfile: %s", strerror(errno));
 
+    if ((fchdir(cwd)) != 0) {
+        LOG(log_error, logtype_cnid, "error chdiring back: %s", strerror(errno));        
+        return -1;
+    }
+
     if ((ret = db_env_create(&dbd->db_env, 0))) {
         LOG(log_error, logtype_cnid, "error creating DB environment: %s",
             db_strerror(ret));