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] Replacing Exe with File.getCanonicalPath()


Hi,

While Phil, Rick and me were investigation bug #4788 we noticed that
frysk.sys.Exe just does what File.getCanonicalPath() provides. Since the
way Exe calls readlink is somewhat non-conventional by allocation large
arrays on the stack which isn't recommended by the glibc manual and Exe
doesn't actually come with any test code I replaced the only usage of it
in frysk with File.getCanonicalPath().

frysk-core/frysk/proc/live/ChangeLog
2007-07-16  Mark Wielaard  <mwielaard@redhat.com>

    * LinuxProc.java (sendrecExe): Use File.getCanonicalPath().

frysk-imports/frysk/sys/proc/ChangeLog
2007-07-16  Mark Wielaard  <mwielaard@redhat.com>

    * Exe.java: Removed.
    * cni/Exe.cxx: Likewise.

Tested on x86_64 and x86 without regressions, also smoke tested
FryskGui.

Cheers,

Mark
Index: frysk-core/frysk/proc/live/LinuxProc.java
===================================================================
RCS file: /cvs/frysk/frysk-core/frysk/proc/live/LinuxProc.java,v
retrieving revision 1.1
diff -u -u -r1.1 LinuxProc.java
--- frysk-core/frysk/proc/live/LinuxProc.java	26 Jun 2007 22:12:52 -0000	1.1
+++ frysk-core/frysk/proc/live/LinuxProc.java	16 Jul 2007 09:37:07 -0000
@@ -49,7 +49,6 @@
 import frysk.proc.MemoryMap;
 import java.util.ArrayList;
 import frysk.proc.Isa;
-import frysk.sys.proc.Exe;
 import frysk.sys.proc.CmdLineBuilder;
 import frysk.sys.proc.MapsBuilder;
 import frysk.sys.proc.Status;
@@ -61,6 +60,8 @@
 import java.util.HashMap;
 import frysk.proc.TaskId;
 import java.util.Iterator;
