diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2015-02-21 23:00:19 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2015-02-21 23:00:19 +0200 |
commit | ae984e31c167d3bc52972ec422dd1ebd5f5d5719 (patch) | |
tree | 7ce4f75afab0290a82fb8f22342c2a058c50c640 /src/xz | |
parent | Update THANKS. (diff) | |
download | xz-ae984e31c167d3bc52972ec422dd1ebd5f5d5719.tar.xz |
xz: Fix the fcntl() usage when creating a pipe for the self-pipe trick.
Now it reads the old flags instead of blindly setting O_NONBLOCK.
The old code may have worked correctly, but this is better.
Diffstat (limited to 'src/xz')
-rw-r--r-- | src/xz/file_io.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/xz/file_io.c b/src/xz/file_io.c index c52656c1..9bd515dd 100644 --- a/src/xz/file_io.c +++ b/src/xz/file_io.c @@ -82,13 +82,19 @@ io_init(void) // we are root. warn_fchown = geteuid() == 0; - if (pipe(user_abort_pipe) - || fcntl(user_abort_pipe[0], F_SETFL, O_NONBLOCK) - == -1 - || fcntl(user_abort_pipe[1], F_SETFL, O_NONBLOCK) - == -1) + // Create a pipe for the self-pipe trick. + if (pipe(user_abort_pipe)) message_fatal(_("Error creating a pipe: %s"), strerror(errno)); + + // Make both ends of the pipe non-blocking. + for (unsigned i = 0; i < 2; ++i) { + int flags = fcntl(user_abort_pipe[i], F_GETFL); + if (flags == -1 || fcntl(user_abort_pipe[i], F_SETFL, + flags | O_NONBLOCK) == -1) + message_fatal(_("Error creating a pipe: %s"), + strerror(errno)); + } #endif #ifdef __DJGPP__ |