Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6354700

LD_LIBRARY_PATH polluted in children

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 5.0
    • Fix Version/s: 7
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      A DESCRIPTION OF THE REQUEST :
      The Linux JRE adds three components to the LD_LIBRARY_PATH presumably to enable the loader to find the JRE's shared library files. After it has served its purpose, this change to the environment remains and is inherited by any child processes which the user's Java causes to be executed.

      JUSTIFICATION :
      This sequence of commands, executed in an environment polluted by the JRE:

      strace -o /tmp/trc date
      grep jdk /tmp/trc | wc -l

      Produced this output for me:

      100

      Whereas this sequence of commands:

      unset LD_LIBRARY_PATH
      strace -o /tmp/trc date
      grep jdk /tmp/trc | wc -l

      Produced this output for me:

      0

      Every shared library opened by every process searches this path. date was just a simple example. This takes time and provides no benefit.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I think the JRE should remove elements it added to the LD_LIBRARY_PATH before passing that environment variable on to children which aren't part of its implementation.

      ACTUAL -
      This sequence of commands:

      cat > LdLibraryPathPollutionTester.java <<EOF
      <paste the supplied source code>
      EOF
      unset LD_LIBRARY_PATH
      export LD_LIBRARY_PATH
      javac LdLibraryPathPollutionTester.java
      java LdLibraryPathPollutionTester

      Produces this output for me:

      /usr/local/jdk1.5.0_01/jre/lib/i386/client:/usr/local/jdk1.5.0_01/jre/lib/i386:/usr/local/jdk1.5.0_01/jre/../lib/i386

      Showing that the JRE is polluting the environment of any children with three extra components on the LD_LIBRARY_PATH.


      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.util.regex.*;

      public class LdLibraryPathPollutionTester {
        public static void main(String[] arguments) {
          try {
            final Process process = Runtime.getRuntime().exec("env");
            LineNumberReader input = new LineNumberReader(new InputStreamReader(process.getInputStream()));
            Pattern pattern = Pattern.compile("^LD_LIBRARY_PATH=(.*)$");
            String line;
            while ((line = input.readLine()) != null) {
              Matcher matcher = pattern.matcher(line);
              if (matcher.matches()) {
                System.out.println(matcher.group(1));
              }
            }
          } catch (IOException exception) {
            exception.printStackTrace();
          }
        }
        
        private LdLibraryPathPollutionTester () {
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The LD_LIBRARY_PATH can be restored to its previous value by the child process, if it has some way of knowing what the previous value was in its ancestor which called the JRE. The workaround needs to be duplicated in every child. If the Java in question is a generic program launcher of some kind, like a terminal emulator, this is unfortunately repetitive.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ksrini Kumar Srinivasan
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: