[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20120126160038.b5bb63be.akpm@linux-foundation.org>
Date: Thu, 26 Jan 2012 16:00:38 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Earl Chew <echew@...acom.com>
Cc: Alexander Viro <viro@...iv.linux.org.uk>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
<adobriyan@...il.com>, <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH 1/1] Fix seq_file mishandling of consecutive pread()
invocations.
On Sun, 22 Jan 2012 11:01:21 -0800
Earl Chew <echew@...acom.com> 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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists