Listensrv now in library. [rsc] --rw-rw-r-- M 84741 glenda sys 14440 Dec 11 21:33 sys/src/cmd/wikifs/fs.c /n/sourcesdump/2005/1211/plan9/sys/src/cmd/wikifs/fs.c:807,895 - /n/sourcesdump/2005/1212/plan9/sys/src/cmd/wikifs/fs.c:807,812 exits("usage"); } - char* - getremotesys(char *ndir) - { - char buf[128], *serv, *sys; - int fd, n; - - snprint(buf, sizeof buf, "%s/remote", ndir); - sys = nil; - fd = open(buf, OREAD); - if(fd >= 0){ - n = read(fd, buf, sizeof(buf)-1); - if(n>0){ - buf[n-1] = 0; - serv = strchr(buf, '!'); - if(serv) - *serv = 0; - sys = estrdup(buf); - } - close(fd); - } - if(sys == nil) - sys = estrdup("unknown"); - return sys; - } - - void - listensrv(Srv *os, char *addr) - { - int ctl, data, nctl; - char ndir[NETPATHLEN], dir[NETPATHLEN]; - Srv *s; - - switch(rfork(RFPROC|RFMEM|RFNOWAIT)){ - case -1: - sysfatal("rfork: %r"); - default: - return; - case 0: - break; - } - - ctl = announce(addr, dir); - if(ctl < 0){ - fprint(2, "wikifs announce %s: %r", addr); - _exits(0); - } - - for(;;){ - nctl = listen(dir, ndir); - if(nctl < 0){ - fprint(2, "wikifs listen %s: %r", addr); - _exits(0); - } - - switch(rfork(RFPROC|RFMEM|RFNOWAIT)){ - case -1: - fprint(2, "rfork answerer: %r\n"); - continue; - default: - continue; - case 0: - break; - } - - data = accept(ctl, ndir); - close(nctl); - if(data < 0){ - fprint(2, "wikifs accept %s: %r\n", ndir); - _exits(nil); - } - - s = emalloc(sizeof *s); - *s = *os; - s->aux = getremotesys(ndir); - s->infd = s->outfd = data; - srv(s); - close(data); - free(s->aux); - free(s); - _exits(nil); - } - } - void main(int argc, char **argv) { [rsc] --rw-rw-r-- M 84741 glenda sys 14440 Dec 11 21:33 sys/src/cmd/wikifs/fs.c