Skip to content
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

subprocess opens stdin to /dev/null incorrectly #468

Closed
jsternberg opened this issue Dec 11, 2012 · 1 comment
Closed

subprocess opens stdin to /dev/null incorrectly #468

jsternberg opened this issue Dec 11, 2012 · 1 comment
Labels

Comments

@jsternberg
Copy link

After forking a new process, stdin in the child process is closed and re-opened to /dev/null. It's opened with the flag O_WRONLY. It should be opened with O_RDONLY. For example, if the below program is used within ninja, it will print -1.

#include <stdio.h>
#include <unistd.h>

int main() {
    int fd = fileno(stdin);
    char buf[4096];
    ssize_t bytes_read = read(fd, buf, 4096);
    printf("%ld\n", bytes_read);
    return 0;
}

If you do this in bash, it will print 0.

$ ./a.out < /dev/null

Ninja should probably do the same unless there's a particular reason why it opens stdin incorrectly (in which you could just save time by closing stdin and not opening /dev/null.

evmar added a commit that referenced this issue Dec 21, 2012
@evmar
Copy link
Collaborator

evmar commented Dec 21, 2012

Thanks for the detailed report and diagnosis!

@evmar evmar closed this as completed Dec 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants