From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11953 invoked by alias); 7 Apr 2008 02:06:49 -0000 Received: (qmail 11943 invoked by uid 22791); 7 Apr 2008 02:06:47 -0000 X-Spam-Status: No, hits=0.7 required=5.0 tests=AWL,BAYES_05,J_CHICKENPOX_44,J_CHICKENPOX_46,J_CHICKENPOX_47,J_CHICKENPOX_53,J_CHICKENPOX_54,J_CHICKENPOX_64,J_CHICKENPOX_74,J_CHICKENPOX_92,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; Mon, 07 Apr 2008 02:06:31 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id m3726TSQ028511 for ; Sun, 6 Apr 2008 22:06:29 -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 m3726SAu013983 for ; Sun, 6 Apr 2008 22:06:28 -0400 Received: from [172.16.57.153] (multics.rdu.redhat.com [172.16.57.153]) by pobox.corp.redhat.com (8.13.1/8.13.1) with ESMTP id m3726Svm008782 for ; Sun, 6 Apr 2008 22:06:28 -0400 Subject: sysroot library support From: Stan Cox To: Frysk List Content-Type: text/plain Date: Mon, 07 Apr 2008 11:45:00 -0000 Message-Id: <1207533988.4793.106.camel@multics.rdu.redhat.com> Mime-Version: 1.0 X-Mailer: Evolution 2.12.3 (2.12.3-3.fc8) Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 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: 2008-q2/txt/msg00030.txt.bz2 This patch enables the sysroot handling to find libraries, which avoids the user having to use LD_LIBRARY_PATH to find the desired library. For instance given funit-quicksort which refers to libbubble.so: funit-quicksort-dir/usr/bin/funit-quicksort funit-quicksort-dir/usr/lib/libbubble.so funit-quicksort-dir/usr/lib/debug/usr/bin/funit-quicksort.debug funit-quicksort-dir/usr/lib/debug/usr/lib/funit-bubblesort.debug funit-quicksort-dir/usr/src/debug/funit-{quicksort,bubblesort}.c % ldd -u funit-quicksort-dir/usr/bin/funit-quicksort Unused direct dependencies: libbubble.so % fhpd -sysroot /work/scox/accu/funit-quicksort-dir/ funit-quicksort [0.0] Loaded executable file: /work/scox/accu/funit-quicksort-dir/usr/bin/funit-quicksort (fhpd) break main breakpoint 0 deferred (fhpd) run Attached to process 20321 running with this command: funit-quicksort Running process 20321 (fhpd) Breakpoint 0 main 0x4007fa list ... 93 /* 93 */ main() -> 94 /* 94 */ { 95 /* 95 */ ... (fhpd) go Running process 20321 (fhpd) Task 20321 is exiting with status 0 This is not committed; I wanted to get comments from folks first. Basically the patch causes requestCreateAttachedProc to get the library list and push it down to Fork.cxx#spawn where it sets up LD_LIBRARY_PATH via execve diff --git a/frysk-core/frysk/proc/Host.java b/frysk-core/frysk/proc/Host.java index 612162a..dda263c 100644 --- a/frysk-core/frysk/proc/Host.java +++ b/frysk-core/frysk/proc/Host.java @@ -42,6 +42,8 @@ package frysk.proc; import java.io.File; import java.util.Collection; import frysk.rsl.Log; +import frysk.sysroot.SysRoot; +import frysk.sysroot.SysRootFile; /** * A host machine. @@ -78,29 +80,30 @@ public abstract class Host implements Comparable { public abstract void requestCreateAttachedProc(File exe, String stdin, String stdout, String stderr, String[] args, + String libs, TaskAttachedObserverXXX attachedObserver); /** * Request that a new attached and running process(with stdin, * stdout, and stderr are shared with this process) be created. */ public void requestCreateAttachedProc(String stdin, String stdout, - String stderr, String[] args, + String stderr, String[] args, TaskAttachedObserverXXX attachedObserver) { fine.log(this, "requestCreateAttachedProc", args, "observer", attachedObserver); requestCreateAttachedProc(new File(args[0]), stdin, stdout, stderr, - args, attachedObserver); + args, "", attachedObserver); } /** * Request that a new attached and running process(with stdin, @@ -111,7 +114,7 @@ public abstract class Host implements Comparable { fine.log(this, "requestCreateAttachedProc", args, "observer", attachedObserver); requestCreateAttachedProc(new File(args[0]), null, null, null, - args, attachedObserver); + args, "", attachedObserver); } /** * Request that a new attached and running process based on @@ -121,9 +124,11 @@ public abstract class Host implements Comparable { TaskAttachedObserverXXX attachedObserver) { fine.log(this, "requestCreateAttachedProc template", template, "observer", attachedObserver); - requestCreateAttachedProc(new File(template.getExeFile().getSysRootedPath()), + SysRootFile sysRootFile = template.getExeFile(); + requestCreateAttachedProc(new File(sysRootFile.getSysRootedPath()), null, null, null, template.getCmdLine(), + new SysRoot(sysRootFile.getSysRoot()).getLibPathViaSysRoot(), attachedObserver); } diff --git a/frysk-core/frysk/proc/dead/DeadHost.java b/frysk-core/frysk/proc/dead/DeadHost.java index 08a5baf..9d2075b 100644 --- a/frysk-core/frysk/proc/dead/DeadHost.java +++ b/frysk-core/frysk/proc/dead/DeadHost.java @@ -59,7 +59,7 @@ import java.io.File; abstract class DeadHost extends Host { public void requestCreateAttachedProc(File exe, String in, String out, String err, - String[] args, + String[] args, String libs, TaskAttachedObserverXXX attached) { throw new RuntimeException("requestCreateAttachedProc"); } diff --git a/frysk-core/frysk/proc/dummy/DummyHost.java b/frysk-core/frysk/proc/dummy/DummyHost.java index d6fcf63..5afb229 100644 --- a/frysk-core/frysk/proc/dummy/DummyHost.java +++ b/frysk-core/frysk/proc/dummy/DummyHost.java @@ -58,7 +58,7 @@ public class DummyHost extends Host { public void requestCreateAttachedProc(File exe, String stdin, String stdout, - String stderr, String[] args, + String stderr, String[] args, String libs, TaskAttachedObserverXXX attached) { throw new RuntimeException("requestCreateAttachedProc"); } diff --git a/frysk-core/frysk/proc/live/LinuxPtraceHost.java b/frysk-core/frysk/proc/live/LinuxPtraceHost.java index b51449e..d5bdb52 100644 --- a/frysk-core/frysk/proc/live/LinuxPtraceHost.java +++ b/frysk-core/frysk/proc/live/LinuxPtraceHost.java @@ -262,6 +262,7 @@ public class LinuxPtraceHost extends LiveHost { final String stdout, final String stderr, final String[] args, + final String libs, final TaskAttachedObserverXXX attachedObserver) { fine.log(this, "requestCreateAttachedProc"); Manager.eventLoop.add(new Event() { @@ -270,7 +271,7 @@ public class LinuxPtraceHost extends LiveHost { "execute - requestCreateAttachedProc", exe); ProcessIdentifier pid - = Fork.ptrace(exe, stdin, stdout, stderr, args); + = Fork.ptrace(exe, stdin, stdout, stderr, args, libs); // See if the Host knows about this task. ProcessIdentifier myTid = Tid.get(); LinuxPtraceTask myTask = getTask(myTid); diff --git a/frysk-core/frysk/sysroot/SysRoot.java b/frysk-core/frysk/sysroot/SysRoot.java index 8ba22a5..19437aa 100644 --- a/frysk-core/frysk/sysroot/SysRoot.java +++ b/frysk-core/frysk/sysroot/SysRoot.java @@ -94,6 +94,25 @@ public class SysRoot { else return new SysRootFile(sysRoot, f); } + + /** + * return a pathname of an executable. + * + * @return this executable's library pathname, in the special + * root directory. + */ + public String getLibPathViaSysRoot () { + String libraryPath = ""; + if (! sysRoot.equals("/")) { + if (new File(sysRoot, "/lib").exists()) + libraryPath += sysRoot + "/lib:"; + if (new File(sysRoot, "/usr/lib").exists()) + libraryPath += sysRoot + "/usr/lib"; + } + + return libraryPath; + } + private File findExe(String pathVar, String arg0) { if (pathVar == null) { diff --git a/frysk-sys/frysk/sys/Fork.java b/frysk-sys/frysk/sys/Fork.java index 1a89f47..e82b506 100644 --- a/frysk-sys/frysk/sys/Fork.java +++ b/frysk-sys/frysk/sys/Fork.java @@ -53,9 +53,10 @@ public final class Fork { private static native ProcessIdentifier spawn(File exe, String in, String out, String err, - String[] args, int trace); + String[] args, + String libs, int trace); private static ProcessIdentifier spawn(String[] args, int trace) { - return spawn(new File(args[0]), null, null, null, args, trace); + return spawn(new File(args[0]), null, null, null, args, "", trace); } /** @@ -66,7 +67,7 @@ public final class Fork { public static ProcessIdentifier exec(File exe, String in, String out, String err, String[] args) { - return spawn(exe, in, out, err, args, NO_TRACE); + return spawn(exe, in, out, err, args, "", NO_TRACE); } /** * Create a child process running EXE with arguments ARGS[0..]. @@ -75,7 +76,7 @@ public final class Fork { */ public static ProcessIdentifier exec(String in, String out, String err, String[] args) { - return spawn(new File(args[0]), in, out, err, args, NO_TRACE); + return spawn(new File(args[0]), in, out, err, args, "", NO_TRACE); } /** * Create a child process running ARGS[0] with arguments @@ -93,8 +94,8 @@ public final class Fork { */ public static ProcessIdentifier ptrace(File exe, String in, String out, - String err, String[] args) { - return spawn(exe, in, out, err, args, PTRACE); + String err, String[] args, String libs) { + return spawn(exe, in, out, err, args, libs, PTRACE); } /** * Create a child process running ARGS[0] with arguments @@ -113,7 +114,7 @@ public final class Fork { public static ProcessIdentifier utrace(File exe, String in, String out, String err, String[] args) { - return spawn(exe, in, out, err, args, UTRACE); + return spawn(exe, in, out, err, args, "", UTRACE); } /** * Create a child process running ARGS[0] with arguments diff --git a/frysk-sys/frysk/sys/cni/Fork.cxx b/frysk-sys/frysk/sys/cni/Fork.cxx index b745ed7..c8b639e 100644 --- a/frysk-sys/frysk/sys/cni/Fork.cxx +++ b/frysk-sys/frysk/sys/cni/Fork.cxx @@ -73,7 +73,7 @@ reopen (jstring file, const char *mode, FILE *stream) int spawn(java::io::File* exe, jstring in, jstring out, jstring err, - jstringArray args, jint trace) + jstringArray args, jstring libs, jint trace) { // Convert args into argv, argc, filename. char *filename = ALLOCA_STRING(exe->getPath()); @@ -120,7 +120,19 @@ spawn(java::io::File* exe, jstring in, jstring out, jstring err, case frysk::sys::Fork::NO_TRACE: break; } - ::execv (filename, argv); + if (libs->length() > 0) + { + char *libs_str = (char *) alloca (libs->length() + 1); + JvGetStringUTFRegion (libs, 0, libs->length (), libs_str); + libs_str[libs->length()] = '\0'; + static char* libenv; + if (asprintf (&libenv, "LD_LIBRARY_PATH=%s", libs_str) < 0) + ::perror ("asprintf"); + char * const env[] = {libenv, (char*)0}; + ::execve (filename, argv, env); + } + else + ::execv (filename, argv); // This should not happen. ::perror ("execvp"); ::_exit (errno); @@ -130,8 +142,8 @@ spawn(java::io::File* exe, jstring in, jstring out, jstring err, frysk::sys::ProcessIdentifier* frysk::sys::Fork::spawn(java::io::File* exe, jstring in, jstring out, jstring err, - jstringArray args, jint trace) { - int pid = ::spawn(exe, in, out, err, args, trace); + jstringArray args, jstring libs, jint trace) { + int pid = ::spawn(exe, in, out, err, args, libs, trace); return frysk::sys::ProcessIdentifierFactory::create(pid); } @@ -148,7 +160,7 @@ frysk::sys::Fork::daemon (java::io::File* exe, jstring in, jstring out, // process id ends up in PID. if (v == 0) { - pid = ::spawn(exe, in, out, err, args, frysk::sys::Fork::NO_TRACE); + pid = ::spawn(exe, in, out, err, args, JvNewStringUTF (""), frysk::sys::Fork::NO_TRACE); _exit (0); }