3 * This generates a list of active users for the prlogger
5 * (c) Copyright 1990 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
13 #include <moira_site.h>
14 #include <sys/types.h>
17 EXEC SQL INCLUDE sqlca;
20 char *whoami = "prlogger.gen";
28 char *outf = NULL, outft[64];
31 EXEC SQL BEGIN DECLARE SECTION;
32 char login[9], class[9];
33 EXEC SQL END DECLARE SECTION;
36 EXEC SQL CONNECT moira;
39 EXEC SQL DATABASE moira;
43 if (stat(argv[1], &sb) == 0) {
44 if (ModDiff (&flag, "users", sb.st_mtime))
47 fprintf(stderr, "File %s does not need to be rebuilt.\n",
53 sprintf(outft, "%s~", outf);
54 if ((out = fopen(outft, "w")) == NULL) {
55 fprintf(stderr, "unable to open %s for output\n", outf);
58 } else if (argc != 1) {
59 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
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.
69 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
71 EXEC SQL DECLARE x CURSOR FOR
72 SELECT login, affiliation FROM users WHERE status = 1;
75 EXEC SQL FETCH x INTO :login, :class;
76 if (sqlca.sqlcode != 0) break;
79 fprintf(out, "%s %s\n", login, class);
87 EXEC SQL CLOSE DATABASE;
91 perror("close failed");
99 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
100 critical_alert("DCM", "PrLogger build encountered INGRES ERROR %d",