]>
Commit | Line | Data |
---|---|---|
f6b24974 | 1 | /* $Header$ |
2 | * | |
3 | * This generates a list of active users for the prlogger | |
4 | * | |
5 | * (c) Copyright 1990 by the Massachusetts Institute of Technology. | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
8 | */ | |
9 | ||
10 | #include <mit-copyright.h> | |
11 | #include <stdio.h> | |
12 | #include <moira.h> | |
13 | #include <moira_site.h> | |
14 | #include <sys/types.h> | |
15 | #include <sys/stat.h> | |
16 | #include <sys/time.h> | |
17 | EXEC SQL INCLUDE sqlca; | |
18 | ||
19 | extern int errno; | |
20 | char *whoami = "prlogger.gen"; | |
21 | ||
22 | ||
23 | main(argc, argv) | |
24 | int argc; | |
25 | char **argv; | |
26 | { | |
27 | FILE *out = stdout; | |
28 | char *outf = NULL, outft[64]; | |
29 | struct stat sb; | |
30 | int flag; | |
31 | EXEC SQL BEGIN DECLARE SECTION; | |
32 | char login[9], class[9]; | |
33 | EXEC SQL END DECLARE SECTION; | |
34 | ||
35 | #ifsql INGRES | |
9fd1c2b8 | 36 | EXEC SQL CONNECT moira; |
f6b24974 | 37 | #endsql |
38 | #ifsql INFORMIX | |
9fd1c2b8 | 39 | EXEC SQL DATABASE moira; |
f6b24974 | 40 | #endsql |
41 | ||
42 | if (argc == 2) { | |
43 | if (stat(argv[1], &sb) == 0) { | |
44 | if (ModDiff (&flag, "users", sb.st_mtime)) | |
45 | exit(MR_DATE); | |
46 | if (flag < 0) { | |
47 | fprintf(stderr, "File %s does not need to be rebuilt.\n", | |
48 | argv[1]); | |
49 | exit(MR_NO_CHANGE); | |
50 | } | |
51 | } | |
52 | outf = argv[1]; | |
53 | sprintf(outft, "%s~", outf); | |
54 | if ((out = fopen(outft, "w")) == NULL) { | |
55 | fprintf(stderr, "unable to open %s for output\n", outf); | |
56 | exit(MR_OCONFIG); | |
57 | } | |
58 | } else if (argc != 1) { | |
59 | fprintf(stderr, "usage: %s [outfile]\n", argv[0]); | |
60 | exit(MR_ARGS); | |
61 | } else { | |
62 | outf = NULL; | |
63 | } | |
64 | ||
9fd1c2b8 | 65 | /* The following is declarative, not executed, |
66 | * and so is dependent on where it is in the file, | |
67 | * not in the order of execution of statements. | |
68 | */ | |
f6b24974 | 69 | EXEC SQL WHENEVER SQLERROR GOTO sqlerr; |
70 | ||
71 | EXEC SQL DECLARE x CURSOR FOR | |
9fd1c2b8 | 72 | SELECT login, affiliation FROM users WHERE status = 1; |
f6b24974 | 73 | EXEC SQL OPEN x; |
74 | while (1) { | |
75 | EXEC SQL FETCH x INTO :login, :class; | |
76 | if (sqlca.sqlcode != 0) break; | |
77 | strtrim(login); | |
78 | strtrim(class); | |
79 | fprintf(out, "%s %s\n", login, class); | |
80 | } | |
81 | EXEC SQL CLOSE x; | |
82 | ||
83 | #ifsql INGRES | |
84 | EXEC SQL DISCONNECT; | |
85 | #endsql | |
86 | #ifsql INFORMIX | |
87 | EXEC SQL CLOSE DATABASE; | |
88 | #endsql | |
89 | ||
90 | if (fclose(out)) { | |
91 | perror("close failed"); | |
92 | exit(MR_CCONFIG); | |
93 | } | |
94 | if (outf) | |
95 | fix_file(outf); | |
96 | exit(MR_SUCCESS); | |
97 | ||
98 | sqlerr: | |
99 | com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode); | |
100 | critical_alert("DCM", "PrLogger build encountered INGRES ERROR %d", | |
101 | sqlca.sqlcode); | |
102 | exit(MR_INGRES_ERR); | |
103 | } |