6938627: Make temporary directory use property java.io.tmpdir when specified
Get java.io.tmpdir property in os::get_temp_directory() and call this instead of harcoding "/tmp". Don't assume trailing file_separator either. Reviewed-by: dholmes, kamg
This commit is contained in:
parent
7aaaad73cf
commit
47cda47c42
@ -192,7 +192,8 @@ int LinuxAttachListener::init() {
|
||||
res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
|
||||
}
|
||||
if (res == -1) {
|
||||
sprintf(path, "%s/.java_pid%d", os::get_temp_directory(), os::current_process_id());
|
||||
snprintf(path, PATH_MAX+1, "%s/.java_pid%d",
|
||||
os::get_temp_directory(), os::current_process_id());
|
||||
strcpy(addr.sun_path, path);
|
||||
::unlink(path);
|
||||
res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
|
||||
@ -460,13 +461,14 @@ bool AttachListener::is_init_trigger() {
|
||||
if (init_at_startup() || is_initialized()) {
|
||||
return false; // initialized at startup or already initialized
|
||||
}
|
||||
char fn[32];
|
||||
char fn[128];
|
||||
sprintf(fn, ".attach_pid%d", os::current_process_id());
|
||||
int ret;
|
||||
struct stat64 st;
|
||||
RESTARTABLE(::stat64(fn, &st), ret);
|
||||
if (ret == -1) {
|
||||
sprintf(fn, "/tmp/.attach_pid%d", os::current_process_id());
|
||||
snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
|
||||
os::get_temp_directory(), os::current_process_id());
|
||||
RESTARTABLE(::stat64(fn, &st), ret);
|
||||
}
|
||||
if (ret == 0) {
|
||||
|
@ -1522,7 +1522,10 @@ int os::current_process_id() {
|
||||
|
||||
const char* os::dll_file_extension() { return ".so"; }
|
||||
|
||||
const char* os::get_temp_directory() { return "/tmp/"; }
|
||||
const char* os::get_temp_directory() {
|
||||
const char *prop = Arguments::get_property("java.io.tmpdir");
|
||||
return prop == NULL ? "/tmp" : prop;
|
||||
}
|
||||
|
||||
static bool file_exists(const char* filename) {
|
||||
struct stat statbuf;
|
||||
@ -2305,7 +2308,8 @@ void linux_wrap_code(char* base, size_t size) {
|
||||
char buf[40];
|
||||
int num = Atomic::add(1, &cnt);
|
||||
|
||||
sprintf(buf, "/tmp/hs-vm-%d-%d", os::current_process_id(), num);
|
||||
snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d",
|
||||
os::get_temp_directory(), os::current_process_id(), num);
|
||||
unlink(buf);
|
||||
|
||||
int fd = open(buf, O_CREAT | O_RDWR, S_IRWXU);
|
||||
|
@ -145,11 +145,11 @@ static char* get_user_tmp_dir(const char* user) {
|
||||
|
||||
const char* tmpdir = os::get_temp_directory();
|
||||
const char* perfdir = PERFDATA_NAME;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 2;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 3;
|
||||
char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
|
||||
|
||||
// construct the path name to user specific tmp directory
|
||||
snprintf(dirname, nbytes, "%s%s_%s", tmpdir, perfdir, user);
|
||||
snprintf(dirname, nbytes, "%s/%s_%s", tmpdir, perfdir, user);
|
||||
|
||||
return dirname;
|
||||
}
|
||||
@ -331,8 +331,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||
}
|
||||
|
||||
char* usrdir_name = NEW_C_HEAP_ARRAY(char,
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 1);
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 2);
|
||||
strcpy(usrdir_name, tmpdirname);
|
||||
strcat(usrdir_name, "/");
|
||||
strcat(usrdir_name, dentry->d_name);
|
||||
|
||||
DIR* subdirp = os::opendir(usrdir_name);
|
||||
|
@ -375,7 +375,8 @@ int SolarisAttachListener::create_door() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
sprintf(door_path, "%s/.java_pid%d", os::get_temp_directory(), os::current_process_id());
|
||||
snprintf(door_path, sizeof(door_path), "%s/.java_pid%d",
|
||||
os::get_temp_directory(), os::current_process_id());
|
||||
RESTARTABLE(::creat(door_path, S_IRUSR | S_IWUSR), fd);
|
||||
|
||||
if (fd == -1) {
|
||||
@ -591,13 +592,14 @@ bool AttachListener::is_init_trigger() {
|
||||
if (init_at_startup() || is_initialized()) {
|
||||
return false; // initialized at startup or already initialized
|
||||
}
|
||||
char fn[32];
|
||||
char fn[128];
|
||||
sprintf(fn, ".attach_pid%d", os::current_process_id());
|
||||
int ret;
|
||||
struct stat64 st;
|
||||
RESTARTABLE(::stat64(fn, &st), ret);
|
||||
if (ret == -1) {
|
||||
sprintf(fn, "/tmp/.attach_pid%d", os::current_process_id());
|
||||
snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
|
||||
os::get_temp_directory(), os::current_process_id());
|
||||
RESTARTABLE(::stat64(fn, &st), ret);
|
||||
}
|
||||
if (ret == 0) {
|
||||
|
@ -676,15 +676,6 @@ bool os::have_special_privileges() {
|
||||
}
|
||||
|
||||
|
||||
static char* get_property(char* name, char* buffer, int buffer_size) {
|
||||
if (os::getenv(name, buffer, buffer_size)) {
|
||||
return buffer;
|
||||
}
|
||||
static char empty[] = "";
|
||||
return empty;
|
||||
}
|
||||
|
||||
|
||||
void os::init_system_properties_values() {
|
||||
char arch[12];
|
||||
sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
|
||||
@ -1826,7 +1817,10 @@ void os::set_error_file(const char *logfile) {}
|
||||
|
||||
const char* os::dll_file_extension() { return ".so"; }
|
||||
|
||||
const char* os::get_temp_directory() { return "/tmp/"; }
|
||||
const char* os::get_temp_directory() {
|
||||
const char *prop = Arguments::get_property("java.io.tmpdir");
|
||||
return prop == NULL ? "/tmp" : prop;
|
||||
}
|
||||
|
||||
static bool file_exists(const char* filename) {
|
||||
struct stat statbuf;
|
||||
|
@ -147,11 +147,11 @@ static char* get_user_tmp_dir(const char* user) {
|
||||
|
||||
const char* tmpdir = os::get_temp_directory();
|
||||
const char* perfdir = PERFDATA_NAME;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 2;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 3;
|
||||
char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
|
||||
|
||||
// construct the path name to user specific tmp directory
|
||||
snprintf(dirname, nbytes, "%s%s_%s", tmpdir, perfdir, user);
|
||||
snprintf(dirname, nbytes, "%s/%s_%s", tmpdir, perfdir, user);
|
||||
|
||||
return dirname;
|
||||
}
|
||||
@ -322,8 +322,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
|
||||
}
|
||||
|
||||
char* usrdir_name = NEW_C_HEAP_ARRAY(char,
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 1);
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 2);
|
||||
strcpy(usrdir_name, tmpdirname);
|
||||
strcat(usrdir_name, "/");
|
||||
strcat(usrdir_name, dentry->d_name);
|
||||
|
||||
DIR* subdirp = os::opendir(usrdir_name);
|
||||
|
@ -998,15 +998,16 @@ os::closedir(DIR *dirp)
|
||||
|
||||
const char* os::dll_file_extension() { return ".dll"; }
|
||||
|
||||
const char * os::get_temp_directory()
|
||||
{
|
||||
static char path_buf[MAX_PATH];
|
||||
if (GetTempPath(MAX_PATH, path_buf)>0)
|
||||
return path_buf;
|
||||
else{
|
||||
path_buf[0]='\0';
|
||||
return path_buf;
|
||||
}
|
||||
const char* os::get_temp_directory() {
|
||||
const char *prop = Arguments::get_property("java.io.tmpdir");
|
||||
if (prop != 0) return prop;
|
||||
static char path_buf[MAX_PATH];
|
||||
if (GetTempPath(MAX_PATH, path_buf)>0)
|
||||
return path_buf;
|
||||
else{
|
||||
path_buf[0]='\0';
|
||||
return path_buf;
|
||||
}
|
||||
}
|
||||
|
||||
static bool file_exists(const char* filename) {
|
||||
|
@ -149,11 +149,11 @@ static char* get_user_tmp_dir(const char* user) {
|
||||
|
||||
const char* tmpdir = os::get_temp_directory();
|
||||
const char* perfdir = PERFDATA_NAME;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 2;
|
||||
size_t nbytes = strlen(tmpdir) + strlen(perfdir) + strlen(user) + 3;
|
||||
char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
|
||||
|
||||
// construct the path name to user specific tmp directory
|
||||
_snprintf(dirname, nbytes, "%s%s_%s", tmpdir, perfdir, user);
|
||||
_snprintf(dirname, nbytes, "%s\\%s_%s", tmpdir, perfdir, user);
|
||||
|
||||
return dirname;
|
||||
}
|
||||
@ -318,8 +318,9 @@ static char* get_user_name_slow(int vmid) {
|
||||
}
|
||||
|
||||
char* usrdir_name = NEW_C_HEAP_ARRAY(char,
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 1);
|
||||
strlen(tmpdirname) + strlen(dentry->d_name) + 2);
|
||||
strcpy(usrdir_name, tmpdirname);
|
||||
strcat(usrdir_name, "\\");
|
||||
strcat(usrdir_name, dentry->d_name);
|
||||
|
||||
DIR* subdirp = os::opendir(usrdir_name);
|
||||
|
@ -1414,9 +1414,14 @@ void CompileBroker::init_compiler_thread_log() {
|
||||
intx thread_id = os::current_thread_id();
|
||||
for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) {
|
||||
const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL);
|
||||
if (dir == NULL) dir = "";
|
||||
sprintf(fileBuf, "%shs_c" UINTX_FORMAT "_pid%u.log",
|
||||
dir, thread_id, os::current_process_id());
|
||||
if (dir == NULL) {
|
||||
jio_snprintf(fileBuf, sizeof(fileBuf), "hs_c" UINTX_FORMAT "_pid%u.log",
|
||||
thread_id, os::current_process_id());
|
||||
} else {
|
||||
jio_snprintf(fileBuf, sizeof(fileBuf),
|
||||
"%s%shs_c" UINTX_FORMAT "_pid%u.log", dir,
|
||||
os::file_separator(), thread_id, os::current_process_id());
|
||||
}
|
||||
fp = fopen(fileBuf, "at");
|
||||
if (fp != NULL) {
|
||||
file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1);
|
||||
|
@ -363,7 +363,7 @@ bool defaultStream::has_log_file() {
|
||||
return _log_file != NULL;
|
||||
}
|
||||
|
||||
static const char* make_log_name(const char* log_name, const char* force_directory, char* buf) {
|
||||
static const char* make_log_name(const char* log_name, const char* force_directory) {
|
||||
const char* basename = log_name;
|
||||
char file_sep = os::file_separator()[0];
|
||||
const char* cp;
|
||||
@ -374,6 +374,27 @@ static const char* make_log_name(const char* log_name, const char* force_directo
|
||||
}
|
||||
const char* nametail = log_name;
|
||||
|
||||
// Compute buffer length
|
||||
size_t buffer_length;
|
||||
if (force_directory != NULL) {
|
||||
buffer_length = strlen(force_directory) + strlen(os::file_separator()) +
|
||||
strlen(basename) + 1;
|
||||
} else {
|
||||
buffer_length = strlen(log_name) + 1;
|
||||
}
|
||||
|
||||
const char* star = strchr(basename, '*');
|
||||
int star_pos = (star == NULL) ? -1 : (star - nametail);
|
||||
|
||||
char pid[32];
|
||||
if (star_pos >= 0) {
|
||||
jio_snprintf(pid, sizeof(pid), "%u", os::current_process_id());
|
||||
buffer_length += strlen(pid);
|
||||
}
|
||||
|
||||
// Create big enough buffer.
|
||||
char *buf = NEW_C_HEAP_ARRAY(char, buffer_length);
|
||||
|
||||
strcpy(buf, "");
|
||||
if (force_directory != NULL) {
|
||||
strcat(buf, force_directory);
|
||||
@ -381,14 +402,11 @@ static const char* make_log_name(const char* log_name, const char* force_directo
|
||||
nametail = basename; // completely skip directory prefix
|
||||
}
|
||||
|
||||
const char* star = strchr(basename, '*');
|
||||
int star_pos = (star == NULL) ? -1 : (star - nametail);
|
||||
|
||||
if (star_pos >= 0) {
|
||||
// convert foo*bar.log to foo123bar.log
|
||||
int buf_pos = (int) strlen(buf);
|
||||
strncpy(&buf[buf_pos], nametail, star_pos);
|
||||
sprintf(&buf[buf_pos + star_pos], "%u", os::current_process_id());
|
||||
strcpy(&buf[buf_pos + star_pos], pid);
|
||||
nametail += star_pos + 1; // skip prefix and star
|
||||
}
|
||||
|
||||
@ -399,20 +417,23 @@ static const char* make_log_name(const char* log_name, const char* force_directo
|
||||
void defaultStream::init_log() {
|
||||
// %%% Need a MutexLocker?
|
||||
const char* log_name = LogFile != NULL ? LogFile : "hotspot.log";
|
||||
char buf[O_BUFLEN*2];
|
||||
const char* try_name = make_log_name(log_name, NULL, buf);
|
||||
const char* try_name = make_log_name(log_name, NULL);
|
||||
fileStream* file = new(ResourceObj::C_HEAP) fileStream(try_name);
|
||||
if (!file->is_open()) {
|
||||
// Try again to open the file.
|
||||
char warnbuf[O_BUFLEN*2];
|
||||
sprintf(warnbuf, "Warning: Cannot open log file: %s\n", try_name);
|
||||
jio_snprintf(warnbuf, sizeof(warnbuf),
|
||||
"Warning: Cannot open log file: %s\n", try_name);
|
||||
// Note: This feature is for maintainer use only. No need for L10N.
|
||||
jio_print(warnbuf);
|
||||
try_name = make_log_name("hs_pid*.log", os::get_temp_directory(), buf);
|
||||
sprintf(warnbuf, "Warning: Forcing option -XX:LogFile=%s\n", try_name);
|
||||
FREE_C_HEAP_ARRAY(char, try_name);
|
||||
try_name = make_log_name("hs_pid*.log", os::get_temp_directory());
|
||||
jio_snprintf(warnbuf, sizeof(warnbuf),
|
||||
"Warning: Forcing option -XX:LogFile=%s\n", try_name);
|
||||
jio_print(warnbuf);
|
||||
delete file;
|
||||
file = new(ResourceObj::C_HEAP) fileStream(try_name);
|
||||
FREE_C_HEAP_ARRAY(char, try_name);
|
||||
}
|
||||
if (file->is_open()) {
|
||||
_log_file = file;
|
||||
|
@ -807,8 +807,8 @@ void VMError::report_and_die() {
|
||||
if (fd == -1) {
|
||||
// try temp directory
|
||||
const char * tmpdir = os::get_temp_directory();
|
||||
jio_snprintf(buffer, sizeof(buffer), "%shs_err_pid%u.log",
|
||||
(tmpdir ? tmpdir : ""), os::current_process_id());
|
||||
jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log",
|
||||
tmpdir, os::file_separator(), os::current_process_id());
|
||||
fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user