git: 9front

Download patch

ref: 78171a6fffbfb4aa10a87eab8e26ee2ca0ba1979
parent: da6bd0c1e2a342db9ff9616390a1fc982ca1711f
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Fri Oct 4 17:10:33 EDT 2013

page: avoid intermediate rc shell processes with using exec, move newwindow() before forking namespace

use exec to avoid intermediate rc processes.

avoid capturing old namespace in the waiting process by doing the
newwindow() call before it.

--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -299,10 +299,9 @@
 	if(p->data){
 		p->ext = p->data;
 		if(strcmp(p->ext, "ico") == 0)
-			snprint(nam, sizeof(nam), "%s -c", p->ext);
+			pipeline(fd, "exec %s -c", p->ext);
 		else
-			snprint(nam, sizeof(nam), "%s -t9", p->ext);
-		pipeline(fd, "%s", nam);
+			pipeline(fd, "exec %s -t9", p->ext);
 	}
 
 	/*
@@ -325,7 +324,7 @@
 {
 	seek(p->fd, 0, 0);
 	if(p->data){
-		pipeline(p->fd, "%s", (char*)p->data);
+		pipeline(p->fd, "exec %s", (char*)p->data);
 		p->data = nil;
 	}
 	p->open = popenfile;
@@ -339,7 +338,7 @@
 
 	seek(p->fd, 0, 0);
 	snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
-	snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", (char*)p->data, mnt);
+	snprint(cmd, sizeof(cmd), "exec %s -m %s /fd/0", (char*)p->data, mnt);
 	switch(rfork(RFPROC|RFMEM|RFFDG|RFREND)){
 	case -1:
 		close(p->fd);
@@ -812,11 +811,11 @@
 		p->open = nil;
 	else {
 		if(rotate)
-			pipeline(fd, "rotate -r %d", rotate);
+			pipeline(fd, "exec rotate -r %d", rotate);
 		if(resize.x)
-			pipeline(fd, "resize -x %d", resize.x);
+			pipeline(fd, "exec resize -x %d", resize.x);
 		else if(resize.y)
-			pipeline(fd, "resize -y %d", resize.y);
+			pipeline(fd, "exec resize -y %d", resize.y);
 	}
 	return fd;
 }
@@ -1489,6 +1488,11 @@
 		usage();
 	} ARGEND;
 
+	if(newwin > 0){
+		if(newwindow(nil) < 0)
+			sysfatal("newwindow: %r");
+	}
+
 	/*
 	 * so that we can stop all subprocesses with a note,
 	 * and to isolate rendezvous from other processes
@@ -1501,11 +1505,6 @@
 	}
 	cohort = getpid();
 	atexit(killcohort);
-
-	if(newwin > 0){
-		if(newwindow(nil) < 0)
-			sysfatal("newwindow: %r");
-	}
 	if(initdraw(drawerr, nil, argv0) < 0)
 		sysfatal("initdraw: %r");
 	paper = display->white;
--