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)
{
FdPair in, out;
int d;
if((omode|OCEXEC) == ~0 && c->qid.path == 0){
in.aslong = perm;
out.aslong = ~0;
d = sysdup(in.fd[0], in.fd[1]);
if(d >= 0){
out.fd[1] = d;
errorl(nil, ~out.aslong);
/* ensure that fd.aslong never get ~0 value */
if(in.fd[1] == 0){
/* the requested fd is zero: out.fd[0] will
* prevent the whole fd.aslong to become -1
* 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);
}