src/os/linux/vm/attachListener_linux.cpp
Print this page
rev 4897 : 7162400: Intermittent java.io.IOException: Bad file number during HotSpotVirtualMachine.executeCommand
Reviewed-by: duke
@@ -430,10 +430,32 @@
thread->check_and_wait_while_suspended();
return op;
}
+
+// Performs initialization at vm startup
+// For Linux we remove any stale .java_pid file which could cause
+// an attaching process to think we are ready to recieve on the
+// domain socket before we are properly initialized
+
+void AttachListener::vm_start() {
+ char fn[UNIX_PATH_MAX];
+ struct stat64 st;
+ int ret;
+
+ snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
+ os::get_temp_directory(), os::current_process_id());
+ RESTARTABLE(::stat64(fn, &st), ret);
+ if (ret == 0) {
+ ret = ::unlink(fn);
+ if(ret == -1) {
+ debug_only(warning("failed to remove stale attach pid file at %s", fn));
+ }
+ }
+}
+
int AttachListener::pd_init() {
JavaThread* thread = JavaThread::current();
ThreadBlockInVM tbivm(thread);
thread->set_suspend_equivalent();
@@ -462,17 +484,17 @@
// or /tmp then this is the trigger to start the attach mechanism
bool AttachListener::is_init_trigger() {
if (init_at_startup() || is_initialized()) {
return false; // initialized at startup or already initialized
}
- char fn[PATH_MAX+1];
- sprintf(fn, ".attach_pid%d", os::current_process_id());
+ char fn[UNIX_PATH_MAX];
+ snprintf(fn, UNIX_PATH_MAX, ".attach_pid%d", os::current_process_id());
int ret;
struct stat64 st;
RESTARTABLE(::stat64(fn, &st), ret);
if (ret == -1) {
- snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
+ snprintf(fn, UNIX_PATH_MAX, "%s/.attach_pid%d",
os::get_temp_directory(), os::current_process_id());
RESTARTABLE(::stat64(fn, &st), ret);
}
if (ret == 0) {
// simple check to avoid starting the attach mechanism when