devenv: fix ORCLOSE handling
when opening a /env file ORCLOSE, and the process exits, envgrp() would return nil can crash in envremove() because procexit will have set up->egrp to nil before calling closefgrp(). the solution is to capture the environment on open, keeping a reference in Chan.aux, so it doesnt matter on what process the close happens and a env chan will always refer to its original environment group.
This commit is contained in:
parent
38e1e5272f
commit
98363cb272
1 changed files with 19 additions and 10 deletions
|
@ -132,8 +132,10 @@ envopen(Chan *c, int omode)
|
||||||
runlock(eg);
|
runlock(eg);
|
||||||
}
|
}
|
||||||
c->mode = openmode(omode);
|
c->mode = openmode(omode);
|
||||||
c->flag |= COPEN;
|
incref(eg);
|
||||||
|
c->aux = eg;
|
||||||
c->offset = 0;
|
c->offset = 0;
|
||||||
|
c->flag |= COPEN;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +183,8 @@ envcreate(Chan *c, char *name, int omode, ulong)
|
||||||
|
|
||||||
wunlock(eg);
|
wunlock(eg);
|
||||||
poperror();
|
poperror();
|
||||||
|
incref(eg);
|
||||||
|
c->aux = eg;
|
||||||
c->offset = 0;
|
c->offset = 0;
|
||||||
c->mode = omode;
|
c->mode = omode;
|
||||||
c->flag |= COPEN;
|
c->flag |= COPEN;
|
||||||
|
@ -214,13 +217,19 @@ envremove(Chan *c)
|
||||||
static void
|
static void
|
||||||
envclose(Chan *c)
|
envclose(Chan *c)
|
||||||
{
|
{
|
||||||
/*
|
if(c->flag & COPEN){
|
||||||
* cclose can't fail, so errors from remove will be ignored.
|
/*
|
||||||
* since permissions aren't checked,
|
* cclose can't fail, so errors from remove will be ignored.
|
||||||
* envremove can't not remove it if its there.
|
* since permissions aren't checked,
|
||||||
*/
|
* envremove can't not remove it if its there.
|
||||||
if(c->flag & CRCLOSE)
|
*/
|
||||||
envremove(c);
|
if(c->flag & CRCLOSE && !waserror()){
|
||||||
|
envremove(c);
|
||||||
|
poperror();
|
||||||
|
}
|
||||||
|
closeegrp((Egrp*)c->aux);
|
||||||
|
c->aux = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static long
|
||||||
|
@ -350,7 +359,7 @@ closeegrp(Egrp *eg)
|
||||||
{
|
{
|
||||||
Evalue *e, *ee;
|
Evalue *e, *ee;
|
||||||
|
|
||||||
if(decref(eg) == 0){
|
if(decref(eg) == 0 && eg != &confegrp){
|
||||||
e = eg->ent;
|
e = eg->ent;
|
||||||
for(ee = e + eg->nent; e < ee; e++){
|
for(ee = e + eg->nent; e < ee; e++){
|
||||||
free(e->name);
|
free(e->name);
|
||||||
|
|
Loading…
Reference in a new issue