Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1211/12

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


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


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.