From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Morton Subject: Re: [PATCH 1/1] Fix seq_file mishandling of consecutive pread() invocations. Date: Thu, 26 Jan 2012 16:00:38 -0800 Message-ID: <20120126160038.b5bb63be.akpm@linux-foundation.org> References: <4F166FC9.8030906@ixiacom.com> <4F1C5D01.3060403@ixiacom.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: Alexander Viro , "linux-kernel@vger.kernel.org" , , To: Earl Chew Return-path: In-Reply-To: <4F1C5D01.3060403@ixiacom.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Sun, 22 Jan 2012 11:01:21 -0800 Earl Chew 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??