public inbox for frysk@sourceware.org
 help / color / mirror / Atom feed
From: Sami Wagiaalla <swagiaal@redhat.com>
To: Stan Cox <scox@redhat.com>
Cc: Frysk List <frysk@sourceware.org>
Subject: Re: sysroot library support
Date: Thu, 10 Apr 2008 10:55:00 -0000	[thread overview]
Message-ID: <47FD2A5E.7090306@redhat.com> (raw)
In-Reply-To: <1207533988.4793.106.camel@multics.rdu.redhat.com>

This is pretty cool.... should definitely be added to the NEWS file.

Stan Cox wrote:
> 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);
>    }
>  
> 
> 
> 
> 
> 
> 

      reply	other threads:[~2008-04-09 20:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-07 11:45 Stan Cox
2008-04-10 10:55 ` Sami Wagiaalla [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=47FD2A5E.7090306@redhat.com \
    --to=swagiaal@redhat.com \
    --cc=frysk@sourceware.org \
    --cc=scox@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).