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