< prev index next >

src/os/aix/vm/attachListener_aix.cpp

Print this page




 477 }
 478 
 479 // Performs initialization at vm startup
 480 // For AIX we remove any stale .java_pid file which could cause
 481 // an attaching process to think we are ready to receive on the
 482 // domain socket before we are properly initialized
 483 
 484 void AttachListener::vm_start() {
 485   char fn[UNIX_PATH_MAX];
 486   struct stat64 st;
 487   int ret;
 488 
 489   int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
 490            os::get_temp_directory(), os::current_process_id());
 491   assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
 492 
 493   RESTARTABLE(::stat64(fn, &st), ret);
 494   if (ret == 0) {
 495     ret = ::unlink(fn);
 496     if (ret == -1) {
 497       debug_only(warning("failed to remove stale attach pid file at %s", fn));
 498     }
 499   }
 500 }
 501 
 502 int AttachListener::pd_init() {
 503   JavaThread* thread = JavaThread::current();
 504   ThreadBlockInVM tbivm(thread);
 505 
 506   thread->set_suspend_equivalent();
 507   // cleared by handle_special_suspend_equivalent_condition() or
 508   // java_suspend_self() via check_and_wait_while_suspended()
 509 
 510   int ret_code = AixAttachListener::init();
 511 
 512   // were we externally suspended while we were waiting?
 513   thread->check_and_wait_while_suspended();
 514 
 515   return ret_code;
 516 }
 517 


 520 bool AttachListener::init_at_startup() {
 521   if (ReduceSignalUsage) {
 522     return true;
 523   } else {
 524     return false;
 525   }
 526 }
 527 
 528 // If the file .attach_pid<pid> exists in the working directory
 529 // or /tmp then this is the trigger to start the attach mechanism
 530 bool AttachListener::is_init_trigger() {
 531   if (init_at_startup() || is_initialized()) {
 532     return false;               // initialized at startup or already initialized
 533   }
 534   char fn[PATH_MAX+1];
 535   sprintf(fn, ".attach_pid%d", os::current_process_id());
 536   int ret;
 537   struct stat64 st;
 538   RESTARTABLE(::stat64(fn, &st), ret);
 539   if (ret == -1) {

 540     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 541              os::get_temp_directory(), os::current_process_id());
 542     RESTARTABLE(::stat64(fn, &st), ret);



 543   }
 544   if (ret == 0) {
 545     // simple check to avoid starting the attach mechanism when
 546     // a bogus user creates the file
 547     if (st.st_uid == geteuid()) {
 548       init();

 549       return true;


 550     }
 551   }
 552   return false;
 553 }
 554 
 555 // if VM aborts then remove listener
 556 void AttachListener::abort() {
 557   listener_cleanup();
 558 }
 559 
 560 void AttachListener::pd_data_dump() {
 561   os::signal_notify(SIGQUIT);
 562 }
 563 
 564 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
 565   return NULL;
 566 }
 567 
 568 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 569   out->print_cr("flag '%s' cannot be changed", op->arg(0));


 477 }
 478 
 479 // Performs initialization at vm startup
 480 // For AIX we remove any stale .java_pid file which could cause
 481 // an attaching process to think we are ready to receive on the
 482 // domain socket before we are properly initialized
 483 
 484 void AttachListener::vm_start() {
 485   char fn[UNIX_PATH_MAX];
 486   struct stat64 st;
 487   int ret;
 488 
 489   int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
 490            os::get_temp_directory(), os::current_process_id());
 491   assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
 492 
 493   RESTARTABLE(::stat64(fn, &st), ret);
 494   if (ret == 0) {
 495     ret = ::unlink(fn);
 496     if (ret == -1) {
 497       log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
 498     }
 499   }
 500 }
 501 
 502 int AttachListener::pd_init() {
 503   JavaThread* thread = JavaThread::current();
 504   ThreadBlockInVM tbivm(thread);
 505 
 506   thread->set_suspend_equivalent();
 507   // cleared by handle_special_suspend_equivalent_condition() or
 508   // java_suspend_self() via check_and_wait_while_suspended()
 509 
 510   int ret_code = AixAttachListener::init();
 511 
 512   // were we externally suspended while we were waiting?
 513   thread->check_and_wait_while_suspended();
 514 
 515   return ret_code;
 516 }
 517 


 520 bool AttachListener::init_at_startup() {
 521   if (ReduceSignalUsage) {
 522     return true;
 523   } else {
 524     return false;
 525   }
 526 }
 527 
 528 // If the file .attach_pid<pid> exists in the working directory
 529 // or /tmp then this is the trigger to start the attach mechanism
 530 bool AttachListener::is_init_trigger() {
 531   if (init_at_startup() || is_initialized()) {
 532     return false;               // initialized at startup or already initialized
 533   }
 534   char fn[PATH_MAX+1];
 535   sprintf(fn, ".attach_pid%d", os::current_process_id());
 536   int ret;
 537   struct stat64 st;
 538   RESTARTABLE(::stat64(fn, &st), ret);
 539   if (ret == -1) {
 540     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
 541     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 542              os::get_temp_directory(), os::current_process_id());
 543     RESTARTABLE(::stat64(fn, &st), ret);
 544     if (ret == -1) {
 545       log_debug(attach)("Failed to find attach file: %s", fn);
 546     }
 547   }
 548   if (ret == 0) {
 549     // simple check to avoid starting the attach mechanism when
 550     // a bogus user creates the file
 551     if (st.st_uid == geteuid()) {
 552       init();
 553       log_trace(attach)("Attach trigerred by %s", fn);
 554       return true;
 555     } else {
 556       log_debug(attach)("File %s has wrong user id %d (vs %d). Attach is not triggered", fn, st.st_uid, geteuid());
 557     }
 558   }
 559   return false;
 560 }
 561 
 562 // if VM aborts then remove listener
 563 void AttachListener::abort() {
 564   listener_cleanup();
 565 }
 566 
 567 void AttachListener::pd_data_dump() {
 568   os::signal_notify(SIGQUIT);
 569 }
 570 
 571 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
 572   return NULL;
 573 }
 574 
 575 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
 576   out->print_cr("flag '%s' cannot be changed", op->arg(0));
< prev index next >