]> andersk Git - moira.git/blobdiff - dbck/dbck.pc
Correct offsets for both versions of gsnt.
[moira.git] / dbck / dbck.pc
index 7bdea4d9599a804f21a1ed8fee092683faeb4873..3f68472e922a34d87298ef708d0104479b29a70b 100644 (file)
@@ -1,22 +1,24 @@
-/* $Header$
+/* $Id$
  *
  * Moira database consistency checker
  *
- *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
- *  For copying and distribution information, please see the file
- *  <mit-copyright.h>.
+ * (c) Copyright 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
 #include <mit-copyright.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
+#include <moira.h>
 #include "dbck.h"
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+
 EXEC SQL INCLUDE sqlca;
 EXEC SQL INCLUDE sqlda;
 
-static char dbck_qc_rcsid[] = "$Header$";
-
+RCSID("$Header$");
 
 int debug = 0;
 int mode = MODE_ASK;
@@ -24,189 +26,191 @@ int fast = 0;
 int warn = 1;
 int abort_p = 0;
 struct hash *users, *machines, *clusters, *lists, *filesys, *nfsphys;
-struct hash *strings, *members, *subnets, *string_dups;
-EXEC SQL BEGIN DECLARE SECTION; 
+struct hash *strings, *members, *subnets, *string_dups, *printservers;
+EXEC SQL BEGIN DECLARE SECTION;
 int dcmenable;
-EXEC SQL END DECLARE SECTION; 
-struct save_queue *modtables, *sq_create();
-void interrupt();
+EXEC SQL END DECLARE SECTION;
+struct save_queue *modtables;
 SQLDA *mr_sqlda;
 
-extern SQLDA *sqlald(int,int,int);
+void interrupt(void);
+extern SQLDA *sqlald(int, int, int);
+extern void sqlglm(char *, unsigned int *, unsigned int *);
 
-main(argc, argv)
-int argc;
-char **argv;
+int main(int argc, char **argv)
 {
-    char **arg = argv;
-EXEC SQL BEGIN DECLARE SECTION; 
-    char *database;
-EXEC SQL END DECLARE SECTION; 
-    int ingerr();
-    int countonly = 0;
-
-    database = "moira";
-    setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
-
-    while (++arg - argv < argc) {
-       if  (**arg == '-')
-         switch ((*arg)[1]) {
-         case 'd':
-             debug = atoi((*arg)[2] ? *arg+2 : *++arg);
+  char **arg = argv;
+  EXEC SQL BEGIN DECLARE SECTION;
+  char *database;
+  EXEC SQL END DECLARE SECTION;
+  struct sigaction sa;
+
+  database = "moira";
+  setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
+
+  while (++arg - argv < argc)
+    {
+      if (**arg == '-')
+       {
+         switch ((*arg)[1])
+           {
+           case 'd':
+             debug = atoi((*arg)[2] ? *arg + 2 : *++arg);
              break;
-         case 'n':
+           case 'n':
              mode = MODE_NO;
              break;
-         case 'y':
+           case 'y':
              mode = MODE_YES;
              break;
-         case 'p':
+           case 'p':
              mode = MODE_PREEN;
              break;
-         case 'a':
+           case 'a':
              mode = MODE_ASK;
              break;
-         case 'c':
-             countonly++;
-             break;
-         case 'f':
+           case 'f':
              fast++;
              break;
-         case 'w':
+           case 'w':
              warn = 0;
              break;
-         default:
-             printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-c] [-f] [-w] [database]\n",
+           default:
+             printf("Usage: %s [-d level] [-n] [-y] [-p] [-a] [-f] [-w] [database]\n",
                     argv[0]);
              exit(1);
-         }
-       else
-         database = *arg;
+           }
+       }
+      else
+       database = *arg;
     }
-    if (countonly)
-      printf("Only doing counts\n");
-    else if (fast)
-      printf("Doing fast version (skipping some checks)\n");
-    if (mode == MODE_NO)
-      printf("Will NOT modify the database\n");
-    else if (mode == MODE_PREEN)
-      printf("Will fix simple things without asking\n");
-    else if (mode == MODE_YES)
-      printf("Will fix everything without asking\n");
-    if (debug)
-      printf("Debug level is %d\n", debug);
-
-    signal(SIGHUP, interrupt);
-    signal(SIGQUIT, interrupt);
-    signal(SIGINT, interrupt);
-
-    modtables = sq_create();
-    mr_sqlda = sqlald(1, 255, 0);
-
-    EXEC SQL WHENEVER SQLERROR DO dbmserr();
-    printf("Opening database %s...", database);
-    fflush(stdout);
-    EXEC SQL CONNECT :database IDENTIFIED BY :database;
-    printf("done\n");
-    EXEC SQL SELECT value INTO :dcmenable FROM numvalues 
-       WHERE name='dcm_enable'; 
-    dprintf("DCM disabled (was %d)\n", dcmenable);
-    EXEC SQL UPDATE numvalues SET value=0 WHERE name='dcm_enable';
-
-    /* Begin transaction here. */
-
-    if (!countonly) {
-       phase1();
-       EXEC SQL COMMIT WORK;
-       phase2();
-       EXEC SQL COMMIT WORK;
-       phase3();
-       EXEC SQL COMMIT WORK;
-    } else {
-       count_only_setup();
-       EXEC SQL COMMIT WORK;
+  if (fast)
+    printf("Doing fast version (skipping some checks)\n");
+  if (mode == MODE_NO)
+    printf("Will NOT modify the database\n");
+  else if (mode == MODE_PREEN)
+    printf("Will fix simple things without asking\n");
+  else if (mode == MODE_YES)
+    printf("Will fix everything without asking\n");
+  if (debug)
+    printf("Debug level is %d\n", debug);
+
+  sa.sa_handler = interrupt;
+  sa.sa_flags = 0;
+  sigemptyset(&sa.sa_mask);
+  sigaction(SIGHUP, &sa, NULL);
+  sigaction(SIGQUIT, &sa, NULL);
+  sigaction(SIGINT, &sa, NULL);
+
+  modtables = sq_create();
+  mr_sqlda = sqlald(1, 255, 0);
+
+  EXEC SQL WHENEVER SQLERROR DO dbmserr();
+  printf("Opening database %s...", database);
+  fflush(stdout);
+  EXEC SQL CONNECT :database IDENTIFIED BY :database;
+  printf("done\n");
+  if (mode != MODE_NO)
+    {
+      EXEC SQL SELECT value INTO :dcmenable FROM numvalues
+       WHERE name = 'dcm_enable';
+      dprintf("DCM disabled (was %d)\n", dcmenable);
+      EXEC SQL UPDATE numvalues SET value = 0 WHERE name = 'dcm_enable';
     }
-    phase4();
-    EXEC SQL COMMIT WORK;
 
-    cleanup();
-    printf("Done.\n");
-    exit(0);
+  /* Begin transaction here. */
+
+  phase1();
+  EXEC SQL COMMIT WORK;
+  phase2();
+  EXEC SQL COMMIT WORK;
+  phase3();
+  EXEC SQL COMMIT WORK;
+  phase4();
+  EXEC SQL COMMIT WORK;
+
+  cleanup();
+  printf("Done.\n");
+  exit(0);
 }
 
