public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Handle #! in LinuxExeFactory.
@ 2008-03-15 21:18 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-03-15 21:18 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  267dc2d82fb5a61cb76ff6123c7a5ef0e815ab3a (commit)
       via  82205a2e4f005a2d86d85cf2940e845fe2b57530 (commit)
      from  bd4817addf53c6db24ad95bd2181797434a90b12 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 267dc2d82fb5a61cb76ff6123c7a5ef0e815ab3a
Author: Andrew Cagney <cagney@redhat.com>
Date:   Sat Mar 15 17:09:52 2008 -0400

    Handle #! in LinuxExeFactory.
    
    frysk-core/frysk/proc/dead/ChangeLog
    2008-03-15  Andrew Cagney  <cagney@redhat.com>
    
    	* InterpreterFactory.java: Convert IOException into RuntimeException.
    	* TestLinuxExe.java (testScript()): New.
    	* LinuxExeFactory.java (createInterpreterProc(File,String[])): New.
    	(createElfProc(File,String[])): New.
    	(createProc(File,String[])): Use.

commit 82205a2e4f005a2d86d85cf2940e845fe2b57530
Author: Andrew Cagney <cagney@redhat.com>
Date:   Sat Mar 15 13:32:45 2008 -0400

    Extract parser from a file's magic.
    
    frysk-core/frysk/proc/dead/ChangeLog
    2008-03-15  Andrew Cagney  <cagney@redhat.com>
    
    	* InterpreterFactory.java (parse(File,String[])): New.
    	* TestInterpreter.java (testFile()): New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/proc/dead/ChangeLog               |   11 ++++++
 frysk-core/frysk/proc/dead/InterpreterFactory.java |   32 ++++++++++++++++
 frysk-core/frysk/proc/dead/LinuxExeFactory.java    |   39 +++++++++++++++++++-
 frysk-core/frysk/proc/dead/TestInterpreter.java    |   10 +++++
 frysk-core/frysk/proc/dead/TestLinuxExe.java       |    8 ++++
 5 files changed, 99 insertions(+), 1 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/proc/dead/ChangeLog b/frysk-core/frysk/proc/dead/ChangeLog
index da6e811..1c39faa 100644
--- a/frysk-core/frysk/proc/dead/ChangeLog
+++ b/frysk-core/frysk/proc/dead/ChangeLog
@@ -1,3 +1,14 @@
+2008-03-15  Andrew Cagney  <cagney@redhat.com>
+
+	* InterpreterFactory.java: Convert IOException into RuntimeException.
+	* TestLinuxExe.java (testScript()): New.
+	* LinuxExeFactory.java (createInterpreterProc(File,String[])): New.
+	(createElfProc(File,String[])): New.
+	(createProc(File,String[])): Use.
+	
+	* InterpreterFactory.java (parse(File,String[])): New.
+	* TestInterpreter.java (testFile()): New.
+
 2008-03-14  Andrew Cagney  <cagney@redhat.com>
 
 	* InterpreterFactory.java: New.
diff --git a/frysk-core/frysk/proc/dead/InterpreterFactory.java b/frysk-core/frysk/proc/dead/InterpreterFactory.java
index 9514f2f..a325a0e 100644
--- a/frysk-core/frysk/proc/dead/InterpreterFactory.java
+++ b/frysk-core/frysk/proc/dead/InterpreterFactory.java
@@ -39,6 +39,10 @@
 
 package frysk.proc.dead;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.FileReader;
