dbnothing: temporary utility that just opens and closes the database as a test
[citadel.git] / citadel / utils / dbnothing.c
1 // Don't run this.  It doesn't work and if you try to run it you will immediately die.
2 //
3 // Copyright (c) 2023 by Art Cancro citadel.org
4 //
5 // This program is open source software.  Use, duplication, or disclosure
6 // is subject to the terms of the GNU General Public License, version 3.
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 #include <stdio.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <sys/un.h>
16 #include <netdb.h>
17 #include <string.h>
18 #include <pwd.h>
19 #include <errno.h>
20 #include <stdarg.h>
21 #include <limits.h>
22 #include <syslog.h>
23 #include <libcitadel.h>
24 #include <zlib.h>
25 #include "../server/sysdep.h"
26 #include "../server/citadel_defs.h"
27 #include "../server/server.h"
28 #include "../server/citadel_dirs.h"
29 #include "../server/database.h"
30
31 uid_t ctdluid = 0;
32
33
34 int main(int argc, char **argv) {
35         int i = 0;
36         int confirmed = 0;
37         char *ctdldir = CTDLDIR;
38
39         // display the greeting
40         fprintf(stderr, "\033[44m\033[33m\033[1m \033[K\033[0m\n"
41                         "\033[44m\033[33m\033[1m dbnothing utility for Citadel \033[K\033[0m\n"
42                         "\033[44m\033[33m\033[1m Copyright (c) 2023 by citadel.org et al.  \033[K\033[0m\n"
43                         "\033[44m\033[33m\033[1m This program is open source software.  Use, duplication, or disclosure \033[K\033[0m\n"
44                         "\033[44m\033[33m\033[1m is subject to the terms of the GNU General Public license v3. \033[K\033[0m\n"
45                         "\033[44m\033[33m\033[1m \033[K\033[0m\n");
46
47         // Parse command line
48         int a;
49         while ((a = getopt(argc, argv, "h:y")) != EOF) {
50                 switch (a) {
51                 case 'h':
52                         ctdldir = optarg;
53                         break;
54                 default:
55                         fprintf(stderr, "%s: usage: %s -s citadel_dir [>dumpfile]\n", argv[0], argv[0]);
56                         exit(2);
57                 }
58         }
59
60         if (chdir(ctdldir) != 0) {
61                 fprintf(stderr, "ctdlload: unable to change directory to [%s]: %m", ctdldir);
62                 exit(2);
63         }
64
65         // backend modules use syslog -- redirect to stderr
66         openlog("dbnothing", LOG_PERROR , LOG_DAEMON);
67
68         // initialize the database backend
69         cdb_init_backends();
70         cdb_open_databases();
71
72         // do nothing
73         fprintf(stderr, "dbnothing: doing nothing\n");
74
75         // close databases
76         cdb_close_databases();
77
78         fprintf(stderr, "dbnothing: \033[32m\033[1mfinished\033[0m\n");
79         exit(0);
80 }