1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-18 05:37:04 +00:00

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.
This commit is contained in:
wm4 2018-05-17 12:40:33 +02:00 committed by sfan5
parent fba98cfb05
commit 5a4a69cb58

View File

@ -309,7 +309,6 @@ static int open_f(stream_t *stream)
openmode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; openmode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
if (!write) if (!write)
m |= O_NONBLOCK; m |= O_NONBLOCK;
p->use_poll = true;
#endif #endif
p->fd = open(filename, m | O_BINARY, openmode); p->fd = open(filename, m | O_BINARY, openmode);
if (p->fd < 0) { if (p->fd < 0) {
@ -317,25 +316,25 @@ static int open_f(stream_t *stream)
filename, mp_strerror(errno)); filename, mp_strerror(errno));
return STREAM_ERROR; return STREAM_ERROR;
} }
p->close = true;
}
struct stat st; struct stat st;
if (fstat(p->fd, &st) == 0) { if (fstat(p->fd, &st) == 0) {
if (S_ISDIR(st.st_mode)) { if (S_ISDIR(st.st_mode)) {
p->use_poll = false;
stream->is_directory = true; stream->is_directory = true;
stream->allow_caching = false; stream->allow_caching = false;
MP_INFO(stream, "This is a directory - adding to playlist.\n"); MP_INFO(stream, "This is a directory - adding to playlist.\n");
} } else if (S_ISREG(st.st_mode)) {
#ifndef __MINGW32__
if (S_ISREG(st.st_mode)) {
p->use_poll = false;
p->regular_file = true; p->regular_file = true;
#ifndef __MINGW32__
// O_NONBLOCK has weird semantics on file locks; remove it. // O_NONBLOCK has weird semantics on file locks; remove it.
int val = fcntl(p->fd, F_GETFL) & ~(unsigned)O_NONBLOCK; int val = fcntl(p->fd, F_GETFL) & ~(unsigned)O_NONBLOCK;
fcntl(p->fd, F_SETFL, val); fcntl(p->fd, F_SETFL, val);
}
#endif #endif
} else {
p->use_poll = true;
} }
p->close = true;
} }
#ifdef __MINGW32__ #ifdef __MINGW32__