Re: [PATCH 1/1] Fix seq_file mishandling of consecutive pread()invocations.

From: Andrew Morton
Date: Thu Jan 26 2012 - 19:00:42 EST


On Sun, 22 Jan 2012 11:01:21 -0800
Earl Chew <echew@xxxxxxxxxxx> wrote:

> [ Added Maintainers; Added reference to bugzilla.kernel.org in commit log ]
>
> Also reported in:
>
> https://bugzilla.kernel.org/show_bug.cgi?id=11856
>
> The following program illustrates the problem:
>
> char buf[8192];
>
> int fd = open("/proc/self/maps", O_RDONLY);
>
> n = pread(fd, buf, sizeof(buf), 0);
> printf("%d\n", n);
>
> /* lseek(fd, 0, SEEK_CUR); */ /* Uncomment to work around */
>
> n = pread(fd, buf, sizeof(buf), 0);
> printf("%d\n", n);
>
> The second printf() prints zero, but uncommenting the lseek()
> corrects its behaviour.

I'm stunned and confused. That sequence of operations is the only sane
way in which to poll the contents of a procfs file.

Surely there are many applications which open a procfs file then
repeatedly read it with pread(fd, ..., 0). How can this problem not
have been noticed in the first five minutes??
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/