Project

General

Profile

Actions

Bug #1809

closed

select() hangs on EOF

Added by Johannes.Hofmann over 13 years ago. Updated over 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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

Actions #1

Updated by dillon over 13 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
Actions #2

Updated by sjg over 13 years ago

Johannes,

Can you confirm this is now resolved?

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

Actions #3

Updated by alexh over 13 years ago

So is this fixed?

Actions #4

Updated by Johannes.Hofmann over 13 years ago

fixed in 57b24f4ee66aaaa59b54e9577b93253cf435672f

Actions #5

Updated by sjg over 13 years ago

Will close this after bringing in the supplied test case.

Actions #6

Updated by sjg over 13 years ago

Test case committed: 7b34d05

Actions

Also available in: Atom PDF