shithub: riscv

Download patch

ref: c50bef06dda0c5186fa6653a834550ab03856fe5
parent: 9d8657023ecb154ca8ad3ab53fde5ac54440e42e
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Mon Oct 24 13:10:44 EDT 2011

can't use rfork without RFMEM from shared memory procs and then use heap as it might be cow in a inconsistent state

--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -747,7 +747,7 @@
 
 void filter(char *cmd, int fd){
 	flushimage(display, 1);
-	switch(rfork(RFFDG|RFPROC|RFNOWAIT)){
+	switch(rfork(RFFDG|RFPROC|RFMEM|RFNOWAIT)){
 	case -1:
 		message("Can't fork!");
 		break;
@@ -756,16 +756,13 @@
 		dup(fd, 0);
 		close(fd);
 		execl("/bin/rc", "rc", "-c", cmd, 0);
-		message("Can't exec /bin/rc!");
 		_exits(0);
-	default:
-		break;
 	}
 	close(fd);
 }
 void gettext(Www *w, int fd, int type){
 	flushimage(display, 1);
-	switch(rfork(RFFDG|RFPROC|RFNOWAIT|RFMEM)){
+	switch(rfork(RFFDG|RFPROC|RFMEM|RFNOWAIT)){
 	case -1:
 		message("Can't fork, please wait");
 		break;
--- a/sys/src/cmd/page.c
+++ b/sys/src/cmd/page.c
@@ -201,7 +201,10 @@
 		dup(nullfd, fd);
 		return;
 	}
-	switch(rfork(RFPROC|RFFDG|RFREND|RFNOWAIT)){
+	va_start(arg, fmt);
+	vsnprint(buf, sizeof buf, fmt, arg);
+	va_end(arg);
+	switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
 	case -1:
 		close(pfd[0]);
 		close(pfd[1]);
@@ -208,9 +211,6 @@
 		goto Err;
 	case 0:
 		dupfds(fd, pfd[1], 2, -1);
-		va_start(arg, fmt);
-		vsnprint(buf, sizeof buf, fmt, arg);
-		va_end(arg);
 		argv[0] = "rc";
 		argv[1] = "-c";
 		argv[2] = buf;
@@ -286,7 +286,8 @@
 
 	seek(p->fd, 0, 0);
 	snprint(mnt, sizeof(mnt), "/n/tapefs.%.12d%.8lux", getpid(), (ulong)p);
-	switch(rfork(RFPROC|RFFDG|RFREND)){
+	snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", p->data, mnt);
+	switch(rfork(RFPROC|RFMEM|RFFDG|RFREND)){
 	case -1:
 		close(p->fd);
 		p->fd = -1;
@@ -295,7 +296,6 @@
 		dupfds(p->fd, 1, 2, -1);
 		argv[0] = "rc";
 		argv[1] = "-c";
-		snprint(cmd, sizeof(cmd), "%s -m %s /fd/0", p->data, mnt);
 		argv[2] = cmd;
 		argv[3] = nil;
 		exec("/bin/rc", argv);
@@ -374,7 +374,7 @@
 
 	if(pipe(pfd) < 0)
 		return -1;
-	switch(rfork(RFPROC|RFFDG|RFMEM|RFNOWAIT)){
+	switch(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT)){
 	case -1:
 		close(pfd[0]);
 		close(pfd[1]);
@@ -449,7 +449,8 @@
 		goto Err1;
 	}
 
-	switch(rfork(RFPROC|RFFDG|RFREND|RFNOWAIT)){
+	argv[0] = p->data;
+	switch(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT)){
 	case -1:
 		goto Err2;
 	case 0:
@@ -457,8 +458,8 @@
 			dupfds(pin[1], pout[1], nullfd, pdat[1], ifd, -1);
 		else
 			dupfds(nullfd, nullfd, nullfd, pdat[1], ifd, -1);
-		if(p->data)
-			pipeline(4, "%s", (char*)p->data);
+		if(argv[0])
+			pipeline(4, "%s", argv[0]);
 		argv[0] = "gs";
 		argv[1] = "-q";
 		argv[2] = "-sDEVICE=plan9";
@@ -570,7 +571,7 @@
 		close(ifd[1]);
 		return -1;
 	}
-	if(rfork(RFPROC|RFFDG|RFREND|RFNOWAIT) == 0){
+	if(rfork(RFPROC|RFMEM|RFFDG|RFREND|RFNOWAIT) == 0){
 		dupfds(ifd[1], ofd[1], 2, -1);
 		argv[0] = "file";
 		argv[1] = "-m";
@@ -579,7 +580,7 @@
 	}
 	close(ifd[1]);
 	close(ofd[1]);
-	if(rfork(RFPROC|RFFDG|RFNOWAIT) == 0){
+	if(rfork(RFPROC|RFMEM|RFFDG|RFNOWAIT) == 0){
 		dupfds(ifd[0], -1);
 		write(0, buf, nbuf);
 		exits(nil);
@@ -1126,7 +1127,7 @@
 	qlock(p);
 	if((fd = openpage(p)) < 0)
 		goto Out;
-	if(rfork(RFPROC|RFFDG|RFREND|RFENVG|RFNOTEG|RFNOWAIT) == 0){
+	if(rfork(RFPROC|RFMEM|RFFDG|RFENVG|RFNOTEG|RFNOWAIT) == 0){
 		dupfds(fd, 1, 2, -1);
 		snprint(nam, sizeof nam, "/bin/%s", argv0);
 		argv[0] = argv0;