439
440
441 // Performs initialization at vm startup
442 // For BSD we remove any stale .java_pid file which could cause
443 // an attaching process to think we are ready to receive on the
444 // domain socket before we are properly initialized
445
446 void AttachListener::vm_start() {
447 char fn[UNIX_PATH_MAX];
448 struct stat st;
449 int ret;
450
451 int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
452 os::get_temp_directory(), os::current_process_id());
453 assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
454
455 RESTARTABLE(::stat(fn, &st), ret);
456 if (ret == 0) {
457 ret = ::unlink(fn);
458 if (ret == -1) {
459 debug_only(warning("failed to remove stale attach pid file at %s", fn));
460 }
461 }
462 }
463
464 int AttachListener::pd_init() {
465 JavaThread* thread = JavaThread::current();
466 ThreadBlockInVM tbivm(thread);
467
468 thread->set_suspend_equivalent();
469 // cleared by handle_special_suspend_equivalent_condition() or
470 // java_suspend_self() via check_and_wait_while_suspended()
471
472 int ret_code = BsdAttachListener::init();
473
474 // were we externally suspended while we were waiting?
475 thread->check_and_wait_while_suspended();
476
477 return ret_code;
478 }
479
483 if (ReduceSignalUsage) {
484 return true;
485 } else {
486 return false;
487 }
488 }
489
490 // If the file .attach_pid<pid> exists in the working directory
491 // or /tmp then this is the trigger to start the attach mechanism
492 bool AttachListener::is_init_trigger() {
493 if (init_at_startup() || is_initialized()) {
494 return false; // initialized at startup or already initialized
495 }
496 char path[PATH_MAX + 1];
497 int ret;
498 struct stat st;
499
500 snprintf(path, PATH_MAX + 1, "%s/.attach_pid%d",
501 os::get_temp_directory(), os::current_process_id());
502 RESTARTABLE(::stat(path, &st), ret);
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));
|
439
440
441 // Performs initialization at vm startup
442 // For BSD we remove any stale .java_pid file which could cause
443 // an attaching process to think we are ready to receive on the
444 // domain socket before we are properly initialized
445
446 void AttachListener::vm_start() {
447 char fn[UNIX_PATH_MAX];
448 struct stat st;
449 int ret;
450
451 int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
452 os::get_temp_directory(), os::current_process_id());
453 assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
454
455 RESTARTABLE(::stat(fn, &st), ret);
456 if (ret == 0) {
457 ret = ::unlink(fn);
458 if (ret == -1) {
459 log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
460 }
461 }
462 }
463
464 int AttachListener::pd_init() {
465 JavaThread* thread = JavaThread::current();
466 ThreadBlockInVM tbivm(thread);
467
468 thread->set_suspend_equivalent();
469 // cleared by handle_special_suspend_equivalent_condition() or
470 // java_suspend_self() via check_and_wait_while_suspended()
471
472 int ret_code = BsdAttachListener::init();
473
474 // were we externally suspended while we were waiting?
475 thread->check_and_wait_while_suspended();
476
477 return ret_code;
478 }
479
483 if (ReduceSignalUsage) {
484 return true;
485 } else {
486 return false;
487 }
488 }
489
490 // If the file .attach_pid<pid> exists in the working directory
491 // or /tmp then this is the trigger to start the attach mechanism
492 bool AttachListener::is_init_trigger() {
493 if (init_at_startup() || is_initialized()) {
494 return false; // initialized at startup or already initialized
495 }
496 char path[PATH_MAX + 1];
497 int ret;
498 struct stat st;
499
500 snprintf(path, PATH_MAX + 1, "%s/.attach_pid%d",
501 os::get_temp_directory(), os::current_process_id());
502 RESTARTABLE(::stat(path, &st), ret);
503 if (ret == -1) {
504 log_debug(attach)("Failed to find attach file: %s", fn);
505 }
506 if (ret == 0) {
507 // simple check to avoid starting the attach mechanism when
508 // a bogus user creates the file
509 if (st.st_uid == geteuid()) {
510 init();
511 log_trace(attach)("Attach trigerred by %s", fn);
512 return true;
513 } else {
514 log_debug(attach)("File %s has wrong user id %d (vs %d). Attach is not triggered", fn, st.st_uid, geteuid());
515 }
516 }
517 return false;
518 }
519
520 // if VM aborts then remove listener
521 void AttachListener::abort() {
522 listener_cleanup();
523 }
524
525 void AttachListener::pd_data_dump() {
526 os::signal_notify(SIGQUIT);
527 }
528
529 AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
530 return NULL;
531 }
532
533 jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {
534 out->print_cr("flag '%s' cannot be changed", op->arg(0));
|