Commit:a194837a08fbac1792c9db77f5298a9a999ef6fb (browse)
Parent:7eb61c82c8f04b7f4a93ecbed287b48b51583620
Author:Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
Date:Wed Dec 9 17:33:46 CET 2020
Message:
OCEXEC, open page in the same window

main.c => main.c
@@ -10,9 +10,13 @@
 {
 	if(rfork(RFPROC|RFFDG|RFNOTEG|RFNOWAIT) == 0){
 		char tmp[32] = "/tmp/gem9XXXXXXXXXXX", *cmd;
+		int f;
 		mktemp(tmp);
-		cmd = smprint("cat >%s >[2]/dev/null; page -w %s; rm %s", tmp, tmp, tmp);
+		cmd = smprint("cat >%s; page %s; rm %s", tmp, tmp, tmp);
 		dup(r->fd, 0); close(r->fd);
+		dup((f = open("/dev/null", OWRITE)), 1);
+		dup(f, 2);
+		close(f);
 		execl("/bin/rc", "rc", "-c", cmd, nil);
 	}
 }
@@ -20,19 +24,20 @@
 void
 play(Response *r)
 {
-	int wfd;
-	char *wsys, tmp[64];
-
 	if(rfork(RFPROC|RFFDG|RFNOTEG|RFNOWAIT) == 0){
+		int wfd, f;
+		char *wsys, tmp[64];
 		snprint(tmp, sizeof(tmp), "new -pid %d -dx %d -dy %d", getpid(), 640, 480);
 		if ((wsys = getenv("wsys")) == nil)
 			exits("no wsys");
-		if ((wfd = open(wsys, ORDWR)) < 0 ||
+		if ((wfd = open(wsys, ORDWR|OCEXEC)) < 0 ||
 		    mount(wfd, -1, "/mnt/wsys", MREPL, tmp) < 0 ||
 		    bind("/mnt/wsys", "/dev", MBEFORE) < 0){
 			exits("wsys: %r");
 		}
 		dup(r->fd, 0); close(r->fd);
+		dup((f = open("/dev/null", OWRITE)), 1);
+		dup(f, 2);
 		execl("/bin/play", "play", nil);
 	}
 }
@@ -98,8 +103,8 @@
 				fprint(2, "unsupported MIME %q\n", r->mime);
 		}else if(r->prompt != nil){
 			if(wait)
-				close(open("/dev/text", OWRITE|OTRUNC));
-			if((fd = open("/dev/consctl", OWRITE)) >= 0){
+				close(open("/dev/text", OWRITE|OTRUNC|OCEXEC));
+			if((fd = open("/dev/consctl", OWRITE|OCEXEC)) >= 0){
 				write(fd, "holdon", 6);
 				print("%s\n", r->prompt);
 				Binit(&body, 0, OREAD);
@@ -123,7 +128,7 @@
 			}
 		}else{
 			if(wait)
-				close(open("/dev/text", OWRITE|OTRUNC));
+				close(open("/dev/text", OWRITE|OTRUNC|OCEXEC));
 			if(r->code < 20 || r->code >= 30){
 				if(r->code > 0)
 					fprint(2, "%U: %d %s\n", url, r->code, (r->meta && r->meta[0]) ? r->meta : r->status);