< prev index next >

src/hotspot/os/aix/attachListener_aix.cpp

Print this page

460 
461 
462 // AttachListener functions
463 
464 AttachOperation* AttachListener::dequeue() {
465   JavaThread* thread = JavaThread::current();
466   ThreadBlockInVM tbivm(thread);
467 
468   AttachOperation* op = AixAttachListener::dequeue();
469 
470   return op;
471 }
472 
473 // Performs initialization at vm startup
474 // For AIX we remove any stale .java_pid file which could cause
475 // an attaching process to think we are ready to receive on the
476 // domain socket before we are properly initialized
477 
478 void AttachListener::vm_start() {
479   char fn[UNIX_PATH_MAX];
480   struct stat64 st;
481   int ret;
482 
483   int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
484            os::get_temp_directory(), os::current_process_id());
485   assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
486 
487   RESTARTABLE(::stat64(fn, &st), ret);
488   if (ret == 0) {
489     ret = ::unlink(fn);
490     if (ret == -1) {
491       log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
492     }
493   }
494 }
495 
496 int AttachListener::pd_init() {
497   JavaThread* thread = JavaThread::current();
498   ThreadBlockInVM tbivm(thread);
499 
500   int ret_code = AixAttachListener::init();
501 
502   return ret_code;
503 }
504 
505 bool AttachListener::check_socket_file() {
506   int ret;
507   struct stat64 st;
508   ret = stat64(AixAttachListener::path(), &st);
509   if (ret == -1) { // need to restart attach listener.
510     log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
511                       AixAttachListener::path());
512 
513     listener_cleanup();
514 
515     // wait to terminate current attach listener instance...
516     {
517       // avoid deadlock if AttachListener thread is blocked at safepoint
518       ThreadBlockInVM tbivm(JavaThread::current());
519       while (AttachListener::transit_state(AL_INITIALIZING,
520                                            AL_NOT_INITIALIZED) != AL_NOT_INITIALIZED) {
521         os::naked_yield();
522       }
523     }
524     return is_init_trigger();
525   }
526   return false;
527 }
528 
529 // Attach Listener is started lazily except in the case when
530 // +ReduseSignalUsage is used
531 bool AttachListener::init_at_startup() {
532   if (ReduceSignalUsage) {
533     return true;
534   } else {
535     return false;
536   }
537 }
538 
539 // If the file .attach_pid<pid> exists in the working directory
540 // or /tmp then this is the trigger to start the attach mechanism
541 bool AttachListener::is_init_trigger() {
542   if (init_at_startup() || is_initialized()) {
543     return false;               // initialized at startup or already initialized
544   }
545   char fn[PATH_MAX + 1];
546   int ret;
547   struct stat64 st;
548   os::snprintf_checked(fn, sizeof(fn), ".attach_pid%d", os::current_process_id());
549   RESTARTABLE(::stat64(fn, &st), ret);
550   if (ret == -1) {
551     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
552     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
553              os::get_temp_directory(), os::current_process_id());
554     RESTARTABLE(::stat64(fn, &st), ret);
555     if (ret == -1) {
556       log_debug(attach)("Failed to find attach file: %s", fn);
557     }
558   }
559   if (ret == 0) {
560     // simple check to avoid starting the attach mechanism when
561     // a bogus non-root user creates the file
562     if (os::Posix::matches_effective_uid_or_root(st.st_uid)) {
563       init();
564       log_trace(attach)("Attach triggered by %s", fn);
565       return true;
566     } else {
567       log_debug(attach)("File %s has wrong user id %d (vs %d). Attach is not triggered", fn, st.st_uid, geteuid());
568     }
569   }
570   return false;
571 }
572 
573 // if VM aborts then remove listener
574 void AttachListener::abort() {

460 
461 
462 // AttachListener functions
463 
464 AttachOperation* AttachListener::dequeue() {
465   JavaThread* thread = JavaThread::current();
466   ThreadBlockInVM tbivm(thread);
467 
468   AttachOperation* op = AixAttachListener::dequeue();
469 
470   return op;
471 }
472 
473 // Performs initialization at vm startup
474 // For AIX we remove any stale .java_pid file which could cause
475 // an attaching process to think we are ready to receive on the
476 // domain socket before we are properly initialized
477 
478 void AttachListener::vm_start() {
479   char fn[UNIX_PATH_MAX];
480   struct stat st;
481   int ret;
482 
483   int n = snprintf(fn, UNIX_PATH_MAX, "%s/.java_pid%d",
484            os::get_temp_directory(), os::current_process_id());
485   assert(n < (int)UNIX_PATH_MAX, "java_pid file name buffer overflow");
486 
487   RESTARTABLE(::stat(fn, &st), ret);
488   if (ret == 0) {
489     ret = ::unlink(fn);
490     if (ret == -1) {
491       log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
492     }
493   }
494 }
495 
496 int AttachListener::pd_init() {
497   JavaThread* thread = JavaThread::current();
498   ThreadBlockInVM tbivm(thread);
499 
500   int ret_code = AixAttachListener::init();
501 
502   return ret_code;
503 }
504 
505 bool AttachListener::check_socket_file() {
506   int ret;
507   struct stat st;
508   ret = stat(AixAttachListener::path(), &st);
509   if (ret == -1) { // need to restart attach listener.
510     log_debug(attach)("Socket file %s does not exist - Restart Attach Listener",
511                       AixAttachListener::path());
512 
513     listener_cleanup();
514 
515     // wait to terminate current attach listener instance...
516     {
517       // avoid deadlock if AttachListener thread is blocked at safepoint
518       ThreadBlockInVM tbivm(JavaThread::current());
519       while (AttachListener::transit_state(AL_INITIALIZING,
520                                            AL_NOT_INITIALIZED) != AL_NOT_INITIALIZED) {
521         os::naked_yield();
522       }
523     }
524     return is_init_trigger();
525   }
526   return false;
527 }
528 
529 // Attach Listener is started lazily except in the case when
530 // +ReduseSignalUsage is used
531 bool AttachListener::init_at_startup() {
532   if (ReduceSignalUsage) {
533     return true;
534   } else {
535     return false;
536   }
537 }
538 
539 // If the file .attach_pid<pid> exists in the working directory
540 // or /tmp then this is the trigger to start the attach mechanism
541 bool AttachListener::is_init_trigger() {
542   if (init_at_startup() || is_initialized()) {
543     return false;               // initialized at startup or already initialized
544   }
545   char fn[PATH_MAX + 1];
546   int ret;
547   struct stat st;
548   os::snprintf_checked(fn, sizeof(fn), ".attach_pid%d", os::current_process_id());
549   RESTARTABLE(::stat(fn, &st), ret);
550   if (ret == -1) {
551     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
552     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
553              os::get_temp_directory(), os::current_process_id());
554     RESTARTABLE(::stat(fn, &st), ret);
555     if (ret == -1) {
556       log_debug(attach)("Failed to find attach file: %s", fn);
557     }
558   }
559   if (ret == 0) {
560     // simple check to avoid starting the attach mechanism when
561     // a bogus non-root user creates the file
562     if (os::Posix::matches_effective_uid_or_root(st.st_uid)) {
563       init();
564       log_trace(attach)("Attach triggered by %s", fn);
565       return true;
566     } else {
567       log_debug(attach)("File %s has wrong user id %d (vs %d). Attach is not triggered", fn, st.st_uid, geteuid());
568     }
569   }
570   return false;
571 }
572 
573 // if VM aborts then remove listener
574 void AttachListener::abort() {
< prev index next >