531 // open the directory and check if the file for the given vmid exists. |
531 // open the directory and check if the file for the given vmid exists. |
532 // The file with the expected name and the latest creation date is used |
532 // The file with the expected name and the latest creation date is used |
533 // to determine the user name for the process id. |
533 // to determine the user name for the process id. |
534 // |
534 // |
535 struct dirent* dentry; |
535 struct dirent* dentry; |
536 char* tdbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(tmpdirname), mtInternal); |
|
537 errno = 0; |
536 errno = 0; |
538 while ((dentry = os::readdir(tmpdirp, (struct dirent *)tdbuf)) != NULL) { |
537 while ((dentry = os::readdir(tmpdirp)) != NULL) { |
539 |
538 |
540 // check if the directory entry is a hsperfdata file |
539 // check if the directory entry is a hsperfdata file |
541 if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { |
540 if (strncmp(dentry->d_name, PERFDATA_NAME, strlen(PERFDATA_NAME)) != 0) { |
542 continue; |
541 continue; |
543 } |
542 } |
555 FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); |
554 FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); |
556 continue; |
555 continue; |
557 } |
556 } |
558 |
557 |
559 struct dirent* udentry; |
558 struct dirent* udentry; |
560 char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name), mtInternal); |
|
561 errno = 0; |
559 errno = 0; |
562 while ((udentry = os::readdir(subdirp, (struct dirent *)udbuf)) != NULL) { |
560 while ((udentry = os::readdir(subdirp)) != NULL) { |
563 |
561 |
564 if (filename_to_pid(udentry->d_name) == vmid) { |
562 if (filename_to_pid(udentry->d_name) == vmid) { |
565 struct stat statbuf; |
563 struct stat statbuf; |
566 int result; |
564 int result; |
567 |
565 |
601 |
599 |
602 FREE_C_HEAP_ARRAY(char, filename, mtInternal); |
600 FREE_C_HEAP_ARRAY(char, filename, mtInternal); |
603 } |
601 } |
604 } |
602 } |
605 os::closedir(subdirp); |
603 os::closedir(subdirp); |
606 FREE_C_HEAP_ARRAY(char, udbuf, mtInternal); |
|
607 FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); |
604 FREE_C_HEAP_ARRAY(char, usrdir_name, mtInternal); |
608 } |
605 } |
609 os::closedir(tmpdirp); |
606 os::closedir(tmpdirp); |
610 FREE_C_HEAP_ARRAY(char, tdbuf, mtInternal); |
|
611 |
607 |
612 return(oldest_user); |
608 return(oldest_user); |
613 } |
609 } |
614 |
610 |
615 // return the name of the user that owns the JVM indicated by the given vmid. |
611 // return the name of the user that owns the JVM indicated by the given vmid. |
684 // remove or create new files in this directory. The behavior of this |
680 // remove or create new files in this directory. The behavior of this |
685 // loop under these conditions is dependent upon the implementation of |
681 // loop under these conditions is dependent upon the implementation of |
686 // opendir/readdir. |
682 // opendir/readdir. |
687 // |
683 // |
688 struct dirent* entry; |
684 struct dirent* entry; |
689 char* dbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(dirname), mtInternal); |
|
690 |
|
691 errno = 0; |
685 errno = 0; |
692 while ((entry = os::readdir(dirp, (struct dirent *)dbuf)) != NULL) { |
686 while ((entry = os::readdir(dirp)) != NULL) { |
693 |
687 |
694 pid_t pid = filename_to_pid(entry->d_name); |
688 pid_t pid = filename_to_pid(entry->d_name); |
695 |
689 |
696 if (pid == 0) { |
690 if (pid == 0) { |
697 |
691 |
727 } |
721 } |
728 |
722 |
729 // close the directory and reset the current working directory |
723 // close the directory and reset the current working directory |
730 close_directory_secure_cwd(dirp, saved_cwd_fd); |
724 close_directory_secure_cwd(dirp, saved_cwd_fd); |
731 |
725 |
732 FREE_C_HEAP_ARRAY(char, dbuf, mtInternal); |
|
733 } |
726 } |
734 |
727 |
735 // make the user specific temporary directory. Returns true if |
728 // make the user specific temporary directory. Returns true if |
736 // the directory exists and is secure upon return. Returns false |
729 // the directory exists and is secure upon return. Returns false |
737 // if the directory exists but is either a symlink, is otherwise |
730 // if the directory exists but is either a symlink, is otherwise |