|
|
1.1 root 1: #include <sys/types.h>
2: #include <stdio.h>
3: #include <sys/ioctl.h>
4: #include <ipc.h>
5: #include <libc.h>
6: #include "defs.h"
7:
8: /* preeclared */
9: void dodialin();
10:
11: /* global */
12: int pid;
13:
14: /* imported */
15: extern char *av0;
16: extern int net_announce();
17: extern void net_accept();
18: extern void net_reject();
19: extern ipcinfo *net_listen();
20:
21: /* take alarm */
22: static int
23: ding() {
24: signal(SIGALRM, ding);
25: logevent("time out\n");
26: return;
27: }
28:
29: /* loop on calls into the CPU */
30: void
31: dodialin(mtpt, netname, param)
32: char *mtpt;
33: char *netname;
34: char *param;
35: {
36: int fd;
37: ipcinfo info;
38:
39: pid = getpid();
40:
41: /* plug into network name space */
42: for(;;){
43: info.name = netname;
44: info.user = getlogin();
45: info.param = param;
46: info.rfd = info.cfd = -1;
47: signal(SIGALRM, ding);
48: alarm(60);
49: fd = net_announce(&info);
50: alarm(0);
51: if (fd>=0)
52: break;
53: logconsole("%s: can't announce to network as %s (%s)\n",
54: av0, netname, errstr);
55: sleep(60);
56: }
57: logconsole("%s: announced to network as %s\n", av0, netname);
58:
59: /* loop on requests */
60: for(;;) {
61: ipcinfo *ip;
62: int rv;
63: static stretch newsrc;
64: static stretch newmyname;
65:
66: ip = net_listen(fd);
67: if (ip == NULL) {
68: logevent("broken listen (%s)\n", errstr);
69: break;
70: }
71: ip->flags |= IPC_CAREFUL;
72: if (ip->name==NULL || *ip->name=='\0')
73: ip->name = "login";
74: _strcat(&newsrc, mtpt, "!", ip->machine);
75: ip->machine = newsrc.ptr;
76: _strcat(&newmyname, mtpt, "!", ip->myname);
77: ip->myname = newmyname.ptr;
78: logcall("callin", ip);
79: if (ip->flags & IPC_CREAT) {
80: net_reject(ip, EINVAL, "bad request");
81: logstatus(ip);
82: continue;
83: }
84: signal(SIGALRM, ding);
85: alarm(30); /* avoid single-thread deadlock */
86: rv = ipcdial(ip);
87: alarm(0);
88: if (rv<0) {
89: net_reject(ip, errno, errstr);
90: logstatus(ip);
91: continue;
92: } else
93: close(rv);
94: errno = 0; errstr = "";
95: logstatus(ip);
96: net_accept(ip);
97: }
98: close(fd);
99: }
100:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.