Skip to content
Snippets Groups Projects
Commit 35117245 authored by Nadav Har'El's avatar Nadav Har'El
Browse files

Fix POLLHUP in pipes


The code in pipe_buffer.cc had the meaning of POLLHUP and POLLRDHUP
reversed, and as a result POLLHUP wasn't correctly returned when polling
a read-end of the pipe whose write-end is closed.

This fixes the mixup, and as a result the test added to tst-pipe.cc in
the previous commit, and also another one added in this patch, all pass.

We are still incompatible with Linux with what we do regarding POLLRDHUP.
This will be a separate patch.

Signed-off-by: default avatarNadav Har'El <nyh@cloudius-systems.com>
parent 554e80f6
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ void pipe_buffer::detach_sender()
if (sender) {
sender = nullptr;
if (receiver)
poll_wake(receiver, POLLRDHUP);
poll_wake(receiver, POLLHUP);
may_read.wake_all();
}
}
......@@ -29,7 +29,7 @@ void pipe_buffer::detach_receiver()
if (receiver) {
receiver = nullptr;
if (sender)
poll_wake(sender, POLLHUP);
poll_wake(sender, POLLRDHUP);
may_write.wake_all();
}
}
......@@ -50,14 +50,14 @@ int pipe_buffer::read_events_unlocked()
{
int ret = 0;
ret |= !q.empty() ? POLLIN : 0;
ret |= !sender ? POLLRDHUP : 0;
ret |= !sender ? POLLHUP : 0;
return ret;
}
int pipe_buffer::write_events_unlocked()
{
if (!receiver) {
return POLLHUP;
return POLLRDHUP;
}
int ret = 0;
ret |= q.size() < max_buf ? POLLOUT : 0;
......
......@@ -307,6 +307,19 @@ int main(int ac, char** av)
r = close(s[0]);
report(r == 0, "close also read side");
// Test poll() on read side, when write side is already closed (POLLHUP expected)
r = pipe(s);
report(r == 0, "pipe call");
r = close(s[1]);
report(r == 0, "close write side");
poller = { s[0], POLLIN, 0 };
r = poll(&poller, 1, 0);
report(r==1, "pipe is readable");
report(poller.revents & POLLHUP, "POLLHUP signaled");
t6.join();
r = close(s[0]);
report(r == 0, "close also read side");
debug("SUMMARY: %d tests, %d failures\n", tests, fails);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment