Annotation of 43BSDReno/contrib/isode-beta/acsap/acserver1.c, revision 1.1.1.1

1.1       root        1: /* acserver1.c - generic server dispatch */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/acsap/RCS/acserver1.c,v 7.2 90/07/09 14:30:45 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/acsap/RCS/acserver1.c,v 7.2 90/07/09 14:30:45 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       acserver1.c,v $
                     12:  * Revision 7.2  90/07/09  14:30:45  mrose
                     13:  * sync
                     14:  * 
                     15:  * Revision 7.1  90/02/19  13:07:05  mrose
                     16:  * update
                     17:  * 
                     18:  * Revision 7.0  89/11/23  21:22:02  mrose
                     19:  * Release 6.0
                     20:  * 
                     21:  */
                     22: 
                     23: /*
                     24:  *                               NOTICE
                     25:  *
                     26:  *    Acquisition, use, and distribution of this module and related
                     27:  *    materials are subject to the restrictions of a license agreement.
                     28:  *    Consult the Preface in the User's Manual for the full terms of
                     29:  *    this agreement.
                     30:  *
                     31:  */
                     32: 
                     33: 
                     34: /* LINTLIBRARY */
                     35: 
                     36: #include <signal.h>
                     37: #include "psap.h"
                     38: #include "tsap.h"
                     39: #include <sys/ioctl.h>
                     40: #ifdef BSD42
                     41: #include <sys/file.h>
                     42: #endif
                     43: #ifdef SYS5
                     44: #include <fcntl.h>
                     45: #endif
                     46: #include "tailor.h"
                     47: 
                     48: /*  */
                     49: 
                     50: int    isodeserver (argc, argv, aei, initfnx, workfnx, losefnx, td)
                     51: int    argc;
                     52: char  **argv;
                     53: AEI    aei;
                     54: IFP    initfnx,
                     55:        workfnx,
                     56:        losefnx;
                     57: struct TSAPdisconnect *td;
                     58: {
                     59:     int     fd,
                     60:             nfds,
                     61:             vecp;
                     62:     fd_set  ifds,
                     63:             mask;
                     64:     char   *vec[4];
                     65: 
                     66:     isodetailor (NULLCP, 0);
                     67: 
                     68:     nfds = 0;
                     69:     FD_ZERO (&mask);
                     70: 
                     71:     if (argc > 1) {
                     72:        if ((fd = (*initfnx) (argc, argv)) == NOTOK)
                     73:            return tsaplose (td, DR_NETWORK, NULLCP, "initialization failed");
                     74: 
                     75:        nfds = fd + 1;
                     76:        FD_SET (fd, &mask);
                     77:     }
                     78:     else {
                     79:        struct PSAPaddr *pa;
                     80: 
                     81:        if ((pa = aei2addr (aei)) == NULLPA)
                     82:            return tsaplose (td, DR_ADDRESS, NULLCP,
                     83:                    "address translation failed");
                     84: 
                     85:        if (TNetListen (&pa -> pa_addr.sa_addr, td) == NOTOK)
                     86:            return NOTOK;
                     87: 
                     88:        if (!isatty (2)) {
                     89:            int     i;
                     90: 
                     91:            for (i = 0; i < 5; i++) {
                     92:                switch (fork ()) {
                     93:                    case NOTOK: 
                     94:                        sleep (5);
                     95:                        continue;
                     96: 
                     97:                    case OK: 
                     98:                        break;
                     99: 
                    100:                    default: 
                    101:                        _exit (0);
                    102:                }
                    103:                break;
                    104:            }
                    105: 
                    106:            (void) chdir ("/");
                    107: 
                    108:            if ((fd = open ("/dev/null", O_RDWR)) != NOTOK) {
                    109:                if (fd != 0)
                    110:                    (void) dup2 (fd, 0), (void) close (fd);
                    111:                (void) dup2 (0, 1);
                    112:                (void) dup2 (0, 2);
                    113:            }
                    114: 
                    115: #ifdef SETSID
                    116:            (void) setsid ();
                    117: #endif
                    118: #ifdef TIOCNOTTY
                    119:            if ((fd = open ("/dev/tty", O_RDWR)) != NOTOK) {
                    120:                (void) ioctl (fd, TIOCNOTTY, NULLCP);
                    121:                (void) close (fd);
                    122:            }
                    123: #else
                    124: #ifdef SYS5
                    125:            (void) setpgrp ();
                    126:            (void) signal (SIGINT, SIG_IGN);
                    127:            (void) signal (SIGQUIT, SIG_IGN);
                    128: #endif
                    129: #endif
                    130:            isodexport (NULLCP);        /* re-initialize logfiles */
                    131:        }
                    132:     }
                    133: 
                    134:     for (;;) {
                    135:        ifds = mask;
                    136:        if (TNetAccept (&vecp, vec, nfds, &ifds, NULLFD, NULLFD, NOTOK, td)
                    137:                == NOTOK) {
                    138:            (void) (*losefnx) (td);
                    139:            continue;
                    140:        }
                    141: 
                    142:        if (vecp > 0 && (fd = (*initfnx) (vecp, vec)) != NOTOK) {
                    143:            if (fd >= nfds)
                    144:                nfds = fd + 1;
                    145:            FD_SET (fd, &mask);
                    146:        }
                    147: 
                    148:        for (fd = 0; fd < nfds; fd++)
                    149:            if (FD_ISSET (fd, &ifds)) {
                    150:                if (workfnx == NULLIFP) {
                    151:                    (void) TNetClose (NULLTA, td);
                    152:                    return tsaplose (td, DR_OPERATION, NULLCP,
                    153:                                     "no worker routine for connected fd");
                    154:                }
                    155: 
                    156:                if ((*workfnx) (fd) == NOTOK) {
                    157:                    if (nfds == fd + 1)
                    158:                        nfds--;
                    159:                    FD_CLR (fd, &mask);
                    160:                    if (argc > 1) {
                    161:                        int         xd;
                    162: 
                    163:                        for (xd = 0; xd < nfds; xd++)
                    164:                            if (FD_ISSET (xd, &mask))
                    165:                                break;
                    166:                        if (xd >= nfds)
                    167:                            return OK;
                    168:                    }
                    169:                }
                    170:            }
                    171:     }
                    172: }

unix.superglobalmegacorp.com

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