-dbmserr()
+void dbmserr(void)
 {
-EXEC SQL BEGIN DECLARE SECTION;
-    char buf[512];
-EXEC SQL END DECLARE SECTION;
-    int bufsize=256, msglength=0;
-
-    if (sqlca.sqlcode==1403) return;
-    printf("A DBMS error occurred, code %d\n", sqlca.sqlcode);
-    sqlglm(buf, &bufsize, &msglength);
-    buf[msglength]=0;
-    printf("%s\n", buf);
-    printf("Aborting...\n");
-    if (!abort_p) {
-       abort_p++;
-       EXEC SQL ROLLBACK WORK;
+  EXEC SQL BEGIN DECLARE SECTION;
+  char buf[256];
+  EXEC SQL END DECLARE SECTION;
+  int bufsize = 256, msglength = 0;
+
+  if (sqlca.sqlcode == 1403)
+    return;
+  printf("A DBMS error occurred, code %ld\n", sqlca.sqlcode);
+  sqlglm(buf, &bufsize, &msglength);
+  buf[msglength] = '\0';
+  printf("%s\n", buf);
+  printf("Aborting...\n");
+  if (!abort_p)
+    {
+      abort_p++;
+      EXEC SQL ROLLBACK WORK;
     }
-    exit(1);
+  exit(1);
 }
 
 
-void interrupt()
+void interrupt(void)
 {
-    printf("Signal caught\n");
-    if (prompt("Save database changes")) {
-       EXEC SQL COMMIT WORK;
-       cleanup();
-       exit(0);
+  printf("Signal caught\n");
+  if (prompt("Save database changes"))
+    {
+      EXEC SQL COMMIT WORK;
+      cleanup();
+      exit(0);
     }
-    printf("Aborting transaction\n");
-    if (!abort_p) {
-       abort_p++;
-       EXEC SQL ROLLBACK WORK;
+  printf("Aborting transaction\n");
+  if (!abort_p)
+    {
+      abort_p++;
+      EXEC SQL ROLLBACK WORK;
     }
 
-    EXEC SQL UPDATE numvalues SET value=:dcmenable
-       WHERE name='dcm_enable';
+  EXEC SQL UPDATE numvalues SET value = :dcmenable
+    WHERE name = 'dcm_enable';
 
-    exit(0);
+  exit(0);
 }
 
 
-modified(table)
-char *table;
+void modified(char *table)
 {
-    sq_save_unique_string(modtables, table);
+  sq_save_unique_string(modtables, table);
 }
 
-cleanup()
+void cleanup(void)
 {
-    EXEC SQL BEGIN DECLARE SECTION; 
-    char *tab;
-    EXEC SQL END DECLARE SECTION; 
-
-    while (sq_get_data(modtables, &tab)) {
-       EXEC SQL UPDATE tblstats SET modtime=SYSDATE
-           WHERE table_name = :tab;
+  EXEC SQL BEGIN DECLARE SECTION;
+  char *tab;
+  EXEC SQL END DECLARE SECTION;
+
+  while (sq_get_data(modtables, &tab))
+    {
+      EXEC SQL UPDATE tblstats SET modtime = SYSDATE
+       WHERE table_name = :tab;
     }
-    EXEC SQL UPDATE numvalues SET value = :dcmenable
-       WHERE name='dcm_enable';
+  EXEC SQL UPDATE numvalues SET value = :dcmenable
+    WHERE name = 'dcm_enable';
 }
 
 
-out_of_mem(msg)
-char *msg;
+void out_of_mem(char *msg)
 {
-    fprintf(stderr, "Out of memory while %s\n", msg);
-    if (prompt("Save database changes")) {
-       EXEC SQL COMMIT WORK;
-       cleanup();
-       exit(1);
+  fprintf(stderr, "Out of memory while %s\n", msg);
+  if (prompt("Save database changes"))
+    {
+      EXEC SQL COMMIT WORK;
+      cleanup();
+      exit(1);
     }
-    printf("Aborting transaction\n");
-    EXEC SQL ROLLBACK WORK;
-    exit(1);
+  printf("Aborting transaction\n");
+  EXEC SQL ROLLBACK WORK;
+  exit(1);
 }
This page took 0.046994 seconds and 4 git commands to generate.