+import java.io.File;
+import java.io.IOException;
 
 /**
  * A Linux Proc tracked using PTRACE.
@@ -201,7 +202,16 @@
      */
     protected String sendrecExe ()
     {
-	return Exe.get (getPid ());
+      String exeString = "/proc/" + getPid() + "/exe";
+      try
+	{
+	  exeString = new File(exeString).getCanonicalPath();
+	}
+      catch (IOException ioe)
+	{
+	  // Just return exeString. No permission or process died.
+	}
+      return exeString;
     }
     /**
      * Get the Process-wide ISA.
Index: frysk-imports/frysk/sys/proc/ChangeLog
===================================================================
RCS file: /cvs/frysk/frysk-imports/frysk/sys/proc/ChangeLog,v
retrieving revision 1.4
diff -u -u -r1.4 ChangeLog
--- frysk-imports/frysk/sys/proc/ChangeLog	20 Apr 2007 14:50:04 -0000	1.4
+++ frysk-imports/frysk/sys/proc/ChangeLog	16 Jul 2007 09:37:07 -0000
@@ -1,3 +1,8 @@
+2007-07-16  Mark Wielaard  <mwielaard@redhat.com>
+
+	* Exe.java: Removed.
+	* cni/Exe.cxx: Likewise.
+
 2007-04-20  Petr Machata  <pmachata@redhat.com>
 
 	* cni/slurp.cxx (uslurp): Adjust the length to accomodate trailing
Index: frysk-imports/frysk/sys/proc/Exe.java
===================================================================
RCS file: frysk-imports/frysk/sys/proc/Exe.java
diff -N frysk-imports/frysk/sys/proc/Exe.java
--- frysk-imports/frysk/sys/proc/Exe.java	8 Dec 2006 20:00:34 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,52 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2006, 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
-// the Free Software Foundation; version 2 of the License.
-//
-// FRYSK is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with FRYSK; if not, write to the Free Software Foundation,
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-// 
-// In addition, as a special exception, Red Hat, Inc. gives You the
-// additional right to link the code of FRYSK with code not covered
-// under the GNU General Public License ("Non-GPL Code") and to
-// distribute linked combinations including the two, subject to the
-// limitations in this paragraph. Non-GPL Code permitted under this
-// exception must only link to the code of FRYSK through those well
-// defined interfaces identified in the file named EXCEPTION found in
-// the source code files (the "Approved Interfaces"). The files of
-// Non-GPL Code may instantiate templates or use macros or inline
-// functions from the Approved Interfaces without causing the
-// resulting work to be covered by the GNU General Public
-// License. Only Red Hat, Inc. may make changes or additions to the
-// list of Approved Interfaces. You must obey the GNU General Public
-// License in all respects for all of the FRYSK code and other code
-// used in conjunction with FRYSK except the Non-GPL Code covered by
-// this exception. If you modify this file, you may extend this
-// exception to your version of the file, but you are not obligated to
-// do so. If you do not wish to provide this exception without
-// modification, you must delete this exception statement from your
-// version and license this file solely under the GPL without
-// exception.
-
-package frysk.sys.proc;
-
-/**
- * The contents of <tt>/proc/PID/exe</tt>.
- *
- * XXX: Should this be more like a builder or like Stat where there's
- * a refresh method that detects that the contents actually changed?
- */
-
-public class Exe
-{
-    public static final native String get (int pid);
-}
Index: frysk-imports/frysk/sys/proc/cni/Exe.cxx
===================================================================
RCS file: frysk-imports/frysk/sys/proc/cni/Exe.cxx
diff -N frysk-imports/frysk/sys/proc/cni/Exe.cxx
--- frysk-imports/frysk/sys/proc/cni/Exe.cxx	8 Dec 2006 20:00:34 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,63 +0,0 @@
-// This file is part of the program FRYSK.
-//
-// Copyright 2006, 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
-// the Free Software Foundation; version 2 of the License.
-//
-// FRYSK is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with FRYSK; if not, write to the Free Software Foundation,
-// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-// 
-// In addition, as a special exception, Red Hat, Inc. gives You the
-// additional right to link the code of FRYSK with code not covered
-// under the GNU General Public License ("Non-GPL Code") and to
-// distribute linked combinations including the two, subject to the
-// limitations in this paragraph. Non-GPL Code permitted under this
-// exception must only link to the code of FRYSK through those well
-// defined interfaces identified in the file named EXCEPTION found in
-// the source code files (the "Approved Interfaces"). The files of
-// Non-GPL Code may instantiate templates or use macros or inline
-// functions from the Approved Interfaces without causing the
-// resulting work to be covered by the GNU General Public
-// License. Only Red Hat, Inc. may make changes or additions to the
-// list of Approved Interfaces. You must obey the GNU General Public
-// License in all respects for all of the FRYSK code and other code
-// used in conjunction with FRYSK except the Non-GPL Code covered by
-// this exception. If you modify this file, you may extend this
-// exception to your version of the file, but you are not obligated to
-// do so. If you do not wish to provide this exception without
-// modification, you must delete this exception statement from your
-// version and license this file solely under the GPL without
-// exception.
-
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-
-#include <gcj/cni.h>
-
-#include "frysk/sys/proc/cni/slurp.hxx"
-#include "frysk/sys/cni/Errno.hxx"
-#include "frysk/sys/proc/Exe.h"
-
-jstring
-frysk::sys::proc::Exe::get (jint pid)
-{
-  char file[FILENAME_MAX];
-  if (::snprintf (file, sizeof file, "/proc/%d/exe", (int) pid)
-      >= FILENAME_MAX)
-    throwRuntimeException ("snprintf: buffer overflow");
-
-  char link[FILENAME_MAX];
-  int len = ::readlink (file, link, sizeof link);
-  if (len < 0 || len >= FILENAME_MAX)
-    throwErrno (errno, "readlink");
-  return JvNewStringLatin1 (link, len);
-}

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