]> andersk Git - moira.git/blob - dbck/dbck.qc
changed exit/cleanup code, interrupt handler, & added tblstat modtime
[moira.git] / dbck / dbck.qc
1 /* $Header$
2  *
3  * SMS database consistency checker
4  *
5  *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
6  *  For copying and distribution information, please see the file
7  *  <mit-copyright.h>.
8  */
9
10 #include <mit-copyright.h>
11 #include <stdio.h>
12 #include <strings.h>
13 #include <signal.h>
14 #include "dbck.h"
15
16
17 static char dbck_qc_rcsid[] = "$Header$";
18
19
20 int debug = 1;
21 int mode = MODE_ASK;
22 int fast = 0;
23 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys, *strings;
24 ##int dcmenable;
25 struct save_queue *modtables;
26 int interrupt();
27
28
29 main(argc, argv)
30 int argc;
31 char **argv;
32 {
33     char **arg = argv;
34 ##  char *database;
35     int ingerr();
36     int countonly = 0;
37
38     database = "sms";
39
40     while (++arg - argv < argc) {
41         if  (**arg == '-')
42           switch ((*arg)[1]) {
43           case 'd':
44               debug = atoi((*arg)[2] ? *arg+2 : *++arg);
45               break;
46           case 'n':
47               mode = MODE_NO;
48               break;
49           case 'y':
50               mode = MODE_YES;
51               break;
52           case 'p':
53               mode = MODE_PREEN;
54               break;
55           case 'a':
56               mode = MODE_ASK;
57               break;
58           case 'c':
59               countonly++;
60               break;
61           case 'f':
62               fast++;
63               break;
64           }
65         else
66           database = *arg;
67     }
68     if (countonly)
69       printf("Only doing counts\n");
70     else if (fast)
71       printf("Doing fast version (skipping some checks)\n");
72     if (mode == MODE_NO)
73       printf("Will NOT modify the database\n");
74     else if (mode == MODE_PREEN)
75       printf("Will fix simple things without asking\n");
76     else if (mode == MODE_YES)
77       printf("Will fix everything without asking\n");
78     if (debug)
79       printf("Debug level is %d\n", debug);
80
81     signal(SIGHUP, interrupt);
82     signal(SIGQUIT, interrupt);
83     signal(SIGINT, interrupt);
84     modtables = sq_create();
85
86     IIseterr(ingerr);
87     printf("Opening database %s...", database);
88     fflush(stdout);
89 ##  ingres database
90     printf("done\n");
91 ##  retrieve (dcmenable = values.value) where values.name = "dcm_enable"
92     dprintf("DCM disabled (was %d)\n", dcmenable);
93 ##  replace values (value = 0) where values.name = "dcm_enable"
94
95 ##  begin transaction
96
97     if (!countonly) {
98         phase1();
99         phase2();
100         phase3();
101     } else {
102         count_only_setup();
103     }
104     phase4();
105
106 ##  end transaction
107     cleanup();
108     printf("Done.\n");
109     exit(0);
110 }
111
112 ingerr(num)
113 int     *num;
114 {
115     printf("An ingres error occuurred, code %d\n", *num);
116     printf("Aborting...\n");
117 ##  abort
118     exit(1);
119 }
120
121
122 int interrupt()
123 ##{
124     printf("Signal caught\n");
125     if (prompt("Save database changes")) {
126 ##      end transaction
127         cleanup();
128         exit(0);
129     }
130     printf("Aborting transaction\n");
131 ##  abort
132 ##  replace values (value = dcmenable) where values.name = "dcm_enable"
133 ##  exit
134     exit(0);
135 ##}
136
137
138 modified(table)
139 char *table;
140 {
141     sq_save_unique_string(modtables, table);
142 }
143
144 cleanup()
145 ##{
146 ##  char *tab;
147
148     while (sq_get_data(modtables, &tab)) {
149 ##      replace tblstats (modtime = "now") where tblstats.table = tab
150     }
151 ##  replace values (value = dcmenable) where values.name = "dcm_enable"
152 ##  exit
153 ##}
This page took 0.046841 seconds and 5 git commands to generate.