File:  [CSRG BSD Unix] / 43BSDReno / contrib / isode-beta / acsap / acserver1.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:56 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43reno
BSD 4.3reno

/* acserver1.c - generic server dispatch */

#ifndef	lint
static char *rcsid = "$Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/acsap/acserver1.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $";
#endif

/* 
 * $Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/acsap/acserver1.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $
 *
 *
 * $Log: acserver1.c,v $
 * Revision 1.1.1.1  2018/04/24 16:12:56  root
 * BSD 4.3reno
 *
 * Revision 7.2  90/07/09  14:30:45  mrose
 * sync
 * 
 * Revision 7.1  90/02/19  13:07:05  mrose
 * update
 * 
 * Revision 7.0  89/11/23  21:22:02  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.
 *
 */


/* LINTLIBRARY */

#include <signal.h>
#include "psap.h"
#include "tsap.h"
#include <sys/ioctl.h>
#ifdef	BSD42
#include <sys/file.h>
#endif
#ifdef	SYS5
#include <fcntl.h>
#endif
#include "tailor.h"

/*  */

int	isodeserver (argc, argv, aei, initfnx, workfnx, losefnx, td)
int	argc;
char  **argv;
AEI	aei;
IFP	initfnx,
	workfnx,
	losefnx;
struct TSAPdisconnect *td;
{
    int     fd,
            nfds,
            vecp;
    fd_set  ifds,
            mask;
    char   *vec[4];

    isodetailor (NULLCP, 0);

    nfds = 0;
    FD_ZERO (&mask);

    if (argc > 1) {
	if ((fd = (*initfnx) (argc, argv)) == NOTOK)
	    return tsaplose (td, DR_NETWORK, NULLCP, "initialization failed");

	nfds = fd + 1;
	FD_SET (fd, &mask);
    }
    else {
	struct PSAPaddr *pa;

	if ((pa = aei2addr (aei)) == NULLPA)
	    return tsaplose (td, DR_ADDRESS, NULLCP,
		    "address translation failed");

	if (TNetListen (&pa -> pa_addr.sa_addr, td) == NOTOK)
	    return NOTOK;

	if (!isatty (2)) {
	    int     i;

	    for (i = 0; i < 5; i++) {
		switch (fork ()) {
		    case NOTOK: 
			sleep (5);
			continue;

		    case OK: 
			break;

		    default: 
			_exit (0);
		}
		break;
	    }

	    (void) chdir ("/");

	    if ((fd = open ("/dev/null", O_RDWR)) != NOTOK) {
		if (fd != 0)
		    (void) dup2 (fd, 0), (void) close (fd);
		(void) dup2 (0, 1);
		(void) dup2 (0, 2);
	    }

#ifdef	SETSID
	    (void) setsid ();
#endif
#ifdef	TIOCNOTTY
	    if ((fd = open ("/dev/tty", O_RDWR)) != NOTOK) {
		(void) ioctl (fd, TIOCNOTTY, NULLCP);
		(void) close (fd);
	    }
#else
#ifdef	SYS5
	    (void) setpgrp ();
	    (void) signal (SIGINT, SIG_IGN);
	    (void) signal (SIGQUIT, SIG_IGN);
#endif
#endif
	    isodexport (NULLCP);	/* re-initialize logfiles */
	}
    }

    for (;;) {
	ifds = mask;
	if (TNetAccept (&vecp, vec, nfds, &ifds, NULLFD, NULLFD, NOTOK, td)
		== NOTOK) {
	    (void) (*losefnx) (td);
	    continue;
	}

	if (vecp > 0 && (fd = (*initfnx) (vecp, vec)) != NOTOK) {
	    if (fd >= nfds)
		nfds = fd + 1;
	    FD_SET (fd, &mask);
	}

	for (fd = 0; fd < nfds; fd++)
	    if (FD_ISSET (fd, &ifds)) {
		if (workfnx == NULLIFP) {
		    (void) TNetClose (NULLTA, td);
		    return tsaplose (td, DR_OPERATION, NULLCP,
				     "no worker routine for connected fd");
		}

		if ((*workfnx) (fd) == NOTOK) {
		    if (nfds == fd + 1)
			nfds--;
		    FD_CLR (fd, &mask);
		    if (argc > 1) {
			int	    xd;

			for (xd = 0; xd < nfds; xd++)
			    if (FD_ISSET (xd, &mask))
				break;
			if (xd >= nfds)
			    return OK;
		    }
		}
	    }
    }
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.