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

1.1       root        1: /* acserver2.c - generic server dispatch */
                      2: 
                      3: #ifndef        lint
                      4: static char *rcsid = "$Header: /f/osi/acsap/RCS/acserver2.c,v 7.2 90/07/09 14:30:46 mrose Exp $";
                      5: #endif
                      6: 
                      7: /* 
                      8:  * $Header: /f/osi/acsap/RCS/acserver2.c,v 7.2 90/07/09 14:30:46 mrose Exp $
                      9:  *
                     10:  *
                     11:  * $Log:       acserver2.c,v $
                     12:  * Revision 7.2  90/07/09  14:30:46  mrose
                     13:  * sync
                     14:  * 
                     15:  * Revision 7.1  90/02/19  13:07:07  mrose
                     16:  * update
                     17:  * 
                     18:  * Revision 7.0  89/11/23  21:22:03  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: static int     is_nfds;
                     51: static fd_set  is_mask;
                     52: static char    is_single;
                     53:                
                     54: /*  */
                     55: 
                     56: int    iserver_init (argc, argv, aei, initfnx, td)
                     57: int    argc;
                     58: char   **argv;
                     59: AEI    aei;
                     60: IFP    initfnx;
                     61: struct TSAPdisconnect *td;
                     62: {
                     63:     int        fd;
                     64: 
                     65:     isodetailor (NULLCP, 0);
                     66: 
                     67:     is_nfds = 0;
                     68:     FD_ZERO (&is_mask);
                     69: 
                     70:     if (argc > 1) {
                     71:        is_single = 1;
                     72:        if ((fd = (*initfnx) (argc, argv)) == NOTOK)
                     73:            return tsaplose (td, DR_NETWORK, NULLCP, "initialization failed");
                     74: 
                     75:        is_nfds = fd + 1;
                     76:        FD_SET (fd, &is_mask);
                     77:     }
                     78:     else {
                     79:        struct PSAPaddr *pa;
                     80:        is_single = 0;
                     81: 
                     82:        if ((pa = aei2addr (aei)) == NULLPA)
                     83:            return tsaplose (td, DR_ADDRESS, NULLCP,
                     84:                    "address translation failed");
                     85: 
                     86:        if (TNetListen (&pa -> pa_addr.sa_addr, td) == NOTOK)
                     87:            return NOTOK;
                     88: 
                     89:        if (!isatty (2)) {
                     90:            int     i;
                     91: 
                     92:            for (i = 0; i < 5; i++) {
                     93:                switch (fork ()) {
                     94:                    case NOTOK: 
                     95:                        sleep (5);
                     96:                        continue;
                     97: 
                     98:                    case OK: 
                     99:                        break;
                    100: 
                    101:                    default: 
                    102:                        _exit (0);
                    103:                }
                    104:                break;
                    105:            }
                    106: 
                    107:            (void) chdir ("/");
                    108: 
                    109:            if ((fd = open ("/dev/null", O_RDWR)) != NOTOK) {
                    110:                if (fd != 0)
                    111:                    (void) dup2 (fd, 0), (void) close (fd);
                    112:                (void) dup2 (0, 1);
                    113:                (void) dup2 (0, 2);
                    114:            }
                    115: 
                    116: #ifdef SETSID
                    117:            (void) setsid ();
                    118: #endif
                    119: #ifdef TIOCNOTTY
                    120:            if ((fd = open ("/dev/tty", O_RDWR)) != NOTOK) {
                    121:                (void) ioctl (fd, TIOCNOTTY, NULLCP);
                    122:                (void) close (fd);
                    123:            }
                    124: #else
                    125: #ifdef SYS5
                    126:            (void) setpgrp ();
                    127:            (void) signal (SIGINT, SIG_IGN);
                    128:            (void) signal (SIGQUIT, SIG_IGN);
                    129: #endif
                    130: #endif
                    131:            isodexport (NULLCP);        /* re-initialize logfiles */
                    132:        }
                    133:     }
                    134: 
                    135:     return OK;
                    136: }
                    137: 
                    138: /*  */
                    139: 
                    140: int iserver_wait (initfnx, workfnx, losefnx, nfds, rfds, wfds, efds, secs, td)
                    141: IFP    initfnx,
                    142:        workfnx,
                    143:        losefnx;
                    144: int    nfds;
                    145: fd_set *rfds,
                    146:        *wfds,
                    147:        *efds;
                    148: int    secs;
                    149: struct TSAPdisconnect *td;
                    150: {
                    151:     int            fd,
                    152:            vecp;
                    153:     fd_set  ifds,
                    154:            ofds,
                    155:            xfds;
                    156:     char   *vec[4];
                    157: 
                    158:     ifds = is_mask;    /* struct copy */
                    159:     FD_ZERO (&ofds);
                    160:     FD_ZERO (&xfds);
                    161:     if (is_nfds > nfds)
                    162:        nfds = is_nfds + 1;
                    163: 
                    164:     if (rfds)
                    165:        for (fd = 0; fd < nfds; fd++)
                    166:            if (FD_ISSET (fd, rfds))
                    167:                FD_SET (fd, &ifds);
                    168:     if (wfds)
                    169:        ofds = *wfds;
                    170:     if (efds)
                    171:        xfds = *efds;
                    172: 
                    173:     if (TNetAccept (&vecp, vec, nfds, &ifds, &ofds, &xfds, secs, td)
                    174:            == NOTOK) {
                    175:        (void) (*losefnx) (td);
                    176: 
                    177:        return OK;
                    178:     }
                    179:     if (wfds)
                    180:        *wfds = ofds;
                    181:     if (efds)
                    182:        *efds = xfds;
                    183: 
                    184:     if (vecp > 0 && (fd = (*initfnx) (vecp, vec)) != NOTOK) {
                    185:        if (fd >= is_nfds)
                    186:            is_nfds = fd + 1;
                    187:        FD_SET (fd, &is_mask);
                    188:     }
                    189: 
                    190:     for (fd = 0; fd < nfds; fd++)
                    191:        if (FD_ISSET (fd, &is_mask) && FD_ISSET (fd, &ifds)) {
                    192:            if (workfnx == NULLIFP) {
                    193:                (void) TNetClose (NULLTA, td);
                    194:                return tsaplose (td, DR_OPERATION, NULLCP,
                    195:                                 "no worker routine for connected fd");
                    196:            }
                    197:            FD_CLR (fd, &ifds);
                    198:            if ((*workfnx) (fd) == NOTOK) {
                    199:                FD_CLR (fd, &is_mask);
                    200:                if (is_nfds == fd + 1)
                    201:                    is_nfds--;
                    202: 
                    203:                if (is_single) {
                    204:                    int     xd;
                    205: 
                    206:                    for (xd = 0; xd < nfds; xd++)
                    207:                        if (FD_ISSET (xd, &is_mask))
                    208:                            break;
                    209:                    if (rfds)
                    210:                        FD_ZERO (rfds);
                    211:                    if (xd >= is_nfds)
                    212:                        return DONE;
                    213:                }
                    214:            }
                    215:        }
                    216:     if (rfds)
                    217:        *rfds = ifds;
                    218:     return OK;
                    219: }
                    220: 
                    221: /*  */
                    222: 
                    223: fd_set iserver_mask ()
                    224: {
                    225:     return is_mask;
                    226: }

unix.superglobalmegacorp.com

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