3 * This generates a list of how many lockers are on each NFS server
4 * for statistics gathering purposes.
6 * (c) Copyright 1991 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
11 #include <mit-copyright.h>
14 #include <moira_site.h>
15 #include <sys/types.h>
19 EXEC SQL INCLUDE sqlca;
22 char *whoami = "stats.gen";
30 char *outf = NULL, outft[64];
32 int flag1, flag2, flag3;
33 struct hash *machines;
34 EXEC SQL BEGIN DECLARE SECTION;
37 EXEC SQL END DECLARE SECTION;
40 EXEC SQL CONNECT moira;
41 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
44 EXEC SQL DATABASE moira;
48 if (stat(argv[1], &sb) == 0) {
49 if (ModDiff (&flag1, "machine", sb.st_mtime) == 0 &&
50 ModDiff (&flag2, "filesys", sb.st_mtime) == 0 &&
51 ModDiff (&flag3, "nfsphys", sb.st_mtime) == 0 &&
52 flag1 < 0 && flag2 < 0 && flag3 < 0) {
53 fprintf(stderr, "File %s does not need to be rebuilt.\n",
59 sprintf(outft, "%s~", outf);
60 if ((out = fopen(outft, "w")) == NULL) {
61 fprintf(stderr, "unable to open %s for output\n", outf);
64 } else if (argc != 1) {
65 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
71 /* The following is declarative, not executed,
72 * and so is dependent on where it is in the file,
73 * not in the order of execution of statements.
75 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
77 machines = create_hash(1000);
79 EXEC SQL DECLARE m CURSOR FOR
84 EXEC SQL FETCH m INTO :id, :name;
85 if (sqlca.sqlcode != 0) break;
86 hash_store(machines, id, strsave(name));
90 EXEC SQL DECLARE x CURSOR FOR
91 SELECT DISTINCT f.mach_id, count(f.filsys_id)
97 EXEC SQL FETCH x INTO :id, :n;
98 if (sqlca.sqlcode != 0) break;
99 fprintf(out, "%-32s %d\n", hash_lookup(machines, id), n);
107 EXEC SQL CLOSE DATABASE;
111 perror("close failed");
119 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
120 critical_alert("DCM", "Central America build encountered INGRES ERROR %d",