~ft/gemnine

a194837a08fbac1792c9db77f5298a9a999ef6fb — Sigrid Solveig Haflínudóttir 4 months ago 7eb61c8
OCEXEC, open page in the same window
1 files changed, 13 insertions(+), 8 deletions(-)

M main.c
M main.c => main.c +13 -8
@@ 10,9 10,13 @@ page(Response *r)
{
	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 @@ page(Response *r)
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 @@ nextreq:
				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 @@ nextreq:
			}
		}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);