1d48ff5e05c5f7f5a2bcb816b12cb9e04a3b7bc3
[citadel.git] / citadel / modules / checkpoint / serv_checkpoint.c
1 /*
2  * $Id: serv_checkpoint.c 5756 2007-11-16 17:15:22Z ajc $
3  *
4  * checkpointing module for the database
5  */
6  
7 #include "sysdep.h"
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <sys/types.h>
15 #include <sys/stat.h>
16 #include <dirent.h>
17
18 #ifdef HAVE_DB_H
19 #include <db.h>
20 #elif defined(HAVE_DB4_DB_H)
21 #include <db4/db.h>
22 #else
23 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
24 #endif
25
26
27 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
28 #error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
29 #endif
30
31 #include "citadel.h"
32 #include "server.h"
33 #include "citserver.h"
34 #include "database.h"
35 #include "msgbase.h"
36 #include "sysdep_decls.h"
37 #include "config.h"
38
39 #include "ctdl_module.h"
40  
41 /*
42  * Main loop for the checkpoint thread.
43  */
44 void *checkpoint_thread(void *arg) {
45         struct CitContext checkpointCC;
46
47         CtdlLogPrintf(CTDL_DEBUG, "checkpoint_thread() initializing\n");
48
49         memset(&checkpointCC, 0, sizeof(struct CitContext));
50         checkpointCC.internal_pgm = 1;
51         checkpointCC.cs_pid = 0;
52         pthread_setspecific(MyConKey, (void *)&checkpointCC );
53
54         while (!CtdlThreadCheckStop()) {
55                 cdb_checkpoint();
56                 CtdlThreadSleep(60);
57         }
58
59         CtdlLogPrintf(CTDL_DEBUG, "checkpoint_thread() exiting\n");
60         return NULL;
61 }
62
63
64 CTDL_MODULE_INIT(checkpoint) {
65         if (threading)
66         {
67                 CtdlThreadCreate ("checkpoint", CTDLTHREAD_BIGSTACK, checkpoint_thread, NULL);
68         }
69         /* return our Subversion id for the Log */
70         return "$Id: serv_autocompletion.c 5756 2007-11-16 17:15:22Z ajc $";
71 }