More removal of $Id$ tags
[citadel.git] / citadel / modules / checkpoint / serv_checkpoint.c
1 /*
2  * checkpointing module for the database
3  *
4  * Copyright (c) 1987-2009 by the citadel.org team
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  
21 #include "sysdep.h"
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <stdio.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <dirent.h>
31
32 #ifdef HAVE_DB_H
33 #include <db.h>
34 #elif defined(HAVE_DB4_DB_H)
35 #include <db4/db.h>
36 #else
37 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
38 #endif
39
40
41 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
42 #error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
43 #endif
44
45 #include <libcitadel.h>
46
47 #include "citadel.h"
48 #include "server.h"
49 #include "citserver.h"
50 #include "database.h"
51 #include "msgbase.h"
52 #include "sysdep_decls.h"
53 #include "config.h"
54 #include "threads.h"
55
56 #include "ctdl_module.h"
57 #include "context.h"
58  
59 /*
60  * Main loop for the checkpoint thread.
61  */
62 void *checkpoint_thread(void *arg) {
63         struct CitContext checkpointCC;
64
65
66         CtdlFillSystemContext(&checkpointCC, "checkpoint");
67         citthread_setspecific(MyConKey, (void *)&checkpointCC );
68
69         CtdlLogPrintf(CTDL_DEBUG, "checkpoint_thread() initializing\n");
70         while (!CtdlThreadCheckStop()) {
71                 cdb_checkpoint();
72                 CtdlThreadSleep(60);
73         }
74
75         CtdlLogPrintf(CTDL_DEBUG, "checkpoint_thread() exiting\n");
76         CtdlClearSystemContext();
77         return NULL;
78 }
79
80
81 CTDL_MODULE_INIT(checkpoint) {
82         if (threading)
83         {
84                 CtdlThreadCreate ("checkpoint", CTDLTHREAD_BIGSTACK, checkpoint_thread, NULL);
85         }
86         /* return our Subversion id for the Log */
87         return "checkpoint";
88 }