[PATCH] Prefer TMPDIR over hard coded /tmp

Bernd Eckenfels ecki at zusammenkunft.net
Thu Apr 26 03:48:30 UTC 2018


For robustness reasons, should it maybe fall back to the hardcoded default if the target path does not exist or has the (obvious*) missing write permission?


* with or without trying a actual write?
From: Brian Burkhalter <brian.burkhalter at oracle.com>
Sent: Donnerstag, April 26, 2018 5:09 AM
Subject: Re: [PATCH] Prefer TMPDIR over hard coded /tmp
To: Robert Stupp <snazy at snazy.de>
Cc: <core-libs-dev at openjdk.java.net>

Hi Robert,

On Apr 23, 2018, at 7:23 AM, Robert Stupp <snazy at snazy.de> wrote:

> For MacOS and Windows, Java prefers the user's temporary directory for java.io.tmpdir, but not for Linux, where it is always set to /tmp. The burden with this is that if you want to use a different temp directory, you have to explicitly pass -Djava.io.tmpdir=... on the command line, which can be difficult especially for unit tests or microbenchmarks in 3rd party code ran via Maven for example.
> java_props_t.tmp_dir is always initialized as P_tmpdir in GetJavaProperties (src/java.base/unix/native/libjava/java_props_md.c).
> The attached patch changed the behavior to use the content of the environment variable TMPDIR, if present. Note that this does not change where the hsperf* folders are created.

The source change looks OK to me aside from the copyright year and that in the second line here

+ v = getenv("TMPDIR");
+ if (v) {
+ sprops.tmp_dir = strdup(v);
+ }

it should probably have

+ if (v != NULL) {

for consistency with elsewhere in the file.

> I'm not sure why java.io.tmpdir is always /tmp in Linux as according to the SCM history, this was always as it is (references the initial OpenJDK commit).
> I haven't found any tests that validates the content of java.io.tmpdir.

Some sort of test would need to be added to this patch to validate the change.



More information about the core-libs-dev mailing list