From 5a4a69cb58f78f56f8e45f2b254b9a00e4274cae Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 17 May 2018 12:40:33 +0200 Subject: stream_file: properly detect stdin as pipe There is some code that checks a FD for whether it is a regular file or not. If it's not a regular file, it e.g. enables use of poll() to avoid blocking forever. But this was done only for FDs that were open()ed by us, not from stdin special handling or fd://. Consequently, " | mpv -" could block the player. Fix this by moving the code and running for it on all FDs. Also, set p->regular_file even on mingw. --- stream/stream_file.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'stream/stream_file.c') diff --git a/stream/stream_file.c b/stream/stream_file.c index 8778e7e011..2d0e3457c0 100644 --- a/stream/stream_file.c +++ b/stream/stream_file.c @@ -309,7 +309,6 @@ static int open_f(stream_t *stream) openmode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; if (!write) m |= O_NONBLOCK; - p->use_poll = true; #endif p->fd = open(filename, m | O_BINARY, openmode); if (p->fd < 0) { @@ -317,25 +316,25 @@ static int open_f(stream_t *stream) filename, mp_strerror(errno)); return STREAM_ERROR; } - struct stat st; - if (fstat(p->fd, &st) == 0) { - if (S_ISDIR(st.st_mode)) { - p->use_poll = false; - stream->is_directory = true; - stream->allow_caching = false; - MP_INFO(stream, "This is a directory - adding to playlist.\n"); - } + p->close = true; + } + + struct stat st; + if (fstat(p->fd, &st) == 0) { + if (S_ISDIR(st.st_mode)) { + stream->is_directory = true; + stream->allow_caching = false; + MP_INFO(stream, "This is a directory - adding to playlist.\n"); + } else if (S_ISREG(st.st_mode)) { + p->regular_file = true; #ifndef __MINGW32__ - if (S_ISREG(st.st_mode)) { - p->use_poll = false; - p->regular_file = true; - // O_NONBLOCK has weird semantics on file locks; remove it. - int val = fcntl(p->fd, F_GETFL) & ~(unsigned)O_NONBLOCK; - fcntl(p->fd, F_SETFL, val); - } + // O_NONBLOCK has weird semantics on file locks; remove it. + int val = fcntl(p->fd, F_GETFL) & ~(unsigned)O_NONBLOCK; + fcntl(p->fd, F_SETFL, val); #endif + } else { + p->use_poll = true; } - p->close = true; } #ifdef __MINGW32__ -- cgit v1.2.3