Annotation of researchv10no/ipc/mgrs/common/dialin.c, revision 1.1

1.1     ! root        1: #include <sys/param.h>
        !             2: #include <stdio.h>
        !             3: #include <sys/filio.h>
        !             4: #include <signal.h>
        !             5: #include <ipc.h>
        !             6: #include <libc.h>
        !             7: #include <setjmp.h>
        !             8: #include "defs.h"
        !             9: 
        !            10: jmp_buf xyz;
        !            11: 
        !            12: /* preeclared */
        !            13: void dodialin();
        !            14: 
        !            15: /* global */
        !            16: int pid;
        !            17: int debug;
        !            18: 
        !            19: /* imported */
        !            20: extern char *av0;
        !            21: extern int net_announce();
        !            22: extern void net_accept();
        !            23: extern void net_reject();
        !            24: extern ipcinfo *net_listen();
        !            25: 
        !            26: /* take alarm */
        !            27: static int
        !            28: ding() {
        !            29:        logevent("time out\n");
        !            30:        longjmp(xyz, 1);
        !            31: }
        !            32: 
        !            33: /* loop on calls into the CPU */
        !            34: void
        !            35: dodialin(mtpt, netname, param)
        !            36:        char *mtpt;
        !            37:        char *netname;
        !            38:        char *param;
        !            39: {
        !            40:        int fd;
        !            41:        ipcinfo info;
        !            42: 
        !            43:        signal(SIGPIPE, SIG_IGN);
        !            44:        pid = getpid();
        !            45: 
        !            46:        /*
        !            47:         *  plug into network name space
        !            48:         */
        !            49:        for(;;){
        !            50:                info.name = netname;
        !            51:                info.user = getlogin();
        !            52:                info.param = param;
        !            53:                info.rfd = info.cfd = -1;
        !            54: 
        !            55:                /*
        !            56:                 *  announce yourrself.  alarm is for avoiding
        !            57:                 *  the single thread deadlock
        !            58:                 */
        !            59:                signal(SIGALRM, ding);
        !            60:                alarm(30);
        !            61:                if(setjmp(xyz)==0)
        !            62:                        fd = net_announce(&info);
        !            63:                else
        !            64:                        fd = -1;
        !            65:                alarm(0);
        !            66:                signal(SIGALRM, SIG_IGN);
        !            67:                if (fd>=0)
        !            68:                        break;
        !            69: 
        !            70:                /*
        !            71:                 *  it didn't work, complain and try again
        !            72:                 */
        !            73:                logconsole("%s: can't announce to network as %s (%s)\n",
        !            74:                        av0, netname, errstr);
        !            75:                sleep(60);
        !            76:        }
        !            77:        if (*info.machine)
        !            78:                netname = info.machine;
        !            79:        logconsole("%s: announced to network as %s\n", av0, netname);
        !            80: 
        !            81:        /* loop on requests */
        !            82:        for(;;) {
        !            83:                ipcinfo *ip;
        !            84:                int rv;
        !            85:                static stretch newsrc;
        !            86:                static stretch newmyname;
        !            87: 
        !            88:                /*
        !            89:                 *  get a request from the network
        !            90:                 */
        !            91:                ip = net_listen(fd);
        !            92:                if (ip == NULL) {
        !            93:                        logevent("broken listen (%s)\n", errstr);
        !            94:                        break;
        !            95:                }
        !            96:                if(debug)
        !            97:                        logevent("dialin: rcved\n");
        !            98: 
        !            99:                /*
        !           100:                 *  be careful not to write on an unmounted file
        !           101:                 */
        !           102:                ip->flags |= IPC_CAREFUL;
        !           103: 
        !           104:                /*
        !           105:                 *  default service is login
        !           106:                 */
        !           107:                if (ip->name==NULL || *ip->name=='\0')
        !           108:                        ip->name = "login";
        !           109: 
        !           110:                /*
        !           111:                 *  tack network name onto requestor, requestee, and
        !           112:                 *  name of this service.
        !           113:                 */
        !           114:                _strcat(&newsrc, mtpt, "!", ip->machine);
        !           115:                ip->machine = newsrc.ptr;
        !           116:                _strcat(&newmyname, mtpt, "!", ip->myname);
        !           117:                ip->myname = newmyname.ptr;
        !           118: 
        !           119:                /*
        !           120:                 *  pass request to internal service provider.  once
        !           121:                 *  again avoid internal single thread deadlock.
        !           122:                 */
        !           123:                if (ip->flags & IPC_CREAT) {
        !           124:                        net_reject(ip, EINVAL, "bad request");
        !           125:                        logstatus("in", ip);
        !           126:                        continue;
        !           127:                }
        !           128:                if(setjmp(xyz)==0){
        !           129:                        signal(SIGALRM, ding);
        !           130:                        alarm(30);
        !           131:                        rv = ipcdial(ip);
        !           132:                        alarm(0);
        !           133:                } else {
        !           134:                        /* here after timeout */
        !           135:                        rv = -1;
        !           136:                }
        !           137:                signal(SIGALRM, SIG_IGN);
        !           138:                if(debug)
        !           139:                        logevent("dialin: passed\n");
        !           140:                if (rv<0) {
        !           141:                        net_reject(ip, errno, errstr);
        !           142:                        logstatus("in", ip);
        !           143:                        continue;
        !           144:                } else
        !           145:                        close(rv);
        !           146: 
        !           147:                /*
        !           148:                 *  tell requestor that the connection was accepted
        !           149:                 */
        !           150:                errno = 0; errstr = "";
        !           151:                logstatus("in", ip);
        !           152:                net_accept(ip);
        !           153:        }
        !           154:        close(fd);
        !           155: }

unix.superglobalmegacorp.com

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