]> andersk Git - moira.git/commitdiff
Initial revision
authormar <mar>
Fri, 4 Oct 1991 15:30:06 +0000 (15:30 +0000)
committermar <mar>
Fri, 4 Oct 1991 15:30:06 +0000 (15:30 +0000)
gen/stats.dc [new file with mode: 0644]

diff --git a/gen/stats.dc b/gen/stats.dc
new file mode 100644 (file)
index 0000000..4e8dd9a
--- /dev/null
@@ -0,0 +1,118 @@
+/* $Header$
+ *
+ * This generates a list of how many lockers are on each NFS server
+ * for statistics gathering purposes.
+ *
+ *  (c) Copyright 1991 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 <moira.h>
+#include <moira_site.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <strings.h>
+EXEC SQL INCLUDE sqlca;
+
+extern int errno;
+char *whoami = "stats.gen";
+
+
+main(argc, argv)
+int argc;
+char **argv;
+{
+    FILE *out = stdout;
+    char *outf = NULL, outft[64];
+    struct stat sb;
+    int flag1, flag2, flag3;
+    struct hash *machines;
+    EXEC SQL BEGIN DECLARE SECTION;
+    char name[257];
+    int n, id;
+    EXEC SQL END DECLARE SECTION;
+
+#ifsql INGRES
+    EXEC SQL CONNECT sms;
+#endsql
+#ifsql INFORMIX
+    EXEC SQL DATABASE sms;
+#endsql
+
+    if (argc == 2) {
+       if (stat(argv[1], &sb) == 0) {
+           if (ModDiff (&flag1, "machine", sb.st_mtime) == 0 &&
+               ModDiff (&flag2, "filesys", sb.st_mtime) == 0 &&
+               ModDiff (&flag3, "nfsphys", sb.st_mtime) == 0 &&
+               flag1 < 0 && flag2 < 0 && flag3 < 0) {
+               fprintf(stderr, "File %s does not need to be rebuilt.\n",
+                       argv[1]);
+               exit(MR_NO_CHANGE);
+           }
+       }
+       outf = argv[1];
+       sprintf(outft, "%s~", outf);
+       if ((out = fopen(outft, "w")) == NULL) {
+           fprintf(stderr, "unable to open %s for output\n", outf);
+           exit(MR_OCONFIG);
+       }
+    } else if (argc != 1) {
+       fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
+       exit(MR_ARGS);
+    } else {
+       outf = NULL;
+    }
+
+    EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
+
+    machines = create_hash(1000);
+
+    EXEC SQL DECLARE m CURSOR FOR 
+      SELECT mach_id, name 
+       FROM machine;
+    EXEC SQL OPEN m;
+    while (1) {
+      EXEC SQL FETCH m INTO :id, :name;
+      if (sqlca.sqlcode != 0) break;
+      hash_store(machines, id, strsave(name));
+    }
+    EXEC SQL CLOSE m;
+
+    EXEC SQL DECLARE x CURSOR FOR
+      SELECT DISTINCT f.mach_id, count(f.filsys_id)
+      FROM filesys f
+       WHERE f.type="NFS"
+      GROUP BY f.mach_id;
+    EXEC SQL OPEN x;
+    while (1) {
+       EXEC SQL FETCH x INTO :id, :n;
+       if (sqlca.sqlcode != 0) break;
+       fprintf(out, "%s %d\n", hash_lookup(machines, id), n);
+    }
+    EXEC SQL CLOSE x;
+
+#ifsql INGRES
+    EXEC SQL DISCONNECT;
+#endsql
+#ifsql INFORMIX
+    EXEC SQL CLOSE DATABASE;
+#endsql
+
+    if (fclose(out)) {
+       perror("close failed");
+       exit(MR_CCONFIG);
+    }
+    if (outf)
+      fix_file(outf);
+    exit(MR_SUCCESS);
+
+ sqlerr:
+    com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
+    critical_alert("DCM", "Central America build encountered INGRES ERROR %d",
+                  sqlca.sqlcode);
+    exit(MR_INGRES_ERR);
+}
This page took 0.04463 seconds and 5 git commands to generate.