* Polling(2) /proc/mounts is broken?
@ 2010-12-10 15:32 Tvrtko Ursulin
2010-12-13 12:26 ` Tvrtko Ursulin
0 siblings, 1 reply; 2+ messages in thread
From: Tvrtko Ursulin @ 2010-12-10 15:32 UTC (permalink / raw)
To: Eric Paris, Al Viro; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 815 bytes --]
Hi all,
So since we cannot get fanotify global mode we were told to poll(2) on
/proc/mounts and set up new mount marks dynamically.
Is the attached C program roughly how it should work?
Because on 2.6.37-rc5 it busy loops for me (POLLIN always reported), even
though if I remove the seek it gets EOF immediately after POLLIN.
Under 2.6.32 (Ubuntu flavour) I see the same behaviour.
Going further back to 2.6.24 (again Ubuntu flavour) and there it works, but it
set POLLERR instead of POLLIN in revents.
So I guess it regressed somewhere in between. I'll look to provide a fix
unless someone more familiar with this area beats me to it.
Tvrtko
Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
Company Reg No 2096520. VAT Reg No GB 991 2418 08.
[-- Attachment #2: pollmounts.c --]
[-- Type: text/x-csrc, Size: 759 bytes --]
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <poll.h>
#include <unistd.h>
#include <stdio.h>
int main()
{
int fd;
struct pollfd ev;
int ret;
ssize_t bytes;
char buf[4096];
long unsigned int cnt = 0;
fd = open("/proc/mounts", O_RDONLY);
do {
ev.events = POLLIN;
ev.fd = fd;
ev.revents = 0;
ret = poll(&ev, 1, -1);
lseek(fd, 0, SEEK_SET);
if (ret == 1 && ev.revents == POLLIN) {
printf("#### %lu ########################################\n", cnt);
while ((bytes = read(fd, buf, sizeof(buf))) > 0)
write(1, buf, bytes);
cnt++;
}
} while (ret >= 0);
return 0;
}
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: Polling(2) /proc/mounts is broken?
2010-12-10 15:32 Polling(2) /proc/mounts is broken? Tvrtko Ursulin
@ 2010-12-13 12:26 ` Tvrtko Ursulin
0 siblings, 0 replies; 2+ messages in thread
From: Tvrtko Ursulin @ 2010-12-13 12:26 UTC (permalink / raw)
To: Eric Paris; +Cc: Al Viro, linux-kernel
On Friday 10 Dec 2010 15:32:48 Tvrtko Ursulin wrote:
> Hi all,
>
> So since we cannot get fanotify global mode we were told to poll(2) on
> /proc/mounts and set up new mount marks dynamically.
>
> Is the attached C program roughly how it should work?
>
> Because on 2.6.37-rc5 it busy loops for me (POLLIN always reported), even
> though if I remove the seek it gets EOF immediately after POLLIN.
>
> Under 2.6.32 (Ubuntu flavour) I see the same behaviour.
>
> Going further back to 2.6.24 (again Ubuntu flavour) and there it works, but
> it set POLLERR instead of POLLIN in revents.
>
> So I guess it regressed somewhere in between. I'll look to provide a fix
> unless someone more familiar with this area beats me to it.
It hasn't regressed but was fixed in 2.6.30. :)
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=31b07093c44a7a442394d44423e21d783f5523b8
So it is incorrect to poll for POLLIN. In case of /proc/mounts POLLPRI should
be used and will be returned together with POLLERR.
Tvrtko
Sophos Limited, The Pentagon, Abingdon Science Park, Abingdon, OX14 3YP, United Kingdom.
Company Reg No 2096520. VAT Reg No GB 991 2418 08.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-13 12:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-10 15:32 Polling(2) /proc/mounts is broken? Tvrtko Ursulin
2010-12-13 12:26 ` Tvrtko Ursulin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®