-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
reopen STDIN and STDOUT as dev/null #28
base: master
Are you sure you want to change the base?
Conversation
But STDIN is read only while STDOUT and STDERR are write only. |
Good point! A couple of typos to fix is all it needs then! |
close(0); | ||
if (dup2(fd, STDIN_FILENO) != STDIN_FILENO) | ||
return false; | ||
if (fd > STDERR_FILENO) close(fd); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be "if (fd == STDIN_FILENO)" right?
Nope. If the new fd is already open, dup2() would close it before reusing. If the old fd is equal to the new fd dup2() does nothing. So there is no point to close fd if it is below or equal to STDERR_FILENO. |
Maxim Zakharov [email protected] writes:
Well, if you're assuming the continuity of stdin, stdout, and stderr,
Cheers, |
It looks very good, but perhaps we need to add a comment that this code is rely on unix's property to always use lowest unused file descriptor. As I remember, Windows do not state such guaranty. |
Maxim Zakharov [email protected] writes:
Hmm, does this code even work on Windows at all? If so, might be nice Thanks, |
It is better to reopen STDIN and STDOUT as well as they may be used in a third-party application using ccan.