[PATCH] linux: detect regular files correctly

3 views
Skip to first unread message

Eric Wong

unread,
Dec 4, 2012, 7:44:14 PM12/4/12
to libk...@googlegroups.com
The previous check for non-socket decriptors broke my attempt to
watch a pipe with kevent(), causing havoc in my application.
---
It took me a while to chase this down :<

This patch is also downloadable from:
http://bogomips.org/libkqueue.git/patch?id=a348d15f164e

src/linux/platform.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/linux/platform.c b/src/linux/platform.c
index 097b3ad..6ee805b 100644
--- a/src/linux/platform.c
+++ b/src/linux/platform.c
@@ -294,8 +294,7 @@ linux_get_descriptor_type(struct knote *kn)
dbg_perror("fstat(2)");
return (-1);
}
- if (! S_ISSOCK(sb.st_mode)) {
- //FIXME: could be a pipe, device file, or other non-regular file
+ if (S_ISREG(sb.st_mode)) {
kn->kn_flags |= KNFL_REGULAR_FILE;
dbg_printf("fd %d is a regular file\n", (int)kn->kev.ident);
return (0);
--
Eric Wong

Eric Wong

unread,
Dec 7, 2012, 5:33:15 PM12/7/12
to libk...@googlegroups.com
POSIX 2001 has an S_ISSOCK() macro which allows us to skip
making an the getsockopt() syscall for FDs which would fail with
ENOTSOCK.
---
This is needed because of my previous patch to avoid marking
every non-socket as a regular file. I noticed getsockopt()
being needless called on pipes.

This patch is also downloadable from:
http://bogomips.org/libkqueue.git/patch?id=29a58b9a27

src/linux/platform.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/src/linux/platform.c b/src/linux/platform.c
index 6ee805b..8f8ace2 100644
--- a/src/linux/platform.c
+++ b/src/linux/platform.c
@@ -303,6 +303,9 @@ linux_get_descriptor_type(struct knote *kn)
/*
* Test if the socket is active or passive.
*/
+ if (! S_ISSOCK(sb.st_mode))
+ return (0);
+
slen = sizeof(lsock);
lsock = 0;
i = getsockopt(kn->kev.ident, SOL_SOCKET, SO_ACCEPTCONN, (char *) &lsock, &slen);
--
Eric Wong

Mark Heily

unread,
Dec 9, 2012, 5:26:56 PM12/9/12
to libkqueue
This patch, along with the previous two patches you sent, have been committed as r608. 

Thanks,

  - Mark


--
Eric Wong

--
You received this message because you are subscribed to the Google Groups "libkqueue" group.
To post to this group, send email to libk...@googlegroups.com.
To unsubscribe from this group, send email to libkqueue+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/libkqueue?hl=en.


Reply all
Reply to author
Forward
0 new messages