|
|
1.1 root 1: /*
2: * Retrieve files from GCOS via Spider or dataphone
3: */
4:
5: #include <errno.h>
6: #include <setjmp.h>
7:
8: char dpd[] = "/usr/spool/dpd";
9: char lock[] = "/usr/spool/dpd/glock";
10: char error[] = "/usr/spool/dpd/errors";
11:
12: #include "daemon0.c"
13:
14: #define MINUTES 60
15:
16: #define OKTRB 0
17: #define BADTRB 1
18: #define FATTRB 2
19:
20: char zfname[] = "/usr/spool/dpd/zf";
21: int LZFNAME = 0; /*length of pathname of zf-file thru 'f'. MRW */
22: char badbuf[] = "/usr/spool/dpd/fget.badbuf";
23: char okmes[] = "OK nd =%3d, nf = %-19d";
24: char fgeto[] = "fget.odemon";
25: char *argvo[] = {fgeto, NULL, NULL};
26:
27: FILE *ofd = NULL; /*data file*/
28: FILE *tfd = NULL; /*badbuf file*/
29: int tlaps = 0;
30: int tlimit = 6*MINUTES;
31: int tfac = 1;
32: int nbaderr = 0;
33: int gotit = 0;
34: int nfiles = 0;
35: int ndelim = 0;
36: long nnull = 0; /*count of consecutive nulls*/
37: char fname[108];
38: jmp_buf env;
39:
40: int (*output)();
41:
42:
43: main(argc, argv)
44:
45: int argc;
46: char *argv[];
47:
48: {
49:
50: int i;
51: extern ignore();
52:
53: dem_setup();
54: LZFNAME = 0; /*calculate length of zfname. MRW*/
55: while(zfname[LZFNAME]) LZFNAME++;
56:
57: if (argc == 2) {
58: argvo[1] = argv[1];
59: tlimit = 0;
60: i = 0;
61: while ( argv[1][i] ) tlimit = 10*tlimit + argv[1][i++] - '0' ;
62: }
63:
64: #ifdef DEBUG
65: fprintf(stderr, "tlimit = %d\n",tlimit); /* PRINTF */
66: #endif
67:
68: setjmp(env);
69:
70: ofd = NULL;
71: output = ignore;
72:
73: fgd_read(); /*perform input appropriate to device.*/
74:
75: if (gotit == 0)
76: trouble(OKTRB, -20, "no output");
77:
78: if (gotit == 1) {
79: gotit = 2;
80: trouble(OKTRB, 20, okmes, ndelim, nfiles);
81: }
82:
83: trouble(OKTRB, 0, okmes, ndelim, nfiles);
84: }
85:
86:
87:
88: /* VARARGS */
89: trouble(lev, t, s, a1, a2, a3)
90: int lev;
91: int t;
92: char *s;
93: int a1, a2, a3;
94: {
95:
96: #ifdef DEBUG
97: fprintf(stderr, s, a1, a2, a3); putc('\n', stderr); /* PRINTF */
98: #endif
99: alarm(0);
100: dem_dis(); /*close appropriate device.*/
101: if ( lev >= BADTRB ) nbaderr++;
102:
103: if ( lev <= BADTRB && nbaderr < 2 && t != 0 && tlaps < tlimit ) {
104: if (t < 0) t = -t;
105: t *= tfac;
106: if (t > 4*MINUTES) t = 4*MINUTES;
107: #ifdef DEBUG
108: fprintf(stderr, "holding, t = %d, tlaps = %d\n",t,tlaps); /* PRINTF */
109: #endif
110: sleep(t);
111: tlaps += t;
112: tfac += tfac;
113: if(access(lock, 0) == 0)
114: longjmp(env, 1);
115: logerr("glock has disappeared");
116: }
117:
118: if(gotit)
119: logerr(okmes, ndelim, nfiles);
120: if(t >= 0 && lev > OKTRB)
121: logerr(s, a1, a2, a3);
122:
123: if ( lev >= BADTRB ) {
124: sleep(20);
125: unlink(lock);
126: #ifndef DEBUG
127: #if SPIDER
128: execv("/etc/fget.odemon", argvo);
129: execv("/usr/lib/fget.odemon", argvo);
130: #endif
131: #endif
132: }
133:
134: unlink(lock);
135: exit(0);
136: }
137:
138:
139:
140:
141: ignore(b, i)
142: {
143: }
144:
145:
146: outputa(b, i)
147: char *b;
148: int i;
149: {
150: for ( ; i -- > 0; b++ ) {
151: if (*b == '\0') nnull++;
152: else {
153: for ( ; nnull > 0; nnull -- ) putc( '\0', ofd );
154: putc( *b, ofd );
155: }
156: }
157: }
158:
159:
160: outputb(b, i)
161: char *b;
162: int i;
163: {
164: for ( ; i-- > 0; b++ ) putc( *b, ofd );
165: }
166:
167:
168: firstln(b, i)
169: char b[];
170: int i;
171: {
172: char *fp, *sp;
173: extern ignore(), outputa(), outputb();
174:
175: output = ignore;
176: if ( i == 0 ) return;
177: b[i-1] = '\0';
178: if (i < 104 || b[1] != ' ') {
179: logerr("illeg contr line %s", b);
180: return;
181: }
182:
183: switch (b[0]) {
184:
185: case 'a':
186: case 'A':
187: output = outputa;
188: break;
189:
190: case 'b':
191: case 'B':
192: output = outputb;
193: break;
194:
195: default:
196: logerr("illegal control char - %s\n", b);
197: return;
198:
199: }
200:
201: fp = fname;
202: sp = &b[2];
203: while (*fp++ = *sp++);
204:
205: #ifdef DEBUG
206: fprintf(stderr, "file = %s\n",fname); /* PRINTF */
207: #endif
208:
209: if ( (ofd = fopen(fname, "w")) == NULL) {
210: output = ignore;
211: logerr("cannot open: %s", fname);
212: }
213:
214: nnull = 0;
215: }
216:
217:
218:
219: endfile()
220: {
221: int n;
222: char *fp;
223: extern firstln();
224:
225: gotit = 1;
226: ndelim++;
227: output = firstln;
228: if (ofd == NULL) return;
229: FCLOSE(ofd);
230:
231: nfiles++;
232: nnull = 0;
233:
234: n = 0;
235: fp = fname;
236: while (n < LZFNAME) {
237: if (*fp++ != zfname[n++]) return;
238: }
239:
240: unlink(fname);
241:
242:
243: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.