|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T d
Length: 10010 (0x271a)
Types: TextFile
Names: »dsa.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦35176feda⟧ »EurOpenD22/isode/isode-6.tar.Z«
└─⟦de7628f85⟧
└─⟦this⟧ »isode-6.0/quipu/dsa.c«
/* dsa.c - Main routine for QUIPU DSA process */
#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/RCS/dsa.c,v 7.3 90/01/11 23:55:57 mrose Exp $";
#endif
/*
* $Header: /f/osi/quipu/RCS/dsa.c,v 7.3 90/01/11 23:55:57 mrose Exp $
*
*
* $Log: dsa.c,v $
* Revision 7.3 90/01/11 23:55:57 mrose
* lint
*
* Revision 7.2 90/01/11 18:37:21 mrose
* real-sync
*
* Revision 7.1 89/12/19 16:53:08 mrose
* dgram
*
* Revision 7.0 89/11/23 22:17:19 mrose
* Release 6.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
#include <signal.h>
#include <stdio.h>
#include <varargs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "rosap.h"
#include "tsap.h"
#include "logger.h"
#include "tailor.h"
#include "quipu/util.h"
#include "quipu/connection.h"
#ifdef BSD42
#include <sys/file.h>
#endif
#ifdef SYS5
#include <fcntl.h>
#endif
#include "dgram.h"
#ifdef TCP
#include "internet.h"
#endif
PS opt;
static int debug = 1;
static int nbits = FD_SETSIZE;
extern LLog * log_dsap;
static char *myname;
void adios (), advise ();
static envinit (), setdsauid();
SFD attempt_restart();
extern int start_nameserver;
extern int nameservice;
extern int print_parse_errors;
struct task_act * task_select();
extern SFP abort_vector;
#ifndef NO_STATS
extern LLog *log_stat;
#endif
/*
* Basic data structure of the DSA server.
*/
char * mydsaname = "undefined";
struct PSAPaddr * mydsaaddr = NULLPA;
struct connection * connlist;
int conns_used;
struct connection * connwaitlist;
struct di_block * deferred_dis = NULL_DI_BLOCK;
struct oper_act * get_edb_ops;
OID acse_pci;
OID x500_da_ac;
OID x500_da_as;
OID x500_ds_ac;
OID x500_ds_as;
OID quipu_ds_ac;
OID quipu_ds_as;
struct PSAPctxlist x500_da_pcdl_s;
struct PSAPctxlist * x500_da_pcdl = &x500_da_pcdl_s;
struct PSAPctxlist x500_ds_pcdl_s;
struct PSAPctxlist * x500_ds_pcdl = &x500_ds_pcdl_s;
struct PSAPctxlist quipu_ds_pcdl_s;
struct PSAPctxlist * quipu_ds_pcdl = &quipu_ds_pcdl_s;
int nameserver_unused = TRUE;
char ** sargv;
main(argc, argv)
int argc;
char **argv;
{
#ifdef DEBUG
unsigned proc_size = 0;
unsigned new_size;
extern caddr_t sbrk();
#endif
extern char * mydsaname;
extern char startup_update;
extern struct PSAPaddr * mydsaaddr;
struct task_act * task;
int secs;
char start_buf [LINESIZE];
/*
* Function to stop DSA server.
*/
SFD stop_dsa();
sargv = argv;
if (myname = rindex (argv[0], '/'))
myname++;
if (myname == NULL || *myname == NULL)
myname = argv[0];
isodetailor (myname,0);
envinit(); /* detach */
quipu_syntaxes ();
dsa_sys_init(&argc, &argv);
setdsauid();
print_parse_errors = FALSE;
#ifndef NO_STATS
ll_hdinit (log_stat,myname);
#endif
if ((opt = ps_alloc (std_open)) == NULLPS)
fatal (-12,"ps_alloc failed");
if (std_setup (opt,stdout) == NOTOK)
fatal (-13,"std_setup failed");
DLOG (log_dsap,LLOG_DEBUG,( "About to dsa_init()"));
if(dsa_init() == NOTOK)
{
fatal(-14,"Couldn't initialise the DSA!!");
}
if(net_init() == NOTOK)
{
fatal(-15,"Couldn't start the DSA!!");
}
if (start_nameserver)
ns_init ();
if (startup_update)
{
/* Will generate a list of EDB operations! */
slave_update();
}
{
extern char *treedir;
char filebuf[BUFSIZ];
FILE *fp;
(void) sprintf (filebuf, "%s/PID", treedir);
if (fp = fopen (filebuf, "w")) {
(void) fprintf (fp, "%d\n", getpid ());
(void) fclose (fp);
}
else
LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't open PID file %s",filebuf));
}
/*
* Do stop_dsa() on receiving a Ctrl-C
*/
(void) signal (SIGINT, stop_dsa);
(void) signal (SIGTERM,stop_dsa);
(void) signal (SIGHUP, stop_dsa);
/* now started don't stop on core dumps !!! */
(void) signal (SIGQUIT, attempt_restart);
(void) signal (SIGILL, attempt_restart);
(void) signal (SIGBUS, attempt_restart);
(void) signal (SIGSEGV, attempt_restart);
(void) signal (SIGSYS, attempt_restart);
abort_vector = attempt_restart;
(void) sprintf (start_buf,"DSA %s has started on %s",mydsaname,paddr2str(mydsaaddr,NULLNA));
LLOG (log_dsap,LLOG_NOTICE,(start_buf));
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,(start_buf));
#endif
if (debug) {
(void) fprintf (stderr,"%s\n",start_buf);
if (start_nameserver)
(void) fprintf (stderr,"NS has started on %s\n",ns_address);
}
start_malloc_trace (NULLCP);
#ifdef DEBUG
proc_size = (unsigned) sbrk(0);
#endif
for(;;)
{
#ifdef DEBUG
new_size = (unsigned) sbrk(0);
if ( new_size > proc_size) {
LLOG (log_dsap, LLOG_NOTICE, ("Process grown by %d bytes", new_size - proc_size));
proc_size = new_size;
}
#endif
if((task = task_select(&secs)) == NULLTASK)
{
dsa_wait(secs); /* Check network with timeout of secs */
}
else
{
dsa_work(task); /* Process the DSA task selected */
dsa_wait(0);
}
} /* forever */
} /* main */
dsa_abort(isfatal)
int isfatal;
{
struct connection * cn;
struct AcSAPindication aci_s;
struct AcSAPindication *aci = &aci_s;
#if defined(SOCKETS) && defined(TCP)
if(start_nameserver)
{
(void) close_udp_socket(nameservice);
}
#endif
for(cn=connlist; cn!=NULLCONN; cn=cn->cn_next)
if (cn -> cn_ad != NOTOK) {
if (isfatal || cn -> cn_initiator != INITIATED_BY_THIS)
(void) close (cn -> cn_ad);
else {
watch_dog ("AcUAbortRequest quit");
(void) AcUAbortRequest(cn->cn_ad, NULLPEP, 0, aci);
watch_dog_reset ();
}
}
watch_dog ("stop_listeners");
stop_listeners();
watch_dog_reset();
}
SFD stop_dsa (sig)
int sig;
{
(void) signal (sig, SIG_DFL); /* to stop recursion */
LLOG (log_dsap,LLOG_FATAL,("*** Stopping on signal %d ***",sig));
if (debug)
(void) fprintf (stderr,"DSA %s has Stopped\n",mydsaname);
dsa_abort(0);
exit (0);
}
static envinit () {
int i,
sd;
nbits = getdtablesize ();
if (!(debug = isatty (2))) {
for (i = 0; i < 5; i++) {
switch (fork ()) {
case NOTOK:
sleep (5);
continue;
case OK:
goto fork_ok;
default:
_exit (0);
}
break;
}
fork_ok:;
(void) chdir ("/");
if ((sd = open ("/dev/null", O_RDWR)) == NOTOK)
adios ("/dev/null", "unable to read");
if (sd != 0)
(void) dup2 (sd, 0), (void) close (sd);
(void) dup2 (0, 1);
(void) dup2 (0, 2);
#ifdef TIOCNOTTY
if ((sd = open ("/dev/tty", O_RDWR)) != NOTOK) {
(void) ioctl (sd, TIOCNOTTY, NULLCP);
(void) close (sd);
}
#else
#ifdef SYS5
(void) setpgrp ();
(void) signal (SIGINT, SIG_IGN);
(void) signal (SIGQUIT, SIG_IGN);
#endif
#endif
}
#ifndef DEBUG
/* "Normal" ISODE behavior of full logging only without DEBUG */
else
ll_dbinit (log_dsap, myname);
#endif
#ifndef sun /* damn YP... */
for (sd = 3; sd < nbits; sd++) {
if (log_dsap -> ll_fd == sd)
continue;
#ifdef NO_STATS
if (log_stats -> ll_fd == sd)
continue;
#endif
(void) close (sd);
}
#endif
(void) signal (SIGPIPE, SIG_IGN);
ll_hdinit (log_dsap, myname);
#ifdef DEBUG
advise (LLOG_TRACE, NULLCP, "starting");
#endif
}
/* \f
ERRORS */
#ifndef lint
void adios (va_alist)
va_dcl
{
va_list ap;
va_start (ap);
_ll_log (log_dsap, LLOG_FATAL, ap);
va_end (ap);
if (debug)
(void) fprintf (stderr,"adios exit - see dsap.log\n");
dsa_abort(1);
_exit (-18);
}
#else
/* VARARGS */
void adios (what, fmt)
char *what,
*fmt;
{
adios (what, fmt);
}
#endif
#ifndef lint
void advise (va_alist)
va_dcl
{
int code;
va_list ap;
va_start (ap);
code = va_arg (ap, int);
(void) _ll_log (log_dsap, code, ap);
va_end (ap);
}
#else
/* VARARGS */
void advise (code, what, fmt)
char *what,
*fmt;
int code;
{
advise (code, what, fmt);
}
#endif
static setdsauid ()
{
struct stat buf;
extern char * treedir;
(void) stat (treedir,&buf);
if (setgid (buf.st_gid) == -1)
LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't set gid %d (database directory \"%s\")",buf.st_uid,treedir));
if (setuid (buf.st_uid) == -1)
LLOG (log_dsap,LLOG_EXCEPTIONS,("Can't set uid %d (database directory \"%s\")",buf.st_uid,treedir));
}
#define RESTART_TIME 30 /* for connections to clear... */
#define CLEAR_TIME 300 /* .. */
SFD attempt_restart (sig)
int sig;
{
int fpid, sd;
unsigned int secs;
extern char * mydsaname;
if (sig > 0)
(void) signal (sig, SIG_DFL); /* to stop recursion */
if (sig >= 0 && debug)
(void) fprintf (stderr,"DSA %s has a problem\n",mydsaname);
dsa_abort(sig != NOTOK);
secs = sig != NOTOK ? CLEAR_TIME : RESTART_TIME;
for (sd = 3; sd < nbits; sd++) {
if (log_dsap -> ll_fd == sd)
continue;
#ifdef NO_STATS
if (log_stats -> ll_fd == sd)
continue;
#endif
(void) close (sd);
}
if ( sig == -2 || (fpid = fork()) == 0) {
if (sig == -2) { /* restart due to congestion... */
LLOG (log_dsap,LLOG_FATAL, ("*** in-situ restart attempted ***"));
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,("RESTARTING (%s)",mydsaname));
#endif
}
sleep (secs); /* give connections time to clear */
execv (isodefile(sargv[0], 1),sargv);
exit (-19);
}
if (sig >= 0)
LLOG (log_dsap,LLOG_FATAL,("*** Process dying on signal %d ***",sig));
if (fpid != -1) {
LLOG (log_dsap,LLOG_FATAL,("*** restart attempted in %d seconds ***", secs));
#ifndef NO_STATS
LLOG (log_stat,LLOG_NOTICE,("RESTARTING with pid %d (%s)",fpid,mydsaname));
} else {
LLOG (log_stat,LLOG_NOTICE,("PANIC (%s)",mydsaname));
#endif
}
(void) signal (SIGIOT, SIG_DFL);
abort ();
exit (-20); /* abort should not return */
}