Bug #1809

select() hangs on EOF

Added by Johannes.Hofmann over 4 years ago. Updated about 4 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:sjg% Done:

0%

Category:-
Target version:-

Description

Hi,

lang/guile no longer works since the recent kevent changes.
The problem is that select() for read now hangs when a fd on a local
file has reached EOF.

The following test program shows the issue (touch foo.txt before
running):

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/types.h>

main ()
{
int result, fd;
fd_set rset;

if ((fd = open("foo.txt", O_RDONLY)) < 0) {
printf ("Error %d opening foo.txt\n", errno);
exit (-1);
}

lseek(fd, 0, SEEK_END);

FD_ZERO (&rset);
FD_SET (fd, &rset);

result = select (fd + 1, &rset, 0, 0, 0);
printf("select returned %d\n", result);
}

The following change makes guile work (on hammer), but I don't know
whether this is the right place to deal with this.

diff --git a/sys/vfs/hammer/hammer_vnops.c b/sys/vfs/hammer/hammer_vnops.c
index d02b004..7b000a1 100644
--- a/sys/vfs/hammer/hammer_vnops.c
+++ b/sys/vfs/hammer/hammer_vnops.c
@@ -3413,7 +3413,7 @@ filt_hammerread(struct knote *kn, long hint)
return(1);
}
kn->kn_data = ip->ino_data.size - kn->kn_fp->f_offset;
- return (kn->kn_data != 0);
+ return (1);
}

static int

Cheers,
Johannes

History

#1 Updated by dillon over 4 years ago

:Hi,
:
:lang/guile no longer works since the recent kevent changes.
:The problem is that select() for read now hangs when a fd on a local
:file has reached EOF.
:
:The following test program shows the issue (touch foo.txt before
:running):

Ok, since kqueue expects a read event only when not at the EOF
and select/poll (historically) always return an immediate event
regardless of the file seek position, for regular files, I have
adjusted the kernel and filesystem code to make the distinction.

-Matt

#2 Updated by sjg over 4 years ago

Johannes,

Can you confirm this is now resolved?

I would like to commit this test to base, is that ok?

#3 Updated by alexh about 4 years ago

So is this fixed?

#4 Updated by Johannes.Hofmann about 4 years ago

fixed in 57b24f4ee66aaaa59b54e9577b93253cf435672f

#5 Updated by sjg about 4 years ago

Will close this after bringing in the supplied test case.

#6 Updated by sjg about 4 years ago

Test case committed: 7b34d05

Also available in: Atom PDF