From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19101 invoked by alias); 25 Jul 2007 13:30:07 -0000 Received: (qmail 19072 invoked by uid 22791); 25 Jul 2007 13:30:06 -0000 X-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 25 Jul 2007 13:30:02 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.1/8.13.1) with ESMTP id l6PDTxi3023635; Wed, 25 Jul 2007 09:29:59 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [10.11.255.20]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l6PDTx35027449; Wed, 25 Jul 2007 09:29:59 -0400 Received: from [127.0.0.1] (sebastian-int.corp.redhat.com [172.16.52.221]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id l6PDTv5d008313; Wed, 25 Jul 2007 09:29:57 -0400 Message-ID: <46A75077.2020706@redhat.com> Date: Wed, 25 Jul 2007 13:30:00 -0000 From: Andrew Cagney User-Agent: Thunderbird 1.5.0.12 (X11/20070530) MIME-Version: 1.0 To: Mark Wielaard CC: frysk@sourceware.org Subject: Re: [patch] Stat vs slurp vs linux 2.6.22 References: <1185363024.3597.16.camel@dijkstra.wildebeest.org> In-Reply-To: <1185363024.3597.16.camel@dijkstra.wildebeest.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact frysk-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-owner@sourceware.org X-SW-Source: 2007-q3/txt/msg00175.txt.bz2 Mark Wielaard wrote: > Hi, > > On newer kernels (2.6.22) not just init (process id 1) can have a zero > parent pid, but other kernel processes/threads also have a parent pid of > zero (in particular kthreadd). This was done for systems with thousands > of CPUs which create ten-thousand (kernel) processes and having them all > children of init was not scaling (and not really necessary for the > kernel-threads, which don't need to be reaped by init in the first > place). This exposed a bug in our Stat parsing through LinuxHost. See > http://sourceware.org/bugzilla/show_bug.cgi?id=4838 > > Stat uses slurp which was written to handle these kind of issues > where /proc//stat might not exist or disappear in between calls. > But it relied on the slurp() functions returning a failure value (NULL > or -1). A recent rewrite of slurp to use Errno.tryOpen() which throws an > Exception on error, broke Stat handling in such cases. Besides that > slurp() had a bug in that it could free() a given buffer that it hadn't > created itself (Stat was the owner of that buffer), this could lead to > strange memory corruption. Both issues were fixed by: > > > 2007-07-25 Mark Wielaard > > Fixes bug #4838 > * cni/slurp.cxx (uslurp): Catch Errno after tryOpen(). > (slurp): Likewise and don't free given buffer and return -1. > (slurp_thread): Likewise. > > Tested on x86_64 (Fedora Core 6) and x86 (Fedora 7 - with new 2.6.22 > kernel). The failing tests reported in the bug report PASS with this > test on the new kernel. And introduces no new FAILs. > > It might make sense to rewrite slurp as a normal java class so these > cross C/Java error handling issues. Is there a reason for slurp to have > to be written in C/CNI? > -> memory pressure; notice how it does a callback -> performance it was written in java > Cheers, > > Mark > > ------------------------------------------------------------------------ > > Index: frysk-sys/frysk/sys/proc/cni/slurp.cxx > =================================================================== > RCS file: /cvs/frysk/frysk-sys/frysk/sys/proc/cni/slurp.cxx,v > retrieving revision 1.10 > diff -u -r1.10 slurp.cxx > --- frysk-sys/frysk/sys/proc/cni/slurp.cxx 18 Jul 2007 18:23:52 -0000 1.10 > +++ frysk-sys/frysk/sys/proc/cni/slurp.cxx 25 Jul 2007 10:53:47 -0000 > @@ -1,6 +1,6 @@ > // This file is part of the program FRYSK. > // > -// Copyright 2005, Red Hat Inc. > +// Copyright 2005, 2007 Red Hat Inc. > // > // FRYSK is free software; you can redistribute it and/or modify it > // under the terms of the GNU General Public License as published by > @@ -47,6 +47,7 @@ > > #include > > +#include "frysk/sys/Errno.h" > #include "frysk/sys/cni/Errno.hxx" > #include "frysk/sys/proc/cni/slurp.hxx" > > @@ -73,7 +74,15 @@ > } > > // Open the file file. > - int fd = tryOpen (file, O_RDONLY, 0); > + int fd; > + try > + { > + fd = tryOpen (file, O_RDONLY, 0); > + } > + catch (frysk::sys::Errno *ignored) > + { > + fd = 0; > + } > if (!fd) > { > ::free (buf); > @@ -127,12 +136,18 @@ > throwRuntimeException ("snprintf: buffer overflow"); > > // Open the file file. > - int fd = tryOpen (file, O_RDONLY, 0); > - > + int fd; > + try > + { > + fd = tryOpen (file, O_RDONLY, 0); > + } > + catch (frysk::sys::Errno *ignored) > + { > + fd = 0; > + } > if (!fd) > { > - ::free (buf); > - return 0; > + return -1; > } > > > @@ -165,12 +180,18 @@ > throwRuntimeException ("snprintf: buffer overflow"); > > // Open the file file. > - int fd = tryOpen (file, O_RDONLY, 0); > - > + int fd; > + try > + { > + fd = tryOpen (file, O_RDONLY, 0); > + } > + catch (frysk::sys::Errno *ignored) > + { > + fd = 0; > + } > if (!fd) > { > - ::free (buf); > - return 0; > + return -1; > } > > >