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

user.home property should be configurable via the HOME variable

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • None
    • 7
    • core-libs

    Description

      FULL PRODUCT VERSION :
      openjdk version "1.7.0-m13"
      OpenJDK Runtime Environment (build 1.7.0-m13-b147)
      OpenJDK 64-Bit Server VM (build 21.0-b17, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      All versions of Linux

      A DESCRIPTION OF THE PROBLEM :
      Setting the HOME environment variable from the shell does not affect System.getProperty("user.home")

      System.getProperty("user.home") always returns value from getpwuid which is discouraged.

      This breaks the expected behavior of setting the user home directory through environment variable.

      I traced it to:
      openjdk/jdk/src/solaris/native/java/lang/java_props_md.c:
          452 struct passwd *pwent = getpwuid(getuid());
          453 sprops.user_name = pwent ? strdup(pwent->pw_name) : "?";
          454 sprops.user_home = pwent ? strdup(pwent->pw_dir) : "?";
          
      The description for struct passwd states:
      =====
      The <pwd.h> header shall provide a definition for struct passwd, which shall include at least the following members:

      char *pw_name User's login name.
      uid_t pw_uid Numerical user ID.
      gid_t pw_gid Numerical group ID.
      char *pw_dir Initial working directory.
      char *pw_shell Program to use as shell.
      =====

      But the manpage is very specific (http://linux.die.net/man/3/getpwuid):
      =====
      An application that wants to determine its user's home directory should inspect the value of HOME (rather than the value getpwuid(getuid())->pw_dir) since this allows the user to modify their notion of "the home directory" during a login session.
      =====


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Access the user.home system properties. It is guaranteed to be set.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      1/ Run from normal shell session:
      $ java HomeDirTest
      Home dir in System.getProperties is: /home/sule
      Home dir in System.getenv is: /home/sule

      2/ Run with modified HOME variable:
      $ HOME=/var/tmp/sule java HomeDirTest
      Home dir in System.getProperties is: /var/tmp/sule
      Home dir in System.getenv is: /var/tmp/sule
      ACTUAL -
      1/ Run from normal shell session:
      $ java HomeDirTest
      Home dir in System.getProperties is: /home/sule
      Home dir in System.getenv is: /home/sule

      2/ Run with modified HOME variable:
      $ HOME=/var/tmp/sule java HomeDirTest
      Home dir in System.getProperties is: /home/sule
      Home dir in System.getenv is: /var/tmp/sule

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class HomeDirTest {

          public static void main(String[] args) {
              System.out.println("Home dir in System.getProperties is: " + System.getProperty("user.home"));
              System.out.println("Home dir in System.getenv is: " + System.getenv("HOME"));

          }

      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: