< 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");




 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");


< prev index next >