~ubuntu-branches/ubuntu/precise/netatalk/precise

« back to all changes in this revision

Viewing changes to libatalk/cnid/cnid_close.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Rittau
  • Date: 2004-01-19 12:43:49 UTC
  • Revision ID: james.westby@ubuntu.com-20040119124349-es563jbp0hk0ae51
Tags: upstream-1.6.4
ImportĀ upstreamĀ versionĀ 1.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: cnid_close.c,v 1.25.2.2 2003/03/19 11:50:18 didg Exp $
 
3
 */
 
4
 
 
5
#ifdef HAVE_CONFIG_H
 
6
#include "config.h"
 
7
#endif /* HAVE_CONFIG_H */
 
8
 
 
9
#ifdef CNID_DB
 
10
#ifdef HAVE_UNISTD_H
 
11
#include <unistd.h>
 
12
#endif /* HAVE_UNISTD_H */
 
13
#ifdef HAVE_FCNTL_H
 
14
#include <fcntl.h>
 
15
#endif /* HAVE_FCNTL_H */
 
16
#include <stdlib.h>
 
17
#include <atalk/logger.h>
 
18
#include <db.h>
 
19
#include <errno.h>
 
20
#include <string.h>
 
21
 
 
22
#include "cnid_private.h"
 
23
#include <atalk/cnid.h>
 
24
 
 
25
void cnid_close(void *CNID) {
 
26
    CNID_private *db;
 
27
    int rc;
 
28
 
 
29
    if (!(db = CNID)) {
 
30
        return;
 
31
    }
 
32
 
 
33
#ifndef CNID_DB_CDB
 
34
    /* Flush the transaction log and delete the log file if we can. */
 
35
    if ((db->lockfd > -1) && ((db->flags & CNIDFLAG_DB_RO) == 0)) {
 
36
        struct flock lock;
 
37
 
 
38
    lock.l_type = F_WRLCK;
 
39
    lock.l_whence = SEEK_SET;
 
40
    lock.l_start = lock.l_len = 0;
 
41
    if (fcntl(db->lockfd, F_SETLK, &lock) == 0) {
 
42
            char **list, **first;
 
43
 
 
44
 
 
45
            /* Checkpoint the databases until we can checkpoint no
 
46
             * more. */
 
47
#if DB_VERSION_MAJOR >= 4
 
48
#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1
 
49
            db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
 
50
#else
 
51
            rc = db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
 
52
#endif /* DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1 */
 
53
#else
 
54
            rc = txn_checkpoint(db->dbenv, 0, 0, 0);
 
55
#endif /* DB_VERSION_MAJOR >= 4 */
 
56
#if DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1)
 
57
            while (rc == DB_INCOMPLETE) {
 
58
#if DB_VERSION_MAJOR >= 4
 
59
                rc = db->dbenv->txn_checkpoint(db->dbenv, 0, 0, 0);
 
60
#else
 
61
                rc = txn_checkpoint(db->dbenv, 0, 0, 0);
 
62
#endif /* DB_VERSION_MAJOR >= 4 */
 
63
            }
 
64
#endif /* DB_VERSION_MAJOR < 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 1) */
 
65
 
 
66
#if DB_VERSION_MAJOR >= 4
 
67
            if ((rc = db->dbenv->log_archive(db->dbenv, &list, DB_ARCH_ABS)) != 0) {
 
68
#elif DB_VERSION_MINOR > 2
 
69
            if ((rc = log_archive(db->dbenv, &list, DB_ARCH_ABS)) != 0) {
 
70
#else /* DB_VERSION_MINOR < 2 */
 
71
            if ((rc = log_archive(db->dbenv, &list, DB_ARCH_ABS, NULL)) != 0) {
 
72
#endif /* DB_VERSION_MINOR */
 
73
                LOG(log_error, logtype_default, "cnid_close: Unable to archive logfiles: %s", db_strerror(rc));
 
74
            }
 
75
 
 
76
            if (list != NULL) {
 
77
                for (first = list; *list != NULL; ++list) {
 
78
                    if ((rc = remove(*list)) != 0) {
 
79
#ifdef DEBUG
 
80
                            LOG(log_info, logtype_default, "cnid_close: failed to remove %s: %s", *list, strerror(rc));
 
81
#endif
 
82
                        }
 
83
                }
 
84
                free(first);
 
85
            }
 
86
        }
 
87
        (void)remove(db->lock_file);
 
88
    }
 
89
#endif /* CNID_DB_CDB */
 
90
 
 
91
    db->db_didname->close(db->db_didname, 0);
 
92
    db->db_devino->close(db->db_devino, 0);
 
93
    db->db_cnid->close(db->db_cnid, 0);
 
94
#ifdef FILE_MANGLING
 
95
    db->db_mangle->close(db->db_mangle, 0);
 
96
#endif /* FILE_MANGLING */
 
97
    db->dbenv->close(db->dbenv, 0);
 
98
 
 
99
#ifndef CNID_DB_CDB
 
100
    if (db->lockfd > -1) {
 
101
        close(db->lockfd); /* This will also release any locks we have. */
 
102
    }
 
103
#endif /* CNID_DB_CDB */
 
104
 
 
105
    free(db);
 
106
}
 
107
#endif /* CNID_DB */