xz: Don't fail if stdout doesn't support O_NONBLOCK.

This is similar to the case with stdin.

Thanks to Brad Smith for the bug report and testing
on OpenBSD.
This commit is contained in:
Lasse Collin 2015-01-09 21:34:06 +02:00
parent 04bbc0c284
commit 4170edc914
1 changed files with 15 additions and 21 deletions

View File

@ -713,17 +713,10 @@ io_open_dest_real(file_pair *pair)
return true; return true;
} }
if ((stdout_flags & O_NONBLOCK) == 0) { if ((stdout_flags & O_NONBLOCK) == 0
if (fcntl(STDOUT_FILENO, F_SETFL, && fcntl(STDOUT_FILENO, F_SETFL,
stdout_flags | O_NONBLOCK) == -1) { stdout_flags | O_NONBLOCK) != -1)
message_error(_("Error setting O_NONBLOCK " restore_stdout_flags = true;
"on standard output: %s"),
strerror(errno));
return true;
}
restore_stdout_flags = true;
}
#endif #endif
} else { } else {
pair->dest_name = suffix_get_dest_name(pair->src_name); pair->dest_name = suffix_get_dest_name(pair->src_name);
@ -827,23 +820,24 @@ io_open_dest_real(file_pair *pair)
if (lseek(STDOUT_FILENO, 0, SEEK_END) == -1) if (lseek(STDOUT_FILENO, 0, SEEK_END) == -1)
return false; return false;
// O_NONBLOCK was set earlier in this function // Construct the new file status flags.
// so it must be kept here too. If this // If O_NONBLOCK was set earlier in this
// fcntl() call fails, we continue but won't // function, it must be kept here too.
int flags = stdout_flags & ~O_APPEND;
if (restore_stdout_flags)
flags |= O_NONBLOCK;
// If this fcntl() fails, we continue but won't
// try to create sparse output. The original // try to create sparse output. The original
// flags will still be restored if needed (to // flags will still be restored if needed (to
// unset O_NONBLOCK) when the file is finished. // unset O_NONBLOCK) when the file is finished.
if (fcntl(STDOUT_FILENO, F_SETFL, if (fcntl(STDOUT_FILENO, F_SETFL, flags) == -1)
(stdout_flags | O_NONBLOCK)
& ~O_APPEND) == -1)
return false; return false;
// Disabling O_APPEND succeeded. Mark // Disabling O_APPEND succeeded. Mark
// that the flags should be restored // that the flags should be restored
// in io_close_dest(). This quite likely was // in io_close_dest(). (This may have already
// already set when enabling O_NONBLOCK but // been set when enabling O_NONBLOCK.)
// just in case O_NONBLOCK was already set,
// set this again here.
restore_stdout_flags = true; restore_stdout_flags = true;
} else if (lseek(STDOUT_FILENO, 0, SEEK_CUR) } else if (lseek(STDOUT_FILENO, 0, SEEK_CUR)