< prev index next >

src/os/linux/vm/attachListener_linux.cpp

Print this page




 436 
 437 
 438 // Performs initialization at vm startup
 439 // For Linux we remove any stale .java_pid file which could cause
 440 // an attaching process to think we are ready to receive on the
 441 // domain socket before we are properly initialized
 442 
 443 void AttachListener::vm_start() {
 444   char fn[UNIX_PATH_MAX];
 445   struct stat64 st;
 446   int ret;
 447 
 448   int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
 449            os::get_temp_directory(), os::current_process_id());
 450   assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
 451 
 452   RESTARTABLE(::stat64(fn, &st), ret);
 453   if (ret == 0) {
 454     ret = ::unlink(fn);
 455     if (ret == -1) {
 456       debug_only(warning("failed to remove stale attach pid file at %s", fn));
 457     }
 458   }
 459 }
 460 
 461 int AttachListener::pd_init() {
 462   JavaThread* thread = JavaThread::current();
 463   ThreadBlockInVM tbivm(thread);
 464 
 465   thread->set_suspend_equivalent();
 466   // cleared by handle_special_suspend_equivalent_condition() or
 467   // java_suspend_self() via check_and_wait_while_suspended()
 468 
 469   int ret_code = LinuxAttachListener::init();
 470 
 471   // were we externally suspended while we were waiting?
 472   thread->check_and_wait_while_suspended();
 473 
 474   return ret_code;
 475 }
 476 


 479 bool AttachListener::init_at_startup() {
 480   if (ReduceSignalUsage) {
 481     return true;
 482   } else {
 483     return false;
 484   }
 485 }
 486 
 487 // If the file .attach_pid<pid> exists in the working directory
 488 // or /tmp then this is the trigger to start the attach mechanism
 489 bool AttachListener::is_init_trigger() {
 490   if (init_at_startup() || is_initialized()) {
 491     return false;               // initialized at startup or already initialized
 492   }
 493   char fn[PATH_MAX+1];
 494   sprintf(fn, ".attach_pid%d", os::current_process_id());
 495   int ret;
 496   struct stat64 st;
 497   RESTARTABLE(::stat64(fn, &st), ret);
 498   if (ret == -1) {

 499     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 500              os::get_temp_directory(), os::current_process_id());
 501     RESTARTABLE(::stat64(fn, &st), ret);



 502   }
 503   if (ret == 0) {
 504     // simple check to avoid starting the attach mechanism when
 505     // a bogus user creates the file
 506     if (st.st_uid == geteuid()) {
 507       init();

 508       return true;


 509     }
 510   }
 511   return false;
 512 }
 513 
 514 // if VM aborts then remove listener
 515 void AttachListener::abort() {
 516   listener_cleanup();
 517 }
 518 
 519 void AttachListener::pd_data_dump() {
 520   os::signal_notify(SIGQUIT);
 521 }
 522 
 523 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
 524   return NULL;
 525 }
 526 
 527 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 528   out->print_cr("flag '%s' cannot be changed", op->arg(0));


 436 
 437 
 438 // Performs initialization at vm startup
 439 // For Linux we remove any stale .java_pid file which could cause
 440 // an attaching process to think we are ready to receive on the
 441 // domain socket before we are properly initialized
 442 
 443 void AttachListener::vm_start() {
 444   char fn[UNIX_PATH_MAX];
 445   struct stat64 st;
 446   int ret;
 447 
 448   int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
 449            os::get_temp_directory(), os::current_process_id());
 450   assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
 451 
 452   RESTARTABLE(::stat64(fn, &st), ret);
 453   if (ret == 0) {
 454     ret = ::unlink(fn);
 455     if (ret == -1) {
 456       log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
 457     }
 458   }
 459 }
 460 
 461 int AttachListener::pd_init() {
 462   JavaThread* thread = JavaThread::current();
 463   ThreadBlockInVM tbivm(thread);
 464 
 465   thread->set_suspend_equivalent();
 466   // cleared by handle_special_suspend_equivalent_condition() or
 467   // java_suspend_self() via check_and_wait_while_suspended()
 468 
 469   int ret_code = LinuxAttachListener::init();
 470 
 471   // were we externally suspended while we were waiting?
 472   thread->check_and_wait_while_suspended();
 473 
 474   return ret_code;
 475 }
 476 


 479 bool AttachListener::init_at_startup() {
 480   if (ReduceSignalUsage) {
 481     return true;
 482   } else {
 483     return false;
 484   }
 485 }
 486 
 487 // If the file .attach_pid<pid> exists in the working directory
 488 // or /tmp then this is the trigger to start the attach mechanism
 489 bool AttachListener::is_init_trigger() {
 490   if (init_at_startup() || is_initialized()) {
 491     return false;               // initialized at startup or already initialized
 492   }
 493   char fn[PATH_MAX+1];
 494   sprintf(fn, ".attach_pid%d", os::current_process_id());
 495   int ret;
 496   struct stat64 st;
 497   RESTARTABLE(::stat64(fn, &st), ret);
 498   if (ret == -1) {
 499     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
 500     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 501              os::get_temp_directory(), os::current_process_id());
 502     RESTARTABLE(::stat64(fn, &st), ret);
 503     if (ret == -1) {
 504       log_debug(attach)("Failed to find attach file: %s", fn);
 505     }
 506   }
 507   if (ret == 0) {
 508     // simple check to avoid starting the attach mechanism when
 509     // a bogus user creates the file
 510     if (st.st_uid == geteuid()) {
 511       init();
 512       log_trace(attach)("Attach trigerred by %s", fn);
 513       return true;
 514     } else {
 515       log_debug(attach)("File %s has wrong user id %d (vs %d). Attach is not trigerred", fn, st.st_uid, geteuid());
 516     }
 517   }
 518   return false;
 519 }
 520 
 521 // if VM aborts then remove listener
 522 void AttachListener::abort() {
 523   listener_cleanup();
 524 }
 525 
 526 void AttachListener::pd_data_dump() {
 527   os::signal_notify(SIGQUIT);
 528 }
 529 
 530 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
 531   return NULL;
 532 }
 533 
 534 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 535   out->print_cr("flag '%s' cannot be changed", op->arg(0));
< prev index next >