提交 9c9bc43d 编写于 作者: K kamg

Merge

...@@ -192,7 +192,8 @@ int LinuxAttachListener::init() { ...@@ -192,7 +192,8 @@ int LinuxAttachListener::init() {
res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
} }
if (res == -1) { 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); strcpy(addr.sun_path, path);
::unlink(path); ::unlink(path);
res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr)); res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
...@@ -460,13 +461,14 @@ bool AttachListener::is_init_trigger() { ...@@ -460,13 +461,14 @@ bool AttachListener::is_init_trigger() {
if (init_at_startup() || is_initialized()) { if (init_at_startup() || is_initialized()) {
return false; // initialized at startup or already initialized return false; // initialized at startup or already initialized
} }
char fn[32]; char fn[128];
sprintf(fn, ".attach_pid%d", os::current_process_id()); sprintf(fn, ".attach_pid%d", os::current_process_id());
int ret; int ret;
struct stat64 st; struct stat64 st;
RESTARTABLE(::stat64(fn, &st), ret); RESTARTABLE(::stat64(fn, &st), ret);
if (ret == -1) { 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); RESTARTABLE(::stat64(fn, &st), ret);
} }
if (ret == 0) { if (ret == 0) {
......
...@@ -1522,7 +1522,10 @@ int os::current_process_id() { ...@@ -1522,7 +1522,10 @@ int os::current_process_id() {
const char* os::dll_file_extension() { return ".so"; } 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) { static bool file_exists(const char* filename) {
struct stat statbuf; struct stat statbuf;
...@@ -2305,7 +2308,8 @@ void linux_wrap_code(char* base, size_t size) { ...@@ -2305,7 +2308,8 @@ void linux_wrap_code(char* base, size_t size) {
char buf[40]; char buf[40];
int num = Atomic::add(1, &cnt); 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); unlink(buf);
int fd = open(buf, O_CREAT | O_RDWR, S_IRWXU); int fd = open(buf, O_CREAT | O_RDWR, S_IRWXU);
......
...@@ -145,11 +145,11 @@ static char* get_user_tmp_dir(const char* user) { ...@@ -145,11 +145,11 @@ static char* get_user_tmp_dir(const char* user) {
const char* tmpdir = os::get_temp_directory(); const char* tmpdir = os::get_temp_directory();
const char* perfdir = PERFDATA_NAME; 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); char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
// construct the path name to user specific tmp directory // 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; return dirname;
} }
...@@ -331,8 +331,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -331,8 +331,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
char* usrdir_name = NEW_C_HEAP_ARRAY(char, 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); strcpy(usrdir_name, tmpdirname);
strcat(usrdir_name, "/");
strcat(usrdir_name, dentry->d_name); strcat(usrdir_name, dentry->d_name);
DIR* subdirp = os::opendir(usrdir_name); DIR* subdirp = os::opendir(usrdir_name);
......
...@@ -375,7 +375,8 @@ int SolarisAttachListener::create_door() { ...@@ -375,7 +375,8 @@ int SolarisAttachListener::create_door() {
return -1; 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); RESTARTABLE(::creat(door_path, S_IRUSR | S_IWUSR), fd);
if (fd == -1) { if (fd == -1) {
...@@ -591,13 +592,14 @@ bool AttachListener::is_init_trigger() { ...@@ -591,13 +592,14 @@ bool AttachListener::is_init_trigger() {
if (init_at_startup() || is_initialized()) { if (init_at_startup() || is_initialized()) {
return false; // initialized at startup or already initialized return false; // initialized at startup or already initialized
} }
char fn[32]; char fn[128];
sprintf(fn, ".attach_pid%d", os::current_process_id()); sprintf(fn, ".attach_pid%d", os::current_process_id());
int ret; int ret;
struct stat64 st; struct stat64 st;
RESTARTABLE(::stat64(fn, &st), ret); RESTARTABLE(::stat64(fn, &st), ret);
if (ret == -1) { 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); RESTARTABLE(::stat64(fn, &st), ret);
} }
if (ret == 0) { if (ret == 0) {
......
...@@ -676,15 +676,6 @@ bool os::have_special_privileges() { ...@@ -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() { void os::init_system_properties_values() {
char arch[12]; char arch[12];
sysinfo(SI_ARCHITECTURE, arch, sizeof(arch)); sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
...@@ -1826,7 +1817,10 @@ void os::set_error_file(const char *logfile) {} ...@@ -1826,7 +1817,10 @@ void os::set_error_file(const char *logfile) {}
const char* os::dll_file_extension() { return ".so"; } 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) { static bool file_exists(const char* filename) {
struct stat statbuf; struct stat statbuf;
......
...@@ -147,11 +147,11 @@ static char* get_user_tmp_dir(const char* user) { ...@@ -147,11 +147,11 @@ static char* get_user_tmp_dir(const char* user) {
const char* tmpdir = os::get_temp_directory(); const char* tmpdir = os::get_temp_directory();
const char* perfdir = PERFDATA_NAME; 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); char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
// construct the path name to user specific tmp directory // 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; return dirname;
} }
...@@ -322,8 +322,9 @@ static char* get_user_name_slow(int vmid, TRAPS) { ...@@ -322,8 +322,9 @@ static char* get_user_name_slow(int vmid, TRAPS) {
} }
char* usrdir_name = NEW_C_HEAP_ARRAY(char, 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); strcpy(usrdir_name, tmpdirname);
strcat(usrdir_name, "/");
strcat(usrdir_name, dentry->d_name); strcat(usrdir_name, dentry->d_name);
DIR* subdirp = os::opendir(usrdir_name); DIR* subdirp = os::opendir(usrdir_name);
......
...@@ -998,15 +998,16 @@ os::closedir(DIR *dirp) ...@@ -998,15 +998,16 @@ os::closedir(DIR *dirp)
const char* os::dll_file_extension() { return ".dll"; } const char* os::dll_file_extension() { return ".dll"; }
const char * os::get_temp_directory() const char* os::get_temp_directory() {
{ const char *prop = Arguments::get_property("java.io.tmpdir");
static char path_buf[MAX_PATH]; if (prop != 0) return prop;
if (GetTempPath(MAX_PATH, path_buf)>0) static char path_buf[MAX_PATH];
return path_buf; if (GetTempPath(MAX_PATH, path_buf)>0)
else{ return path_buf;
path_buf[0]='\0'; else{
return path_buf; path_buf[0]='\0';
} return path_buf;
}
} }
static bool file_exists(const char* filename) { static bool file_exists(const char* filename) {
......
...@@ -149,11 +149,11 @@ static char* get_user_tmp_dir(const char* user) { ...@@ -149,11 +149,11 @@ static char* get_user_tmp_dir(const char* user) {
const char* tmpdir = os::get_temp_directory(); const char* tmpdir = os::get_temp_directory();
const char* perfdir = PERFDATA_NAME; 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); char* dirname = NEW_C_HEAP_ARRAY(char, nbytes);
// construct the path name to user specific tmp directory // 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; return dirname;
} }
...@@ -318,8 +318,9 @@ static char* get_user_name_slow(int vmid) { ...@@ -318,8 +318,9 @@ static char* get_user_name_slow(int vmid) {
} }
char* usrdir_name = NEW_C_HEAP_ARRAY(char, 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); strcpy(usrdir_name, tmpdirname);
strcat(usrdir_name, "\\");
strcat(usrdir_name, dentry->d_name); strcat(usrdir_name, dentry->d_name);
DIR* subdirp = os::opendir(usrdir_name); DIR* subdirp = os::opendir(usrdir_name);
......
...@@ -1414,9 +1414,14 @@ void CompileBroker::init_compiler_thread_log() { ...@@ -1414,9 +1414,14 @@ void CompileBroker::init_compiler_thread_log() {
intx thread_id = os::current_thread_id(); intx thread_id = os::current_thread_id();
for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) { for (int try_temp_dir = 1; try_temp_dir >= 0; try_temp_dir--) {
const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL); const char* dir = (try_temp_dir ? os::get_temp_directory() : NULL);
if (dir == NULL) dir = ""; if (dir == NULL) {
sprintf(fileBuf, "%shs_c" UINTX_FORMAT "_pid%u.log", jio_snprintf(fileBuf, sizeof(fileBuf), "hs_c" UINTX_FORMAT "_pid%u.log",
dir, thread_id, os::current_process_id()); 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"); fp = fopen(fileBuf, "at");
if (fp != NULL) { if (fp != NULL) {
file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1); file = NEW_C_HEAP_ARRAY(char, strlen(fileBuf)+1);
......
...@@ -363,7 +363,7 @@ bool defaultStream::has_log_file() { ...@@ -363,7 +363,7 @@ bool defaultStream::has_log_file() {
return _log_file != NULL; 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; const char* basename = log_name;
char file_sep = os::file_separator()[0]; char file_sep = os::file_separator()[0];
const char* cp; const char* cp;
...@@ -374,6 +374,27 @@ static const char* make_log_name(const char* log_name, const char* force_directo ...@@ -374,6 +374,27 @@ static const char* make_log_name(const char* log_name, const char* force_directo
} }
const char* nametail = log_name; 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, ""); strcpy(buf, "");
if (force_directory != NULL) { if (force_directory != NULL) {
strcat(buf, force_directory); strcat(buf, force_directory);
...@@ -381,14 +402,11 @@ static const char* make_log_name(const char* log_name, const char* force_directo ...@@ -381,14 +402,11 @@ static const char* make_log_name(const char* log_name, const char* force_directo
nametail = basename; // completely skip directory prefix nametail = basename; // completely skip directory prefix
} }
const char* star = strchr(basename, '*');
int star_pos = (star == NULL) ? -1 : (star - nametail);
if (star_pos >= 0) { if (star_pos >= 0) {
// convert foo*bar.log to foo123bar.log // convert foo*bar.log to foo123bar.log
int buf_pos = (int) strlen(buf); int buf_pos = (int) strlen(buf);
strncpy(&buf[buf_pos], nametail, star_pos); 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 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 ...@@ -399,20 +417,23 @@ static const char* make_log_name(const char* log_name, const char* force_directo
void defaultStream::init_log() { void defaultStream::init_log() {
// %%% Need a MutexLocker? // %%% Need a MutexLocker?
const char* log_name = LogFile != NULL ? LogFile : "hotspot.log"; const char* log_name = LogFile != NULL ? LogFile : "hotspot.log";
char buf[O_BUFLEN*2]; const char* try_name = make_log_name(log_name, NULL);
const char* try_name = make_log_name(log_name, NULL, buf);
fileStream* file = new(ResourceObj::C_HEAP) fileStream(try_name); fileStream* file = new(ResourceObj::C_HEAP) fileStream(try_name);
if (!file->is_open()) { if (!file->is_open()) {
// Try again to open the file. // Try again to open the file.
char warnbuf[O_BUFLEN*2]; 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. // Note: This feature is for maintainer use only. No need for L10N.
jio_print(warnbuf); jio_print(warnbuf);
try_name = make_log_name("hs_pid*.log", os::get_temp_directory(), buf); FREE_C_HEAP_ARRAY(char, try_name);
sprintf(warnbuf, "Warning: Forcing option -XX:LogFile=%s\n", 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); jio_print(warnbuf);
delete file; delete file;
file = new(ResourceObj::C_HEAP) fileStream(try_name); file = new(ResourceObj::C_HEAP) fileStream(try_name);
FREE_C_HEAP_ARRAY(char, try_name);
} }
if (file->is_open()) { if (file->is_open()) {
_log_file = file; _log_file = file;
......
...@@ -807,8 +807,8 @@ void VMError::report_and_die() { ...@@ -807,8 +807,8 @@ void VMError::report_and_die() {
if (fd == -1) { if (fd == -1) {
// try temp directory // try temp directory
const char * tmpdir = os::get_temp_directory(); const char * tmpdir = os::get_temp_directory();
jio_snprintf(buffer, sizeof(buffer), "%shs_err_pid%u.log", jio_snprintf(buffer, sizeof(buffer), "%s%shs_err_pid%u.log",
(tmpdir ? tmpdir : ""), os::current_process_id()); tmpdir, os::file_separator(), os::current_process_id());
fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666); fd = open(buffer, O_WRONLY | O_CREAT | O_TRUNC, 0666);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册