I question that this is correct. We are calling this from dup2() and the semantics are slightly different. fcntl is I suspect that by adding a shared routine and calling it from fcntl() and and dup2() we can fix this.