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

io::stdin().read(buf) hangs when stdin is pipe on Linux #10237

Closed
stepancheg opened this issue Nov 2, 2013 · 3 comments
Closed

io::stdin().read(buf) hangs when stdin is pipe on Linux #10237

stepancheg opened this issue Nov 2, 2013 · 3 comments

Comments

@stepancheg
Copy link
Contributor

Rust stdlib hangs instead of reporting EOF when stdin is pipe.

Testing with script:

echo aaa | ./program

C program, does not hang, exits properly:

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

int main() {
    for (;;) {
        char buf[1];
        ssize_t r = read(STDIN_FILENO, buf, 1);
        if (r == 0) {
            break;
        } else if (r < 0) {
            perror("read");
            exit(1);
        } else {
            printf("%d\n", (int) buf[0]);
        }
    }
    return 0;
}

Rust program hangs on Linux, exits properly on OSX:

use std::rt::io::stdin;
use std::rt::io::Reader;

fn main() {
    let mut r = stdin();
    loop {
        let b = r.read_byte();
        if b.is_none() {
            break;
        }
        println!("{}", b.unwrap());
    }
}
@alexcrichton
Copy link
Member

This appears to not be our problem, but rather joyent/libuv#982. We'll need to update libuv once that gets fixed.

@alexcrichton
Copy link
Member

Hm, nevermind, I need to keep investigating.

@alexcrichton
Copy link
Member

Ah, narrowed it down, looks like that libuv bug

alexcrichton added a commit to alexcrichton/rust that referenced this issue Nov 8, 2013
It appears that uv's support for interacting with a stdio stream as a tty when
it's actually a pipe is pretty problematic. To get around this, promote a check
to see if the stream is a tty to the top of the tty constructor, and bail out
quickly if it's not identified as a tty.

Closes rust-lang#10237
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 27, 2023
…sed_as_pow, r=Jarcho

Fix styling in documentation for `suspicious_xor_used_as_pow` lint

There was a tab after the three leading slashes which caused the contents of the "Why is this bad?" section to be rendered as a code block.

**Before:**

<img width="626" alt="master" src="https://user-images.githubusercontent.com/4869194/214985546-4433d211-9fd3-450c-8ff7-2c0a47fccdc0.png">

**After:**

<img width="520" alt="fixed" src="https://user-images.githubusercontent.com/4869194/214985561-87255196-008c-4a1c-8cc8-c54b337d22a2.png">

The file still contains a lot of tabs but they don't affect the documentation.

---

changelog: [`suspicious_xor_used_as_pow`]: Fix styling in documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants