xz: Don't fail if stdin doesn't support O_NONBLOCK.
It's a problem at least on OpenBSD which doesn't support O_NONBLOCK on e.g. /dev/null. I'm not surprised if it's a problem on other OSes too since this behavior is allowed in POSIX-1.2008. The code relying on this behavior was committed in June 2013 and included in 5.1.3alpha released on 2013-10-26. Clearly the development releases only get limited testing.
This commit is contained in:
parent
d2d484647d
commit
f0f1f6c723
|
@ -393,7 +393,10 @@ io_open_src_real(file_pair *pair)
|
||||||
#ifdef TUKLIB_DOSLIKE
|
#ifdef TUKLIB_DOSLIKE
|
||||||
setmode(STDIN_FILENO, O_BINARY);
|
setmode(STDIN_FILENO, O_BINARY);
|
||||||
#else
|
#else
|
||||||
// Enable O_NONBLOCK for stdin.
|
// Try to set stdout to non-blocking mode. It won't work
|
||||||
|
// e.g. on OpenBSD if stdout is e.g. /dev/null. In such
|
||||||
|
// case we proceed as if stdout were non-blocking anyway
|
||||||
|
// (in case of /dev/null it will be in practice).
|
||||||
stdin_flags = fcntl(STDIN_FILENO, F_GETFL);
|
stdin_flags = fcntl(STDIN_FILENO, F_GETFL);
|
||||||
if (stdin_flags == -1) {
|
if (stdin_flags == -1) {
|
||||||
message_error(_("Error getting the file status flags "
|
message_error(_("Error getting the file status flags "
|
||||||
|
@ -402,17 +405,10 @@ io_open_src_real(file_pair *pair)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((stdin_flags & O_NONBLOCK) == 0) {
|
if ((stdin_flags & O_NONBLOCK) == 0
|
||||||
if (fcntl(STDIN_FILENO, F_SETFL,
|
&& fcntl(STDIN_FILENO, F_SETFL,
|
||||||
stdin_flags | O_NONBLOCK) == -1) {
|
stdin_flags | O_NONBLOCK) != -1)
|
||||||
message_error(_("Error setting O_NONBLOCK "
|
|
||||||
"on standard input: %s"),
|
|
||||||
strerror(errno));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
restore_stdin_flags = true;
|
restore_stdin_flags = true;
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_POSIX_FADVISE
|
#ifdef HAVE_POSIX_FADVISE
|
||||||
// It will fail if stdin is a pipe and that's fine.
|
// It will fail if stdin is a pipe and that's fine.
|
||||||
|
|
Loading…
Reference in New Issue