summaryrefslogtreecommitdiff
path: root/sys/src/cmd/rc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-08-20 23:56:15 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-08-20 23:56:15 +0200
commit9a3a722ddeb73c7816bbbfa62f0d4accefdcae2b (patch)
treee0759b70d684f7b754d0b60fe60146454b99479a /sys/src/cmd/rc
parentd8cd5d197de6756443c4a5aa109ff78656ebc200 (diff)
rc: flush environment variables (update /env) before fork
on races... normal forks will all share the /env environment but not the in memory variables of rc. so when we would normally fork whoever does an exec (flush) first will override what the values of the /env variables are, *independent* of the variables that where actually modified *in* the process. when we flush *before* fork, then at least both processes start out with marked clean in memory variables and the processes will flush only the things they actually change.
Diffstat (limited to 'sys/src/cmd/rc')
-rw-r--r--sys/src/cmd/rc/havefork.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/sys/src/cmd/rc/havefork.c b/sys/src/cmd/rc/havefork.c
index ea34acc3d..322ec0ce7 100644
--- a/sys/src/cmd/rc/havefork.c
+++ b/sys/src/cmd/rc/havefork.c
@@ -12,10 +12,12 @@ Xasync(void)
int null = open("/dev/null", 0);
int pid;
char npid[10];
+
if(null<0){
Xerror("Can't open /dev/null\n");
return;
}
+ Updenv();
switch(pid = rfork(RFFDG|RFPROC|RFNOTEG)){
case -1:
close(null);
@@ -45,10 +47,12 @@ Xpipe(void)
int lfd = p->code[pc++].i;
int rfd = p->code[pc++].i;
int pfd[2];
+
if(pipe(pfd)<0){
Xerror("can't get pipe");
return;
}
+ Updenv();
switch(forkid = fork()){
case -1:
Xerror("try again");
@@ -91,6 +95,7 @@ Xbackq(void)
Xerror("can't make pipe");
return;
}
+ Updenv();
switch(pid = fork()){
case -1:
Xerror("try again");
@@ -152,6 +157,7 @@ Xpipefd(void)
char name[40];
int pfd[2];
int sidefd, mainfd;
+
if(pipe(pfd)<0){
Xerror("can't get pipe");
return;
@@ -164,6 +170,7 @@ Xpipefd(void)
sidefd = pfd[PRD];
mainfd = pfd[PWR];
}
+ Updenv();
switch(pid = fork()){
case -1:
Xerror("try again");
@@ -191,6 +198,8 @@ void
Xsubshell(void)
{
int pid;
+
+ Updenv();
switch(pid = fork()){
case -1:
Xerror("try again");