kernel: devdup: fix dup(n, 0)

Completes e1a14b49be
This commit is contained in:
Giacomo Tesio 2017-01-24 22:16:41 +01:00
parent edd84db070
commit 19bf511603
1 changed files with 11 additions and 6 deletions

View File

@ -64,16 +64,21 @@ static Chan*
dupcreate(Chan* c, char* name, unsigned long omode, unsigned long perm) dupcreate(Chan* c, char* name, unsigned long omode, unsigned long perm)
{ {
FdPair in, out; FdPair in, out;
int d;
if((omode|OCEXEC) == ~0 && c->qid.path == 0){ if((omode|OCEXEC) == ~0 && c->qid.path == 0){
in.aslong = perm; in.aslong = perm;
out.aslong = ~0; /* ensure that fd.aslong never get ~0 value */
d = sysdup(in.fd[0], in.fd[1]); if(in.fd[1] == 0){
if(d >= 0){ /* the requested fd is zero: out.fd[0] will
out.fd[1] = d; * prevent the whole fd.aslong to become -1
errorl(nil, ~out.aslong); * if the operation succeed
*/
out.fd[0] = -1;
} else {
out.fd[0] = 0;
} }
out.fd[1] = sysdup(in.fd[0], in.fd[1]);
errorl(nil, ~out.aslong);
} }
error(Eperm); error(Eperm);
} }