+import java.io.BufferedReader;
 import frysk.rsl.Log;
 
 /**
@@ -80,4 +84,32 @@ class InterpreterFactory {
 	}
 	return interpreter;
     }
+
+    private static String firstLine(File file) {
+	String line = null;
+	BufferedReader reader = null;
+	try {
+	    reader = new BufferedReader(new FileReader(file));
+	    line = reader.readLine();
+	    reader.close();
+	} catch (IOException io) {
+	    if (reader != null) {
+		try {
+		    reader.close();
+		} catch (IOException e) {
+		    // don't care
+		}
+	    }
+	    throw new RuntimeException(io.getMessage());
+	}
+	return line;
+    }
+
+    static String[] parse(File file, String[] args) {
+	String line = firstLine(file);
+	if (line != null)
+	    return parse(line, args);
+	else
+	    return null;
+    }
 }
diff --git a/frysk-core/frysk/proc/dead/LinuxExeFactory.java b/frysk-core/frysk/proc/dead/LinuxExeFactory.java
index ece01d8..847c9d2 100644
--- a/frysk-core/frysk/proc/dead/LinuxExeFactory.java
+++ b/frysk-core/frysk/proc/dead/LinuxExeFactory.java
@@ -43,6 +43,8 @@ import java.io.File;
 import java.util.List;
 import java.util.LinkedList;
 import lib.dwfl.Elf;
+import lib.dwfl.ElfException;
+import lib.dwfl.ElfFileException;
 import lib.dwfl.ElfCommand;
 import lib.dwfl.ElfEHeader;
 import frysk.proc.MemoryMap;
@@ -54,7 +56,10 @@ import frysk.sysroot.SysRootCache;
 public class LinuxExeFactory {
     private static final Log fine = Log.fine(LinuxExeFactory.class);
 
-    public static DeadProc createProc(final File exeFile, String[] args) {
+    /**
+     * Attempt to create an elf proc, throw an exception if it fails.
+     */
+    private static DeadProc createElfProc(final File exeFile, String[] args) {
 	Elf exeElf = null;
 	try {
 	    exeElf = new Elf(exeFile, ElfCommand.ELF_C_READ);
@@ -83,12 +88,44 @@ public class LinuxExeFactory {
 		= new LinuxExeHost(exeFile, eHeader, SOMaps.getMemoryMaps(),
 				   args);
 	    return host.getProc();
+	} catch (ElfFileException e) {
+	    // File I/O is just bad; re-throw (need to catch it as
+	    // ElfFileException is a sub-class of ElfException).
+	    throw e;
+	} catch (ElfException e) {
+	    // Bad elf is ok; anything else is not.
+	    return null;
 	} finally {
 	    if (exeElf != null)
 		exeElf.close();
 	}
     }
 
+    /**
+     * Attempt to create an interpreter proc (for instance for a script).
+     */
+    private static DeadProc createInterpreterProc(File exeFile, String[] args) {
+	String[] interpreterArgs = InterpreterFactory.parse(exeFile, args);
+	if (interpreterArgs == null)
+	    return null;
+	fine.log("createInterpProc", interpreterArgs);
+	// FIXME: This is bogus; needs to find the interpreter file
+	// within the context of the sysroot; that means passing in
+	// the SysRoot as a parameter.
+	return createElfProc(new File(interpreterArgs[0]), interpreterArgs);
+    }
+
+    public static DeadProc createProc(File exeFile, String[] args) {
+	DeadProc proc;
+	proc = createElfProc(exeFile, args);
+	if (proc != null)
+	    return proc;
+	proc = createInterpreterProc(exeFile, args);
+	if (proc != null)
+	    return proc;
+	throw new RuntimeException("Not an executable: " + exeFile);
+    }
+
     public static DeadProc createProc(String[] args) {
 	SysRoot sysRoot = new SysRoot(SysRootCache.getSysRoot(args[0]));
 	File exe = sysRoot.getPathViaSysRoot(args[0]).getSysRootedFile();
diff --git a/frysk-core/frysk/proc/dead/TestInterpreter.java b/frysk-core/frysk/proc/dead/TestInterpreter.java
index b90966c..57e0948 100644
--- a/frysk-core/frysk/proc/dead/TestInterpreter.java
+++ b/frysk-core/frysk/proc/dead/TestInterpreter.java
@@ -40,6 +40,7 @@
 package frysk.proc.dead;
 
 import frysk.junit.TestCase;
+import frysk.config.Config;
 
 /**
  * Test the interpreter parser.
@@ -90,4 +91,13 @@ public class TestInterpreter extends TestCase {
 						  "script", "param"
 					      }));
     }
+
+    public void testFile() {
+	assertEquals("args",
+		     new String[] { "/bin/sh", "script", "param" },
+		     InterpreterFactory.parse(Config.getBinFile("fdebugrpm"),
+					      new String[] {
+						  "script", "param"
+					      }));
+    }
 }
diff --git a/frysk-core/frysk/proc/dead/TestLinuxExe.java b/frysk-core/frysk/proc/dead/TestLinuxExe.java
index a034c8d..9dd57c1 100644
--- a/frysk-core/frysk/proc/dead/TestLinuxExe.java
+++ b/frysk-core/frysk/proc/dead/TestLinuxExe.java
@@ -103,4 +103,12 @@ public class TestLinuxExe extends TestLib {
 	    });
 	assertRunUntilStop("find proc");
     }
+
+    public void testScript() {
+	Proc proc = LinuxExeFactory.createProc(new String[] {
+		Config.getBinFile("fdebugrpm").getPath(),
+		"arg"
+	    });
+	assertEquals("exe", "/bin/sh", proc.getExe());
+    }
 }


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-03-15 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-15 21:18 [SCM] master: Handle #! in LinuxExeFactory cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).