]> andersk Git - moira.git/blame - gen/pobox.dc
add deadlock detection
[moira.git] / gen / pobox.dc
CommitLineData
c7fb2d10 1/* $Header$
2 *
3 * This generates a list of everyone's poboxes for the mitdir.
4 *
5 * (c) Copyright 1992 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 <sys/types.h>
14#include <sys/stat.h>
15#include <sys/time.h>
16#include <ctype.h>
17EXEC SQL INCLUDE sqlca;
18
19extern int errno;
20char *whoami = "pobox.gen";
21
22
23main(argc, argv)
24int argc;
25char **argv;
26{
27 FILE *out = stdout;
28 char *outf = NULL, outft[64];
29 struct stat sb;
30 int flag, i;
31 EXEC SQL BEGIN DECLARE SECTION;
32 char login[9], id[18], string[257];
33 EXEC SQL END DECLARE SECTION;
34
35#ifsql INGRES
968f523c 36 EXEC SQL CONNECT moira;
37 EXEC SQL SET LOCKMODE SESSION WHERE LEVEL=TABLE, READLOCK=SHARED;
c7fb2d10 38#endsql
39#ifsql INFORMIX
968f523c 40 EXEC SQL DATABASE moira;
c7fb2d10 41#endsql
42
43 if (argc == 2) {
44 if (stat(argv[1], &sb) == 0) {
45 if (ModDiff (&flag, "users", sb.st_mtime))
46 exit(MR_DATE);
47 if (flag < 0) {
48 fprintf(stderr, "File %s does not need to be rebuilt.\n",
49 argv[1]);
50 exit(MR_NO_CHANGE);
51 }
52 }
53 outf = argv[1];
54 sprintf(outft, "%s~", outf);
55 if ((out = fopen(outft, "w")) == NULL) {
56 fprintf(stderr, "unable to open %s for output\n", outf);
57 exit(MR_OCONFIG);
58 }
59 } else if (argc != 1) {
60 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
61 exit(MR_ARGS);
62 } else {
63 outf = NULL;
64 }
65
968f523c 66 /* The following is declarative, not executed,
67 * and so is dependent on where it is in the file,
68 * not in the order of execution of statements.
69 */
c7fb2d10 70 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
71
72 EXEC SQL DECLARE x CURSOR FOR SELECT
968f523c 73 clearid, login
74 FROM users WHERE status != 3 and potype='POP';
c7fb2d10 75 EXEC SQL OPEN x;
76 while (1) {
77 EXEC SQL FETCH x INTO :id, :login;
78 if (sqlca.sqlcode != 0) break;
79 strtrim(login);
80 strtrim(id);
81 if (isdigit(id[0]))
fa556426 82 fprintf(out, "%s %s@MIT.EDU\n", id, login);
c7fb2d10 83 }
84
85 EXEC SQL CLOSE x;
86
87 EXEC SQL DECLARE y CURSOR FOR SELECT
968f523c 88 u.clearid, s.string
c7fb2d10 89 FROM users u, strings s
968f523c 90 WHERE u.status != 3 and u.potype='SMTP' and u.box_id = s.string_id;
c7fb2d10 91 EXEC SQL OPEN y;
92 while (1) {
93 EXEC SQL FETCH y INTO :id, :string;
94 if (sqlca.sqlcode != 0) break;
95 strtrim(string);
96 strtrim(id);
97 if (isdigit(id[0])) {
98 if ((i = strlen(string)) > 7 &&
99 !strcasecmp(".local", string + i - 6)) {
100 string[i-6] = 0;
101 fprintf(out, "%s %s.mit.edu\n", id, string);
102 } else
103 fprintf(out, "%s %s\n", id, string);
104 }
105 }
106
107 EXEC SQL CLOSE y;
108
109#ifsql INGRES
110 EXEC SQL DISCONNECT;
111#endsql
112#ifsql INFORMIX
113 EXEC SQL CLOSE DATABASE;
114#endsql
115
116 if (fclose(out)) {
117 perror("close failed");
118 exit(MR_CCONFIG);
119 }
120 if (outf)
121 fix_file(outf);
122 exit(MR_SUCCESS);
123
124 sqlerr:
125 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
e1c251ac 126#ifsql INGRES
127 if (sqlca.sqlcode == 17700 || sqlca.sqlcode == -37000)
128 exit(MR_DEADLOCK);
129#endsql
c7fb2d10 130 critical_alert("DCM", "Pobox build encountered INGRES ERROR %d",
131 sqlca.sqlcode);
132 exit(MR_INGRES_ERR);
133}
This page took 1.187709 seconds and 5 git commands to generate.