This is the mail archive of the frysk@sourceware.org mailing list for the frysk project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Stat vs slurp vs linux 2.6.22


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/<pid>/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  <mark@klomp.org>

    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?

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 <gcj/cni.h>
 
+#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;
     }
 
 

Attachment: signature.asc
Description: This is a digitally signed message part


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]