]> andersk Git - moira.git/blame - gen/stats.dc
get proper version of name
[moira.git] / gen / stats.dc
CommitLineData
0966656e 1/* $Header$
2 *
3 * This generates a list of how many lockers are on each NFS server
4 * for statistics gathering purposes.
5 *
6 * (c) Copyright 1991 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 */
10
11#include <mit-copyright.h>
12#include <stdio.h>
13#include <moira.h>
14#include <moira_site.h>
15#include <sys/types.h>
16#include <sys/stat.h>
17#include <sys/time.h>
18#include <strings.h>
19EXEC SQL INCLUDE sqlca;
20
21extern int errno;
22char *whoami = "stats.gen";
23
24
25main(argc, argv)
26int argc;
27char **argv;
28{
29 FILE *out = stdout;
30 char *outf = NULL, outft[64];
31 struct stat sb;
32 int flag1, flag2, flag3;
33 struct hash *machines;
34 EXEC SQL BEGIN DECLARE SECTION;
35 char name[257];
36 int n, id;
37 EXEC SQL END DECLARE SECTION;
38
39#ifsql INGRES
40 EXEC SQL CONNECT sms;
41#endsql
42#ifsql INFORMIX
43 EXEC SQL DATABASE sms;
44#endsql
45
46 if (argc == 2) {
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",
53 argv[1]);
54 exit(MR_NO_CHANGE);
55 }
56 }
57 outf = argv[1];
58 sprintf(outft, "%s~", outf);
59 if ((out = fopen(outft, "w")) == NULL) {
60 fprintf(stderr, "unable to open %s for output\n", outf);
61 exit(MR_OCONFIG);
62 }
63 } else if (argc != 1) {
64 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
65 exit(MR_ARGS);
66 } else {
67 outf = NULL;
68 }
69
70 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
71
72 machines = create_hash(1000);
73
74 EXEC SQL DECLARE m CURSOR FOR
75 SELECT mach_id, name
76 FROM machine;
77 EXEC SQL OPEN m;
78 while (1) {
79 EXEC SQL FETCH m INTO :id, :name;
80 if (sqlca.sqlcode != 0) break;
81 hash_store(machines, id, strsave(name));
82 }
83 EXEC SQL CLOSE m;
84
85 EXEC SQL DECLARE x CURSOR FOR
86 SELECT DISTINCT f.mach_id, count(f.filsys_id)
87 FROM filesys f
88 WHERE f.type="NFS"
89 GROUP BY f.mach_id;
90 EXEC SQL OPEN x;
91 while (1) {
92 EXEC SQL FETCH x INTO :id, :n;
93 if (sqlca.sqlcode != 0) break;
94 fprintf(out, "%s %d\n", hash_lookup(machines, id), n);
95 }
96 EXEC SQL CLOSE x;
97
98#ifsql INGRES
99 EXEC SQL DISCONNECT;
100#endsql
101#ifsql INFORMIX
102 EXEC SQL CLOSE DATABASE;
103#endsql
104
105 if (fclose(out)) {
106 perror("close failed");
107 exit(MR_CCONFIG);
108 }
109 if (outf)
110 fix_file(outf);
111 exit(MR_SUCCESS);
112
113 sqlerr:
114 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
115 critical_alert("DCM", "Central America build encountered INGRES ERROR %d",
116 sqlca.sqlcode);
117 exit(MR_INGRES_ERR);
118}
This page took 0.063293 seconds and 5 git commands to generate.