ref: 319bb17e1c1349ffb3c51c4b7654142050984772
parent: e220636fd305f378a27cfa485d39e7588d6dc03c
author: cinap_lenrek <[email protected]>
date: Sun Sep 15 12:04:32 EDT 2013
vncs: fix cmdpid fork bug we cannot do: cmdpid = rfork(... RFMEM); because cmdpid is a global variable in the data segment and hence shared between parent and child process. use a temporary variable on the stack.
--- a/sys/src/cmd/vnc/vncs.c
+++ b/sys/src/cmd/vnc/vncs.c
@@ -87,7 +87,7 @@
void
main(int argc, char **argv)
{
- int altnet, baseport, cfd, display, exnum, fd, h, killing, w;
+ int altnet, baseport, cfd, display, exnum, fd, pid, h, killing, w;
char adir[NETPATHLEN], ldir[NETPATHLEN];
char net[NETPATHLEN], *p;
char *kbdfs[] = { "/bin/aux/kbdfs", "-dq", nil };
@@ -197,8 +197,8 @@
sysfatal("mounter: %r");
close(fd);
- cmdpid = rfork(RFPROC|RFMEM|RFFDG|RFNOTEG);
- switch(cmdpid){
+ pid = rfork(RFPROC|RFMEM|RFFDG|RFNOTEG);
+ switch(pid){
case -1:
sysfatal("rfork: %r");
break;
@@ -211,8 +211,8 @@
open("/dev/cons", OWRITE);
/* start and mount kbdfs */
- cmdpid = rfork(RFPROC|RFMEM|RFFDG|RFREND);
- switch(cmdpid){
+ pid = rfork(RFPROC|RFMEM|RFFDG|RFREND);
+ switch(pid){
case -1:
sysfatal("rfork: %r");
break;
@@ -221,9 +221,9 @@
fprint(2, "exec %s: %r\n", kbdfs[0]);
_exits("kbdfs");
}
- if(waitpid() != cmdpid){
+ if(waitpid() != pid){
rendezvous(&kbdin, nil);
- sysfatal("%s: %r", kbdfs[0]);
+ sysfatal("waitpid: %s: %r", kbdfs[0]);
}
rendezvous(&kbdin, nil);
@@ -240,6 +240,7 @@
fprint(2, "exec %s: %r\n", argv[0]);
_exits(nil);
}
+ cmdpid = pid;
/* wait for kbdfs to get mounted */
rendezvous(&kbdin, nil);