2 * This file is part of the UCB release of Plan 9. It is subject to the license
3 * terms in the LICENSE file found in the top-level directory of this
4 * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
5 * part of the UCB release of Plan 9, including this file, may be copied,
6 * modified, propagated, or distributed except according to the terms contained
12 #include <parlib/parlib.h>
15 #include <iplib/iplib.h>
16 #include <iplib/icmp.h>
19 #include <parlib/spinlock.h>
20 #include <parlib/timing.h>
21 #include <parlib/tsc-compat.h>
22 #include <parlib/printf-ext.h>
23 #include <benchutil/alarm.h>
24 #include <ndblib/ndb.h>
27 #include <sys/types.h>
35 fprintf(stderr, "usage: listen1 [-tv] address cmd args...\n");
36 fprintf(stderr, "usage");
47 snprintf(buf, sizeof buf, "%s/remote", dir);
48 fd = open(buf, O_RDONLY);
51 n = read(fd, buf, sizeof(buf));
64 main(int argc, char **argv)
66 static char data[1024], dir[1024], ndir[1024];
73 fd = open("/dev/null", O_WRONLY);
81 printf("listen started\n");
82 ctl = announce9(argv[0], dir, 0);
84 fprintf(stderr, "announce %s: %r", argv[0]);
89 nctl = listen9(dir, ndir, 0);
91 fprintf(stderr, "listen %s: %r", argv[0]);
95 //switch(rfork(RFFDG|RFPROC|RFNOWAIT|RFENVG|RFNAMEG|RFNOTEG)){
98 reject9(nctl, ndir, "host overloaded");
102 fd = accept9(nctl, ndir);
104 fprintf(stderr, "accept %s: can't open %s/data: %r\n",
108 printf("incoming call for %s from %s in %s\n", argv[0],
109 remoteaddr(ndir), ndir);
110 //fprintf(nctl, "keepalive");
113 //putenv("net", ndir);
114 /* this is for children that open /dev/cons. Too bad.
115 snprintf(data, sizeof data, "%s/data", ndir);
116 bind(data, "/dev/cons", MREPL);
122 execv(argv[1], argv+1);
123 // if(argv[1][0] != '/')
124 // exec(smprintf("%s", argv[1]), argv+1);
125 fprintf(stderr, "exec: %r\n");
128 /* reap any available children */
129 while (waitpid(-1, 0, WNOHANG) > 0)