|
|
1.1 root 1: /* dsa.c - Main routine for QUIPU DSA process */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/quipu/RCS/dsa.c,v 7.5 90/07/09 14:45:56 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/quipu/RCS/dsa.c,v 7.5 90/07/09 14:45:56 mrose Exp $
9: *
10: *
11: * $Log: dsa.c,v $
12: * Revision 7.5 90/07/09 14:45:56 mrose
13: * sync
14: *
15: * Revision 7.4 90/03/15 11:18:57 mrose
16: * quipu-sync
17: *
18: * Revision 7.3 90/01/11 23:55:57 mrose
19: * lint
20: *
21: * Revision 7.2 90/01/11 18:37:21 mrose
22: * real-sync
23: *
24: * Revision 7.1 89/12/19 16:53:08 mrose
25: * dgram
26: *
27: * Revision 7.0 89/11/23 22:17:19 mrose
28: * Release 6.0
29: *
30: */
31:
32: /*
33: * NOTICE
34: *
35: * Acquisition, use, and distribution of this module and related
36: * materials are subject to the restrictions of a license agreement.
37: * Consult the Preface in the User's Manual for the full terms of
38: * this agreement.
39: *
40: */
41:
42:
43: #include <signal.h>
44: #include <stdio.h>
45: #include <varargs.h>
46: #include "rosap.h"
47: #include "tsap.h"
48: #include "logger.h"
49: #include "tailor.h"
50: #include "quipu/util.h"
51: #include "quipu/connection.h"
52: #include <sys/ioctl.h>
53: #include <sys/stat.h>
54: #ifdef BSD42
55: #include <sys/file.h>
56: #endif
57: #ifdef SYS5
58: #include <fcntl.h>
59: #endif
60:
61: #include "dgram.h"
62: #ifdef TCP
63: #include "internet.h"
64: #endif
65:
66: PS opt;
67: static int debug = 1;
68: static int nbits = FD_SETSIZE;
69:
70: extern LLog * log_dsap;
71:
72: static char *myname;
73:
74: void adios (), advise ();
75: static envinit (), setdsauid();
76: SFD attempt_restart();
77: extern int print_parse_errors;
78: extern int parse_line;
79: struct task_act * task_select();
80:
81: extern SFP abort_vector;
82:
83: #ifndef NO_STATS
84: extern LLog *log_stat;
85: #endif
86:
87: /*
88: * Basic data structure of the DSA server.
89: */
90: char * mydsaname = "undefined";
91: struct PSAPaddr * mydsaaddr = NULLPA;
92: struct connection * connlist;
93: int conns_used;
94: struct connection * connwaitlist;
95: struct di_block * deferred_dis = NULL_DI_BLOCK;
96: struct oper_act * get_edb_ops;
97: OID acse_pci;
98: OID x500_da_ac;
99: OID x500_da_as;
100: OID x500_ds_ac;
101: OID x500_ds_as;
102: OID quipu_ds_ac;
103: OID quipu_ds_as;
104: struct PSAPctxlist x500_da_pcdl_s;
105: struct PSAPctxlist * x500_da_pcdl = &x500_da_pcdl_s;
106: struct PSAPctxlist x500_ds_pcdl_s;
107: struct PSAPctxlist * x500_ds_pcdl = &x500_ds_pcdl_s;
108: struct PSAPctxlist quipu_ds_pcdl_s;
109: struct PSAPctxlist * quipu_ds_pcdl = &quipu_ds_pcdl_s;
110:
111:
112: char ** sargv;
113:
114: main(argc, argv)
115: int argc;
116: char **argv;
117: {
118: #ifdef DEBUG
119: unsigned proc_size = 0;
120: unsigned new_size;
121: extern caddr_t sbrk();
122: #endif
123: extern char * mydsaname;
124: extern char startup_update;
125: extern struct PSAPaddr * mydsaaddr;
126: struct task_act * task;
127: int secs;
128: char start_buf [LINESIZE];
129: /*
130: * Function to stop DSA server.
131: */
132: SFD stop_dsa();
133:
134: sargv = argv;
135:
136: if (myname = rindex (argv[0], '/'))
137: myname++;
138: if (myname == NULL || *myname == NULL)
139: myname = argv[0];
140:
141: isodetailor (myname,0);
142:
143: envinit(); /* detach */
144:
145: quipu_syntaxes ();
146: dsa_sys_init(&argc, &argv);
147: setdsauid();
148:
149: print_parse_errors = FALSE;
150:
151: #ifndef NO_STATS
152: ll_hdinit (log_stat,myname);
153: #endif
154:
155: if ((opt = ps_alloc (std_open)) == NULLPS)
156: fatal (-12,"ps_alloc failed");
157: if (std_setup (opt,stdout) == NOTOK)
158: fatal (-13,"std_setup failed");
159:
160: DLOG (log_dsap,LLOG_DEBUG,( "About to dsa_init()"));
161:
162: if(dsa_init() == NOTOK)
163: {
164: fatal(-14,"Couldn't initialise the DSA!!");
165: }
166:
167:
168: if(net_init() == NOTOK)
169: {
170: fatal(-15,"Couldn't start the DSA!!");
171: }
172:
173:
174: if (startup_update)
175: {
176: /* Will generate a list of EDB operations! */
177: slave_update();
178: }
179:
180: {
181: extern char *treedir;
182: char filebuf[BUFSIZ];
183: FILE *fp;
184:
185: (void) sprintf (filebuf, "%s/PID", treedir);
186: if (fp = fopen (filebuf, "w")) {
187: (void) fprintf (fp, "%d\n", getpid ());
188: (void) fclose (fp);
189: }
190: else
191: LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't open PID file %s",filebuf));
192: }
193:
194: /*
195: * Do stop_dsa() on receiving a Ctrl-C
196: */
197:
198: (void) signal (SIGINT, stop_dsa);
199: (void) signal (SIGTERM,stop_dsa);
200: (void) signal (SIGHUP, stop_dsa);
201:
202: /* now started don't stop on core dumps !!! */
203: (void) signal (SIGQUIT, attempt_restart);
204: (void) signal (SIGILL, attempt_restart);
205: (void) signal (SIGBUS, attempt_restart);
206: (void) signal (SIGSEGV, attempt_restart);
207: (void) signal (SIGSYS, attempt_restart);
208:
209: abort_vector = attempt_restart;
210: parse_line = 0;
211:
212: (void) sprintf (start_buf,"DSA %s has started on %s",mydsaname,paddr2str(mydsaaddr,NULLNA));
213: LLOG (log_dsap,LLOG_NOTICE,(start_buf));
214: #ifndef NO_STATS
215: LLOG (log_stat,LLOG_NOTICE,(start_buf));
216: #endif
217:
218: if (debug)
219: (void) fprintf (stderr,"%s\n",start_buf);
220:
221: start_malloc_trace (NULLCP);
222:
223: #ifdef DEBUG
224: proc_size = (unsigned) sbrk(0);
225: #endif
226:
227: for(;;)
228: {
229: if((task = task_select(&secs)) == NULLTASK)
230: {
231: #ifdef DEBUG
232: if (secs > 0) {
233: /* Only if we are idle ! */
234: new_size = (unsigned) sbrk(0);
235: if ( new_size > proc_size) {
236: LLOG (log_dsap, LLOG_NOTICE, ("Process grown by %d bytes", new_size - proc_size));
237: proc_size = new_size;
238: }
239: }
240: #endif
241: dsa_wait(secs); /* Check network with timeout of secs */
242: }
243: else
244: {
245: dsa_work(task); /* Process the DSA task selected */
246: dsa_wait(0);
247: }
248: } /* forever */
249: } /* main */
250:
251: dsa_abort(isfatal)
252: int isfatal;
253: {
254: struct connection * cn;
255: struct DSAPindication di_s;
256: struct DSAPindication * di = &di_s;
257:
258: for(cn=connlist; cn!=NULLCONN; cn=cn->cn_next)
259: if (cn -> cn_ad != NOTOK) {
260: if (isfatal || (! cn -> cn_initiator))
261: (void) close (cn -> cn_ad);
262: else {
263: watch_dog ("DUAbortRequest quit");
264: (void) DUAbortRequest(cn->cn_ad, di);
265: watch_dog_reset ();
266: }
267: }
268:
269: watch_dog ("stop_listeners");
270: stop_listeners();
271: watch_dog_reset();
272: }
273:
274: SFD stop_dsa (sig)
275: int sig;
276: {
277: (void) signal (sig, SIG_DFL); /* to stop recursion */
278: LLOG (log_dsap,LLOG_FATAL,("*** Stopping on signal %d ***",sig));
279: if (debug)
280: (void) fprintf (stderr,"DSA %s has Stopped\n",mydsaname);
281: dsa_abort(0);
282: exit (0);
283: }
284:
285: static envinit () {
286: int i,
287: sd;
288:
289: nbits = getdtablesize ();
290:
291: if (!(debug = isatty (2))) {
292: for (i = 0; i < 5; i++) {
293: switch (fork ()) {
294: case NOTOK:
295: sleep (5);
296: continue;
297:
298: case OK:
299: goto fork_ok;
300:
301: default:
302: _exit (0);
303: }
304: break;
305: }
306:
307: fork_ok:;
308: (void) chdir ("/");
309:
310: if ((sd = open ("/dev/null", O_RDWR)) == NOTOK)
311: adios ("/dev/null", "unable to read");
312: if (sd != 0)
313: (void) dup2 (sd, 0), (void) close (sd);
314: (void) dup2 (0, 1);
315: (void) dup2 (0, 2);
316:
317: #ifdef SETSID
318: if (setsid () == NOTOK)
319: advise (LLOG_EXCEPTIONS, "failed", "setsid");
320: #endif
321: #ifdef TIOCNOTTY
322: if ((sd = open ("/dev/tty", O_RDWR)) != NOTOK) {
323: (void) ioctl (sd, TIOCNOTTY, NULLCP);
324: (void) close (sd);
325: }
326: #else
327: #ifdef SYS5
328: (void) setpgrp ();
329: (void) signal (SIGINT, SIG_IGN);
330: (void) signal (SIGQUIT, SIG_IGN);
331: #endif
332: #endif
333: }
334: #ifndef DEBUG
335: /* "Normal" ISODE behavior of full logging only without DEBUG */
336: else
337: ll_dbinit (log_dsap, myname);
338: #endif
339:
340: #ifndef sun /* damn YP... */
341: for (sd = 3; sd < nbits; sd++) {
342: if (log_dsap -> ll_fd == sd)
343: continue;
344: #ifdef NO_STATS
345: if (log_stats -> ll_fd == sd)
346: continue;
347: #endif
348: (void) close (sd);
349: }
350: #endif
351:
352: (void) signal (SIGPIPE, SIG_IGN);
353:
354: ll_hdinit (log_dsap, myname);
355: #ifdef DEBUG
356: advise (LLOG_TRACE, NULLCP, "starting");
357: #endif
358: }
359:
360:
361: /* ERRORS */
362:
363: #ifndef lint
364: void adios (va_alist)
365: va_dcl
366: {
367: va_list ap;
368:
369: va_start (ap);
370:
371: _ll_log (log_dsap, LLOG_FATAL, ap);
372:
373: va_end (ap);
374:
375: if (debug)
376: (void) fprintf (stderr,"adios exit - see dsap.log\n");
377: dsa_abort(1);
378: _exit (-18);
379: }
380: #else
381: /* VARARGS */
382:
383: void adios (what, fmt)
384: char *what,
385: *fmt;
386: {
387: adios (what, fmt);
388: }
389: #endif
390:
391: #ifndef lint
392: void advise (va_alist)
393: va_dcl
394: {
395: int code;
396: va_list ap;
397:
398: va_start (ap);
399:
400: code = va_arg (ap, int);
401:
402: (void) _ll_log (log_dsap, code, ap);
403:
404: va_end (ap);
405: }
406: #else
407: /* VARARGS */
408:
409: void advise (code, what, fmt)
410: char *what,
411: *fmt;
412: int code;
413: {
414: advise (code, what, fmt);
415: }
416: #endif
417:
418:
419:
420: static setdsauid ()
421: {
422: struct stat buf;
423: extern char * treedir;
424:
425: (void) stat (treedir,&buf);
426:
427: if (setgid (buf.st_gid) == -1)
428: LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't set gid %d (database directory \"%s\")",buf.st_uid,treedir));
429:
430: if (setuid (buf.st_uid) == -1)
431: LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't set uid %d (database directory \"%s\")",buf.st_uid,treedir));
432: }
433:
434: #define RESTART_TIME 30 /* for connections to clear... */
435: #define CLEAR_TIME 300 /* .. */
436:
437: SFD attempt_restart (sig)
438: int sig;
439: {
440: int fpid, sd;
441: unsigned int secs;
442: extern char * mydsaname;
443:
444: if (sig > 0)
445: (void) signal (sig, SIG_DFL); /* to stop recursion */
446:
447: if (sig >= 0 && debug)
448: (void) fprintf (stderr,"DSA %s has a problem\n",mydsaname);
449:
450: dsa_abort(sig != NOTOK);
451: secs = sig != NOTOK ? CLEAR_TIME : RESTART_TIME;
452:
453: for (sd = 3; sd < nbits; sd++) {
454: if (log_dsap -> ll_fd == sd)
455: continue;
456: #ifdef NO_STATS
457: if (log_stats -> ll_fd == sd)
458: continue;
459: #endif
460: (void) close (sd);
461: }
462:
463: if ( sig == -2 || (fpid = fork()) == 0) {
464: if (sig == -2) { /* restart due to congestion... */
465: LLOG (log_dsap,LLOG_FATAL, ("*** in-situ restart attempted ***"));
466: #ifndef NO_STATS
467: LLOG (log_stat,LLOG_NOTICE,("RESTARTING (%s)",mydsaname));
468: #endif
469: }
470:
471: sleep (secs); /* give connections time to clear */
472: execv (isodefile(sargv[0], 1),sargv);
473: exit (-19);
474: }
475:
476: if (sig >= 0)
477: LLOG (log_dsap,LLOG_FATAL,("*** Process dying on signal %d ***",sig));
478:
479: if (fpid != -1) {
480: LLOG (log_dsap,LLOG_FATAL,("*** restart attempted in %d seconds ***", secs));
481: #ifndef NO_STATS
482: LLOG (log_stat,LLOG_NOTICE,("RESTARTING with pid %d (%s)",fpid,mydsaname));
483: } else {
484: LLOG (log_stat,LLOG_NOTICE,("PANIC (%s)",mydsaname));
485: #endif
486: }
487:
488: (void) signal (SIGIOT, SIG_DFL);
489: abort ();
490: exit (-20); /* abort should not return */
491: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.