Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1128/4

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


Clean up plumbopen, try to create ports that don't exist.
 [rsc] --rw-rw-r-- M 374841 glenda sys 7080 Nov 28 07:17 sys/src/libplumb/mesg.c
	/n/sourcesdump/2005/1128/plan9/sys/src/libplumb/mesg.c:8,37 - 
	/n/sourcesdump/2005/1129/plan9/sys/src/libplumb/mesg.c:8,54
	  plumbopen(char *name, int omode)
	  {
	  	int fd, f;
	- 	char *s;
	- 	char buf[128];
	+ 	char *s, *plumber;
	+ 	char buf[128], err[ERRMAX];
	  
	  	if(name[0] == '/')
	  		return open(name, omode);
	- 	snprint(buf, sizeof buf, "/mnt/plumb/%s", name);
	+ 		
	+ 	/* find elusive plumber */
	+ 	if(access("/mnt/plumb/send", OWRITE) >= 0)
	+ 		plumber = "/mnt/plumb";
	+ 	else if(access("/mnt/term/mnt/plumb/send", OWRITE) >= 0)
	+ 		plumber = "/mnt/term/mnt/plumb";
	+ 	else{
	+ 		/* last resort: try mounting service */
	+ 		plumber = "/mnt/plumb";
	+ 		s = getenv("plumbsrv");
	+ 		if(s == nil)
	+ 			return -1;
	+ 		f = open(s, ORDWR);
	+ 		if(f < 0)
	+ 			return -1;
	+ 		if(mount(f, -1, "/mnt/plumb", MREPL, "") < 0){
	+ 			close(f);
	+ 			return -1;
	+ 		}
	+ 		if(access("/mnt/plumb/send", OWRITE) < 0)
	+ 			return -1;
	+ 	}
	+ 
	+ 	snprint(buf, sizeof buf, "%s/%s", plumber, name);
	  	fd = open(buf, omode);
	  	if(fd >= 0)
	  		return fd;
	- 	snprint(buf, sizeof buf, "/mnt/term/mnt/plumb/%s", name);
	- 	fd = open(buf, omode);
	+ 
	+ 	/* try creating port; used by non-standard plumb implementations */
	+ 	rerrstr(err, sizeof err);
	+ 	fd = create(buf, omode, 0600);
	  	if(fd >= 0)
	  		return fd;
	- 	/* try mounting service */
	- 	s = getenv("plumbsrv");
	- 	if(s == nil)
	- 		return -1;
	- 	f = open(s, ORDWR);
	- 	if(f < 0)
	- 		return -1;
	- 	if(mount(f, -1, "/mnt/plumb", MREPL, "") < 0)
	- 		return -1;
	- 	snprint(buf, sizeof buf, "/mnt/plumb/%s", name);
	- 	return open(buf, omode);
	+ 	errstr(err, sizeof err);
	+ 
	+ 	return -1;
	  }
	  
	  static int


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.