DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T d

⟦474460a96⟧ TextFile

    Length: 7908 (0x1ee4)
    Types: TextFile
    Names: »dsa.c«

Derivation

└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
    └─⟦eba4602b1⟧ »./isode-5.0.tar.Z« 
        └─⟦d3ac74d73⟧ 
            └─⟦this⟧ »isode-5.0/quipu/dsa.c« 

TextFile

/* dsa.c - Main routine for QUIPU DSA process */

#ifndef lint
static char *rcsid = "$Header: /f/osi/quipu/RCS/dsa.c,v 6.1 89/03/23 22:27:53 mrose Exp $";
#endif

/*
 * $Header: /f/osi/quipu/RCS/dsa.c,v 6.1 89/03/23 22:27:53 mrose Exp $
 *
 *
 * $Log:	dsa.c,v $
 * Revision 6.1  89/03/23  22:27:53  mrose
 * out-the-door
 * 
 * Revision 6.0  89/03/18  23:41:25  mrose
 * Release 5.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

#ifdef lint
#define ETCDIR "/etc"
#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;
#ifdef DSAP
extern int nameservice;
#endif

#ifndef NO_STATS

static  LLog    lstat_log =
{
	"quipu.log",
	NULLCP,
	NULLCP,
	LLOG_NOTICE,
	LLOG_NONE,
	50,
	LLOGCLS | LLOGCRT | LLOGZER,
	NOTOK,
};

LLog    *log_stat = &lstat_log;

#endif

/*
* Basic data structure of the DSA server.
*/
struct quipu_dsa_state     id_st;

extern char *isodepath;
char ** sargv;

main(argc, argv)
int    argc;
char    **argv;
{

    extern char * mydsaname;
    struct activity     * act;
    extern int quipu_nofree_malloc;
    extern char startup_update;
    extern char * sbrk();

    /*
    * Function to stop DSA server.
    */
    SFD          stop_dsa();

    isodepath = ETCDIR;

    sargv = argv;

    if (myname = rindex (argv[0], '/'))
	myname++;
    if (myname == NULL || *myname == NULL)
	myname = argv[0];

    isodetailor (myname,0);

    envinit();  /* detach */
    dsa_sys_init(&argc, &argv);
    setdsauid();

#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()"));

#ifdef QUIPU_MALLOC
    quipu_nofree_malloc = TRUE;
		/* database will rarely have components freed so use 
		this optimisation */
#endif

    if(dsa_init(NULLCP) == NOTOK)
    {
	fatal(-14,"Couldn't initialise the DSA!!");
    }

#ifdef QUIPU_MALLOC
    quipu_nofree_malloc = FALSE;
#endif

    if (startup_update) 
    {
  	slave_update();
    }


    if(net_init() == NOTOK)
    {
	fatal(15,"Couldn't initialise the network monitor!!");
    }

#ifdef DSAP
    if (start_nameserver)
	    ns_init ();
#endif

    /*
    * Do stop_dsa() on receiving a Ctrl-C
    */
    (void) signal (SIGINT,stop_dsa);
    (void) signal (SIGTERM,stop_dsa);

    /* now started don't stop on core dumps !!! */
    (void) signal (SIGQUIT, attempt_restart);
    (void) signal (SIGILL, attempt_restart);
    (void) signal (SIGTRAP, attempt_restart);
    (void) signal (SIGIOT, attempt_restart);
    (void) signal (SIGBUS, attempt_restart);
    (void) signal (SIGSEGV, attempt_restart);
    (void) signal (SIGSYS, attempt_restart);
  
    LLOG (log_dsap,LLOG_NOTICE,( "DSA Started..."));

    (void) fprintf (stderr,"DSA Started\n");

#ifndef NO_STATS
    LLOG (log_stat,LLOG_NOTICE,("DSA started (%s)",mydsaname));
#endif

    for(;;)
    {
	DLOG (log_dsap,LLOG_DEBUG,("sbrk %x",sbrk(0)));

	if(conn_select(&act) == ACTIVITY_NET_WAIT)
	{
	    if(act == NULLACTIVITY)
	        net_monitor(NOTOK);	/* Block until something happens */
	    else
		net_monitor(1);		/* Poll the network for 1 sec */
	}
	else
	{
	    dsa_schedule(act);
	}
    } /* forever */
} /* main */

dsa_abort()
{
    struct connection		* cn;
    struct AcSAPindication	  aci_s;
    struct AcSAPindication	*aci = &aci_s;

#ifdef DSAP
    if(start_nameserver)
    {
	(void) close_udp_socket(nameservice);
    }
#endif

    for(cn=id_st.connlist; cn!=NULLCONN; cn=cn->cn_next)
    {
	if(cn->cn_ad != 0)
	    (void) AcUAbortRequest(cn->cn_ad, NULLPEP, 0, aci);
    }
}

SFD stop_dsa ()
{
	LLOG (log_dsap,LLOG_FATAL,("*** SIGINT ***"));
	dsa_abort();
	stop_listeners ();
	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++)
	(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);

    (void) fprintf (stderr,"adios exit - see dsap.log\n");
    _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;
char filebuf [BUFSIZ];
FILE * fptr;
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));

	(void) sprintf (filebuf,"%s/PID",treedir);
	if ((fptr = fopen (filebuf,"w")) == NULL ) {
		LLOG (log_dsap,LLOG_EXCEPTIONS,("Cant open PID file %s",filebuf));
		return;
	}

	(void) fprintf (fptr,"%d",getpid());
	(void) fclose (fptr);
}

/* ARGSUSED */
SFD attempt_restart (sig, code, context)
int     sig, code;
struct sigcontext *context;
{
int fpid;
extern char * mydsaname;
extern char *sys_siglist[];

	dsa_abort();
	stop_listeners();

	if ( (fpid =fork ()) == 0) {
		/* restart !!! */
		sleep (5);	/* give connections time to clear */
		execv (isodefile(sargv[0]),sargv);
		exit (-19);
	}

	(void) signal (sig, SIG_DFL);    /* to stop recursion */
	(void) signal (SIGILL, SIG_DFL); /* for abort */
	(void) signal (SIGIOT, SIG_DFL); /* for abort */
	LLOG (log_dsap,LLOG_FATAL,("*** Process dying on signal %d (%s) ***", sig, sys_siglist[sig]));
	if (fpid != -1)
		LLOG (log_dsap,LLOG_FATAL,("*** restart attempted ***"));
#ifndef NO_STATS
	if (fpid != -1)
		LLOG (log_stat,LLOG_NOTICE,("RESTARTING (%s)",mydsaname));
	else
		LLOG (log_stat,LLOG_NOTICE,("PANIC (%s)",mydsaname));
#endif
	(void) fprintf (stderr,"%s - core dumped\n",sys_siglist[sig]);
	abort ();
	exit (-20);  /* abort may return */
}