equal
deleted
inserted
replaced
602 |
602 |
603 return OS_OK; |
603 return OS_OK; |
604 } |
604 } |
605 |
605 |
606 int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() { |
606 int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() { |
607 struct dirent* entry; |
|
608 |
|
609 if (!is_valid()) { |
607 if (!is_valid()) { |
610 return OS_ERR; |
608 return OS_ERR; |
611 } |
609 } |
612 |
610 |
613 do { |
611 do { |
614 if ((entry = os::readdir(_dir, _entry)) == NULL) { |
612 _entry = os::readdir(_dir); |
615 // error |
613 if (_entry == NULL) { |
|
614 // Error or reached end. Could use errno to distinguish those cases. |
616 _valid = false; |
615 _valid = false; |
617 return OS_ERR; |
616 return OS_ERR; |
618 } |
617 } |
619 } while(!is_valid_entry(_entry)); |
618 } while(!is_valid_entry(_entry)); |
620 |
619 |
627 _entry = NULL; |
626 _entry = NULL; |
628 _valid = false; |
627 _valid = false; |
629 } |
628 } |
630 |
629 |
631 bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() { |
630 bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() { |
632 _dir = opendir("/proc"); |
631 _dir = os::opendir("/proc"); |
633 _entry = (struct dirent*)NEW_C_HEAP_ARRAY(char, sizeof(struct dirent) + _PC_NAME_MAX + 1, mtInternal); |
632 _entry = NULL; |
634 if (NULL == _entry) { |
|
635 return false; |
|
636 } |
|
637 _valid = true; |
633 _valid = true; |
638 next_process(); |
634 next_process(); |
639 |
635 |
640 return true; |
636 return true; |
641 } |
637 } |
642 |
638 |
643 SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() { |
639 SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() { |
644 if (_entry != NULL) { |
|
645 FREE_C_HEAP_ARRAY(char, _entry); |
|
646 } |
|
647 |
|
648 if (_dir != NULL) { |
640 if (_dir != NULL) { |
649 closedir(_dir); |
641 os::closedir(_dir); |
650 } |
642 } |
651 } |
643 } |
652 |
644 |
653 SystemProcessInterface::SystemProcesses::SystemProcesses() { |
645 SystemProcessInterface::SystemProcesses::SystemProcesses() { |
654 _iterator = NULL; |
646 _iterator = NULL; |