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;
43 EXEC SQL DATABASE moira;
47 if (stat(argv[1], &sb) == 0) {
48 if (ModDiff (&flag1, "machine", sb.st_mtime) == 0 &&
49 ModDiff (&flag2, "filesys", sb.st_mtime) == 0 &&
50 ModDiff (&flag3, "nfsphys", sb.st_mtime) == 0 &&
51 flag1 < 0 && flag2 < 0 && flag3 < 0) {
52 fprintf(stderr, "File %s does not need to be rebuilt.\n",
58 sprintf(outft, "%s~", outf);
59 if ((out = fopen(outft, "w")) == NULL) {
60 fprintf(stderr, "unable to open %s for output\n", outf);
63 } else if (argc != 1) {
64 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
70 /* The following is declarative, not executed,
71 * and so is dependent on where it is in the file,
72 * not in the order of execution of statements.
74 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
76 machines = create_hash(1000);
78 EXEC SQL DECLARE m CURSOR FOR
83 EXEC SQL FETCH m INTO :id, :name;
84 if (sqlca.sqlcode != 0) break;
85 hash_store(machines, id, strsave(name));
89 EXEC SQL DECLARE x CURSOR FOR
90 SELECT DISTINCT f.mach_id, count(f.filsys_id)
96 EXEC SQL FETCH x INTO :id, :n;
97 if (sqlca.sqlcode != 0) break;
98 fprintf(out, "%s %d\n", hash_lookup(machines, id), n);
106 EXEC SQL CLOSE DATABASE;
110 perror("close failed");
118 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
119 critical_alert("DCM", "Central America build encountered INGRES ERROR %d",