Actions
Bug #14005
closedeventfd_read/write() don't return failure
Start date:
Due date:
% Done:
100%
Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:
Description
While investigating a new test failure with Python 3.10, I found that our eventfd_read()
function does not return a failure when the underlying read() returns -1 due to an unsigned comparison.
Here's a simple reproducer. With a non-blocking semaphore with an initial value of 2, the third read should fail with EAGAIN. It does not.
#include <stdio.h>
#include <sys/eventfd.h>
#include <errno.h>
#include <assert.h>
int
main()
{
int fd = eventfd(2, EFD_NONBLOCK | EFD_CLOEXEC | EFD_SEMAPHORE);
assert(fd >= 0);
for (uint_t i = 0; i < 3; i++) {
eventfd_t v = 0xdeadbeef;
int ret = eventfd_read(fd, &v);
printf("Ret: %d (errno %d, v %p)\n", ret, errno, v);
}
}
Here's the output:
Ret: 0 (errno 0, v 1) Ret: 0 (errno 0, v 1) Ret: 0 (errno 11, v deadbeef)
With a bit of dtrace, one can see that the underlying read()
is returning -1, and yet eventfd_read()
is not:
% pfexec dtrace -n 'pid$target::eventfd_read:return,syscall::read:return{trace(arg1)}' -c ./eventfd 3 1338 read:return 8 3 75386 eventfd_read:return 0 3 1338 read:return 8 3 75386 eventfd_read:return 0 3 1338 read:return -1 3 75386 eventfd_read:return 0
Related issues
Updated by Andy Fiddaman 10 months ago
- Related to Feature #6188: add support for eventfd added
Updated by Andy Fiddaman 9 months ago
Before the change in the associated Gerrit review, the new test program produces three errors:
bloody:illumos:ig_14005_eventfd% ./eventfd.64 eventfd.64: no semaphores read got ret 0 (expected -1) eventfd.64: no semaphores read got ret 0 (expected -1) eventfd.64: bad write got ret 0 (expected -1) bloody:illumos:ig_14005_eventfd% ./eventfd.32 eventfd.32: no semaphores read got ret 0 (expected -1) eventfd.32: no semaphores read got ret 0 (expected -1) eventfd.32: bad write got ret 0 (expected -1)
and after, none:
The illumos Project gate-ig_14005_eventfd-ce1e2c6b2bf August 2021 bloody:illumos:ig_14005_eventfd% ./eventfd.32 bloody:illumos:ig_14005_eventfd% ./eventfd.64
The python 3.10rc1 os_tests
module passes now too.
Updated by Electric Monk 8 months ago
- Status changed from In Progress to Closed
- % Done changed from 0 to 100
git commit d7159b37699523966f5e7af69b1bd84e2a084fa4
commit d7159b37699523966f5e7af69b1bd84e2a084fa4 Author: Andy Fiddaman <omnios@citrus-it.co.uk> Date: 2021-09-15T15:13:18.000Z 14005 eventfd_read/write() don't return failure Reviewed by: Robert Mustacchi <rm@fingolfin.org> Reviewed by: Dan McDonald <danmcd@joyent.com> Approved by: Robert Mustacchi <rm@fingolfin.org>
Actions