diff options
| author | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-26 22:49:07 +0200 |
|---|---|---|
| committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2014-05-26 22:49:07 +0200 |
| commit | b672403c6d9ad0029782a71c2b9e4bbb8fe7fbf1 (patch) | |
| tree | a0e3a081ca15534f93e712ea57c12340552f2373 | |
| parent | 235cc0747d3909c4d3eac307fa58664896eb5951 (diff) | |
| parent | 9ebbfae28b3be0ffcc2122024441cac2f0025c09 (diff) | |
| download | plan9front-b672403c6d9ad0029782a71c2b9e4bbb8fe7fbf1.tar.xz | |
merge
| -rw-r--r-- | sys/src/9/port/devproc.c | 39 | ||||
| -rw-r--r-- | sys/src/9/port/sysfile.c | 18 |
2 files changed, 22 insertions, 35 deletions
diff --git a/sys/src/9/port/devproc.c b/sys/src/9/port/devproc.c index 1258e46d8..db229802d 100644 --- a/sys/src/9/port/devproc.c +++ b/sys/src/9/port/devproc.c @@ -1270,39 +1270,34 @@ procstopwait(Proc *p, int ctl) error(Eprocdied); } -static void -procctlcloseone(Proc *p, Fgrp *f, int fd) -{ - Chan *c; - - c = f->fd[fd]; - if(c == nil) - return; - f->fd[fd] = nil; - unlock(f); - qunlock(&p->debug); - cclose(c); - qlock(&p->debug); - lock(f); -} - void procctlclosefiles(Proc *p, int all, int fd) { - int i; Fgrp *f; + Chan *c; + if(fd < 0) + error(Ebadfd); f = p->fgrp; if(f == nil) error(Eprocdied); lock(f); f->ref++; - if(all) - for(i = 0; i < f->maxfd; i++) - procctlcloseone(p, f, i); - else - procctlcloseone(p, f, fd); + while(fd <= f->maxfd){ + c = f->fd[fd]; + if(c != nil){ + f->fd[fd] = nil; + unlock(f); + qunlock(&p->debug); + cclose(c); + qlock(&p->debug); + lock(f); + } + if(!all) + break; + fd++; + } unlock(f); closefgrp(f); } diff --git a/sys/src/9/port/sysfile.c b/sys/src/9/port/sysfile.c index 9dfeb5371..a354d6e96 100644 --- a/sys/src/9/port/sysfile.c +++ b/sys/src/9/port/sysfile.c @@ -292,28 +292,20 @@ sysopen(va_list list) void fdclose(int fd, int flag) { - int i; Chan *c; Fgrp *f = up->fgrp; lock(f); c = f->fd[fd]; - if(c == 0){ - /* can happen for users with shared fd tables */ + if(c == nil || (flag != 0 && (c->flag&flag) == 0)){ unlock(f); return; } - if(flag){ - if(c==0 || !(c->flag&flag)){ - unlock(f); - return; - } + f->fd[fd] = nil; + if(fd == f->maxfd){ + while(fd > 0 && f->fd[fd] == nil) + f->maxfd = --fd; } - f->fd[fd] = 0; - if(fd == f->maxfd) - for(i=fd; --i>=0 && f->fd[i]==0; ) - f->maxfd = i; - unlock(f); cclose(c); } |
