< prev index next >

src/os/solaris/vm/attachListener_solaris.cpp

Print this page




 377 int SolarisAttachListener::create_door() {
 378   char door_path[PATH_MAX+1];
 379   char initial_path[PATH_MAX+1];
 380   int fd, res;
 381 
 382   // register exit function
 383   ::atexit(listener_cleanup);
 384 
 385   // create the door descriptor
 386   int dd = ::door_create(enqueue_proc, NULL, 0);
 387   if (dd < 0) {
 388     return -1;
 389   }
 390 
 391   // create initial file to attach door descriptor
 392   snprintf(door_path, sizeof(door_path), "%s/.java_pid%d",
 393            os::get_temp_directory(), os::current_process_id());
 394   snprintf(initial_path, sizeof(initial_path), "%s.tmp", door_path);
 395   RESTARTABLE(::creat(initial_path, S_IRUSR | S_IWUSR), fd);
 396   if (fd == -1) {
 397     debug_only(warning("attempt to create %s failed", initial_path));
 398     ::door_revoke(dd);
 399     return -1;
 400   }
 401   assert(fd >= 0, "bad file descriptor");
 402   ::close(fd);
 403 
 404   // attach the door descriptor to the file
 405   if ((res = ::fattach(dd, initial_path)) == -1) {
 406     // if busy then detach and try again
 407     if (errno == EBUSY) {
 408       ::fdetach(initial_path);
 409       res = ::fattach(dd, initial_path);
 410     }
 411     if (res == -1) {

 412       ::door_revoke(dd);
 413       dd = -1;
 414     }
 415   }
 416 
 417   // rename file so that clients can attach
 418   if (dd >= 0) {
 419     if (::rename(initial_path, door_path) == -1) {
 420         ::close(dd);
 421         ::fdetach(initial_path);

 422         dd = -1;
 423     }
 424   }
 425   if (dd >= 0) {
 426     set_door_descriptor(dd);
 427     set_door_path(door_path);

 428   } else {
 429     // unable to create door, attach it to file, or rename file into place
 430     ::unlink(initial_path);
 431     return -1;
 432   }
 433 
 434   return 0;
 435 }
 436 
 437 // Initialization - create the door, locks, and other initialization
 438 int SolarisAttachListener::init() {
 439   if (create_door()) {
 440     return -1;
 441   }
 442 
 443   int status = os::Solaris::mutex_init(&_mutex);
 444   assert_status(status==0, status, "mutex_init");
 445 
 446   status = ::sema_init(&_wakeup, 0, NULL, NULL);
 447   assert_status(status==0, status, "sema_init");


 585 
 586 
 587 // Performs initialization at vm startup
 588 // For Solaris we remove any stale .java_pid file which could cause
 589 // an attaching process to think we are ready to receive a door_call
 590 // before we are properly initialized
 591 
 592 void AttachListener::vm_start() {
 593   char fn[PATH_MAX+1];
 594   struct stat64 st;
 595   int ret;
 596 
 597   int n = snprintf(fn, sizeof(fn), "%s/.java_pid%d",
 598            os::get_temp_directory(), os::current_process_id());
 599   assert(n < sizeof(fn), "java_pid file name buffer overflow");
 600 
 601   RESTARTABLE(::stat64(fn, &st), ret);
 602   if (ret == 0) {
 603     ret = ::unlink(fn);
 604     if (ret == -1) {
 605       debug_only(warning("failed to remove stale attach pid file at %s", fn));
 606     }
 607   }
 608 }
 609 
 610 int AttachListener::pd_init() {
 611   JavaThread* thread = JavaThread::current();
 612   ThreadBlockInVM tbivm(thread);
 613 
 614   thread->set_suspend_equivalent();
 615   // cleared by handle_special_suspend_equivalent_condition() or
 616   // java_suspend_self()
 617 
 618   int ret_code = SolarisAttachListener::init();
 619 
 620   // were we externally suspended while we were waiting?
 621   thread->check_and_wait_while_suspended();
 622 
 623   return ret_code;
 624 }
 625 


 628 bool AttachListener::init_at_startup() {
 629   if (ReduceSignalUsage) {
 630     return true;
 631   } else {
 632     return false;
 633   }
 634 }
 635 
 636 // If the file .attach_pid<pid> exists in the working directory
 637 // or /tmp then this is the trigger to start the attach mechanism
 638 bool AttachListener::is_init_trigger() {
 639   if (init_at_startup() || is_initialized()) {
 640     return false;               // initialized at startup or already initialized
 641   }
 642   char fn[PATH_MAX+1];
 643   sprintf(fn, ".attach_pid%d", os::current_process_id());
 644   int ret;
 645   struct stat64 st;
 646   RESTARTABLE(::stat64(fn, &st), ret);
 647   if (ret == -1) {

 648     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 649              os::get_temp_directory(), os::current_process_id());
 650     RESTARTABLE(::stat64(fn, &st), ret);



 651   }
 652   if (ret == 0) {
 653     // simple check to avoid starting the attach mechanism when
 654     // a bogus user creates the file
 655     if (st.st_uid == geteuid()) {
 656       init();
 657       return true;
 658     }
 659   }
 660   return false;
 661 }
 662 
 663 // if VM aborts then detach/cleanup
 664 void AttachListener::abort() {
 665   listener_cleanup();
 666 }
 667 
 668 void AttachListener::pd_data_dump() {
 669   os::signal_notify(SIGQUIT);
 670 }




 377 int SolarisAttachListener::create_door() {
 378   char door_path[PATH_MAX+1];
 379   char initial_path[PATH_MAX+1];
 380   int fd, res;
 381 
 382   // register exit function
 383   ::atexit(listener_cleanup);
 384 
 385   // create the door descriptor
 386   int dd = ::door_create(enqueue_proc, NULL, 0);
 387   if (dd < 0) {
 388     return -1;
 389   }
 390 
 391   // create initial file to attach door descriptor
 392   snprintf(door_path, sizeof(door_path), "%s/.java_pid%d",
 393            os::get_temp_directory(), os::current_process_id());
 394   snprintf(initial_path, sizeof(initial_path), "%s.tmp", door_path);
 395   RESTARTABLE(::creat(initial_path, S_IRUSR | S_IWUSR), fd);
 396   if (fd == -1) {
 397     log_debug(attach)("attempt to create door file %s failed (%d)", initial_path, errno);
 398     ::door_revoke(dd);
 399     return -1;
 400   }
 401   assert(fd >= 0, "bad file descriptor");
 402   ::close(fd);
 403 
 404   // attach the door descriptor to the file
 405   if ((res = ::fattach(dd, initial_path)) == -1) {
 406     // if busy then detach and try again
 407     if (errno == EBUSY) {
 408       ::fdetach(initial_path);
 409       res = ::fattach(dd, initial_path);
 410     }
 411     if (res == -1) {
 412       log_debug(attach)("unable to create door - fattach failed (%d)", errno);
 413       ::door_revoke(dd);
 414       dd = -1;
 415     }
 416   }
 417 
 418   // rename file so that clients can attach
 419   if (dd >= 0) {
 420     if (::rename(initial_path, door_path) == -1) {
 421         ::close(dd);
 422         ::fdetach(initial_path);
 423         log_debug(attach)("unable to create door - rename %s to %s failed (%d)", errno);
 424         dd = -1;
 425     }
 426   }
 427   if (dd >= 0) {
 428     set_door_descriptor(dd);
 429     set_door_path(door_path);
 430     log_trace(attach)("door file %s created succesfully", door_path);
 431   } else {
 432     // unable to create door, attach it to file, or rename file into place
 433     ::unlink(initial_path);
 434     return -1;
 435   }
 436 
 437   return 0;
 438 }
 439 
 440 // Initialization - create the door, locks, and other initialization
 441 int SolarisAttachListener::init() {
 442   if (create_door()) {
 443     return -1;
 444   }
 445 
 446   int status = os::Solaris::mutex_init(&_mutex);
 447   assert_status(status==0, status, "mutex_init");
 448 
 449   status = ::sema_init(&_wakeup, 0, NULL, NULL);
 450   assert_status(status==0, status, "sema_init");


 588 
 589 
 590 // Performs initialization at vm startup
 591 // For Solaris we remove any stale .java_pid file which could cause
 592 // an attaching process to think we are ready to receive a door_call
 593 // before we are properly initialized
 594 
 595 void AttachListener::vm_start() {
 596   char fn[PATH_MAX+1];
 597   struct stat64 st;
 598   int ret;
 599 
 600   int n = snprintf(fn, sizeof(fn), "%s/.java_pid%d",
 601            os::get_temp_directory(), os::current_process_id());
 602   assert(n < sizeof(fn), "java_pid file name buffer overflow");
 603 
 604   RESTARTABLE(::stat64(fn, &st), ret);
 605   if (ret == 0) {
 606     ret = ::unlink(fn);
 607     if (ret == -1) {
 608       log_debug(attach)("Failed to remove stale attach pid file at %s", fn);
 609     }
 610   }
 611 }
 612 
 613 int AttachListener::pd_init() {
 614   JavaThread* thread = JavaThread::current();
 615   ThreadBlockInVM tbivm(thread);
 616 
 617   thread->set_suspend_equivalent();
 618   // cleared by handle_special_suspend_equivalent_condition() or
 619   // java_suspend_self()
 620 
 621   int ret_code = SolarisAttachListener::init();
 622 
 623   // were we externally suspended while we were waiting?
 624   thread->check_and_wait_while_suspended();
 625 
 626   return ret_code;
 627 }
 628 


 631 bool AttachListener::init_at_startup() {
 632   if (ReduceSignalUsage) {
 633     return true;
 634   } else {
 635     return false;
 636   }
 637 }
 638 
 639 // If the file .attach_pid<pid> exists in the working directory
 640 // or /tmp then this is the trigger to start the attach mechanism
 641 bool AttachListener::is_init_trigger() {
 642   if (init_at_startup() || is_initialized()) {
 643     return false;               // initialized at startup or already initialized
 644   }
 645   char fn[PATH_MAX+1];
 646   sprintf(fn, ".attach_pid%d", os::current_process_id());
 647   int ret;
 648   struct stat64 st;
 649   RESTARTABLE(::stat64(fn, &st), ret);
 650   if (ret == -1) {
 651     log_trace(attach)("Failed to find attach file: %s, trying alternate", fn);
 652     snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
 653              os::get_temp_directory(), os::current_process_id());
 654     RESTARTABLE(::stat64(fn, &st), ret);
 655     if (ret == -1) {
 656       log_debug(attach)("Failed to find attach file: %s", fn);
 657     }
 658   }
 659   if (ret == 0) {
 660     // simple check to avoid starting the attach mechanism when
 661     // a bogus user creates the file
 662     if (st.st_uid == geteuid()) {
 663       init();
 664       return true;
 665     }
 666   }
 667   return false;
 668 }
 669 
 670 // if VM aborts then detach/cleanup
 671 void AttachListener::abort() {
 672   listener_cleanup();
 673 }
 674 
 675 void AttachListener::pd_data_dump() {
 676   os::signal_notify(SIGQUIT);
 677 }


< prev index next >