/* Return an error when trying to close the comm_sd file descriptor (pretend that it's closed). */ int close(int fd) { int retval, reterr; lock_comm_sd(); if (comm_sd >= 0 && comm_sd == fd) { retval = -1; reterr = EBADF; } else { retval = next_close(fd); reterr = errno; } unlock_comm_sd(); errno = reterr; return retval; }
int dup2(int oldfd, int newfd) { int retval, reterr; lock_comm_sd(); if (comm_sd >= 0 && comm_sd == newfd) { /* If dup fails, comm_sd gets set to -1, which is fine. */ comm_sd = dup(newfd); next_close(newfd); } retval = next_dup2(oldfd, newfd); reterr = errno; unlock_comm_sd(); errno = reterr; return retval; }