< prev index next >

src/hotspot/os/solaris/os_perf_solaris.cpp

Print this page
rev 50955 : [mq]: readdir


 587     }
 588   }
 589 
 590   process_info->set_pid(atoi(_entry->d_name));
 591   process_info->set_name(allocate_string(psinfo_data.pr_fname));
 592   process_info->set_path(allocate_string(exe_path));
 593   process_info->set_command_line(allocate_string(psinfo_data.pr_psargs));
 594 
 595   if (exe_path != NULL) {
 596     FREE_C_HEAP_ARRAY(char, exe_path);
 597   }
 598 
 599   if (fp != NULL) {
 600     fclose(fp);
 601   }
 602 
 603   return OS_OK;
 604 }
 605 
 606 int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
 607   struct dirent* entry;
 608 
 609   if (!is_valid()) {
 610     return OS_ERR;
 611   }
 612 
 613   do {
 614     if ((entry = os::readdir(_dir, _entry)) == NULL) {
 615       // error

 616       _valid = false;
 617       return OS_ERR;
 618     }
 619   } while(!is_valid_entry(_entry));
 620 
 621   _valid = true;
 622   return OS_OK;
 623 }
 624 
 625 SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
 626   _dir = NULL;
 627   _entry = NULL;
 628   _valid = false;
 629 }
 630 
 631 bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
 632   _dir = opendir("/proc");
 633   _entry = (struct dirent*)NEW_C_HEAP_ARRAY(char, sizeof(struct dirent) + _PC_NAME_MAX + 1, mtInternal);
 634   if (NULL == _entry) {
 635     return false;
 636   }
 637   _valid = true;
 638   next_process();
 639 
 640   return true;
 641 }
 642 
 643 SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
 644   if (_entry != NULL) {
 645     FREE_C_HEAP_ARRAY(char, _entry);
 646   }
 647 
 648   if (_dir != NULL) {
 649     closedir(_dir);
 650   }
 651 }
 652 
 653 SystemProcessInterface::SystemProcesses::SystemProcesses() {
 654   _iterator = NULL;
 655 }
 656 
 657 bool SystemProcessInterface::SystemProcesses::initialize() {
 658   _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
 659   return _iterator != NULL && _iterator->initialize();
 660 }
 661 
 662 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
 663   if (_iterator != NULL) {
 664     delete _iterator;
 665   }
 666 }
 667 
 668 int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
 669   assert(system_processes != NULL, "system_processes pointer is NULL!");




 587     }
 588   }
 589 
 590   process_info->set_pid(atoi(_entry->d_name));
 591   process_info->set_name(allocate_string(psinfo_data.pr_fname));
 592   process_info->set_path(allocate_string(exe_path));
 593   process_info->set_command_line(allocate_string(psinfo_data.pr_psargs));
 594 
 595   if (exe_path != NULL) {
 596     FREE_C_HEAP_ARRAY(char, exe_path);
 597   }
 598 
 599   if (fp != NULL) {
 600     fclose(fp);
 601   }
 602 
 603   return OS_OK;
 604 }
 605 
 606 int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {


 607   if (!is_valid()) {
 608     return OS_ERR;
 609   }
 610 
 611   do {
 612     _entry = os::readdir(_dir);
 613     if (_entry == NULL) {
 614       // Error or reached end.  Could use errno to distinguish those cases.
 615       _valid = false;
 616       return OS_ERR;
 617     }
 618   } while(!is_valid_entry(_entry));
 619 
 620   _valid = true;
 621   return OS_OK;
 622 }
 623 
 624 SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
 625   _dir = NULL;
 626   _entry = NULL;
 627   _valid = false;
 628 }
 629 
 630 bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
 631   _dir = os::opendir("/proc");
 632   _entry = NULL;



 633   _valid = true;
 634   next_process();
 635 
 636   return true;
 637 }
 638 
 639 SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {




 640   if (_dir != NULL) {
 641     os::closedir(_dir);
 642   }
 643 }
 644 
 645 SystemProcessInterface::SystemProcesses::SystemProcesses() {
 646   _iterator = NULL;
 647 }
 648 
 649 bool SystemProcessInterface::SystemProcesses::initialize() {
 650   _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
 651   return _iterator != NULL && _iterator->initialize();
 652 }
 653 
 654 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
 655   if (_iterator != NULL) {
 656     delete _iterator;
 657   }
 658 }
 659 
 660 int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
 661   assert(system_processes != NULL, "system_processes pointer is NULL!");


< prev index next >