mirror of https://git.tukaani.org/xz.git
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.
This commit is contained in:
parent
2205bb5853
commit
ae984e31c1
|
@ -82,13 +82,19 @@ io_init(void)
|
||||||
// we are root.
|
// we are root.
|
||||||
warn_fchown = geteuid() == 0;
|
warn_fchown = geteuid() == 0;
|
||||||
|
|
||||||
if (pipe(user_abort_pipe)
|
// Create a pipe for the self-pipe trick.
|
||||||
|| fcntl(user_abort_pipe[0], F_SETFL, O_NONBLOCK)
|
if (pipe(user_abort_pipe))
|
||||||
== -1
|
|
||||||
|| fcntl(user_abort_pipe[1], F_SETFL, O_NONBLOCK)
|
|
||||||
== -1)
|
|
||||||
message_fatal(_("Error creating a pipe: %s"),
|
message_fatal(_("Error creating a pipe: %s"),
|
||||||
strerror(errno));
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef __DJGPP__
|
#ifdef __DJGPP__
|
||||||
|
|
Loading…
Reference in New Issue