aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2015-01-09 21:34:06 +0200
committerLasse Collin <lasse.collin@tukaani.org>2015-01-09 21:34:06 +0200
commit4170edc914655310d2363baccf5e615e09b04911 (patch)
tree0e6e90f4c413506743bf87e579ad0bc489faf33c /src
parentxz: Fix a memory leak in DOS-specific code. (diff)
downloadxz-4170edc914655310d2363baccf5e615e09b04911.tar.xz
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.
Diffstat (limited to 'src')
-rw-r--r--src/xz/file_io.c36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/xz/file_io.c b/src/xz/file_io.c
index 08288ebb..7895ee01 100644
--- a/src/xz/file_io.c
+++ b/src/xz/file_io.c
@@ -713,17 +713,10 @@ io_open_dest_real(file_pair *pair)
return true;
}
- if ((stdout_flags & O_NONBLOCK) == 0) {
- if (fcntl(STDOUT_FILENO, F_SETFL,
- stdout_flags | O_NONBLOCK) == -1) {
- message_error(_("Error setting O_NONBLOCK "
- "on standard output: %s"),
- strerror(errno));
- return true;
- }
-
- restore_stdout_flags = true;
- }
+ if ((stdout_flags & O_NONBLOCK) == 0
+ && fcntl(STDOUT_FILENO, F_SETFL,
+ stdout_flags | O_NONBLOCK) != -1)
+ restore_stdout_flags = true;
#endif
} else {
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)
return false;
- // O_NONBLOCK was set earlier in this function
- // so it must be kept here too. If this
- // fcntl() call fails, we continue but won't
+ // Construct the new file status flags.
+ // If O_NONBLOCK was set earlier in this
+ // 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
// flags will still be restored if needed (to
// unset O_NONBLOCK) when the file is finished.
- if (fcntl(STDOUT_FILENO, F_SETFL,
- (stdout_flags | O_NONBLOCK)
- & ~O_APPEND) == -1)
+ if (fcntl(STDOUT_FILENO, F_SETFL, flags) == -1)
return false;
// Disabling O_APPEND succeeded. Mark
// that the flags should be restored
- // in io_close_dest(). This quite likely was
- // already set when enabling O_NONBLOCK but
- // just in case O_NONBLOCK was already set,
- // set this again here.
+ // in io_close_dest(). (This may have already
+ // been set when enabling O_NONBLOCK.)
restore_stdout_flags = true;
} else if (lseek(STDOUT_FILENO, 0, SEEK_CUR)