876 process_info->set_pid(atoi(_entry->d_name));
877
878 get_exe_name();
879 process_info->set_name(allocate_string(_exeName));
880
881 if (get_exe_path() != NULL) {
882 process_info->set_path(allocate_string(_exePath));
883 }
884
885 char* cmdline = NULL;
886 cmdline = get_cmdline();
887 if (cmdline != NULL) {
888 process_info->set_command_line(allocate_string(cmdline));
889 FREE_C_HEAP_ARRAY(char, cmdline);
890 }
891
892 return OS_OK;
893 }
894
895 int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
896 struct dirent* entry;
897
898 if (!is_valid()) {
899 return OS_ERR;
900 }
901
902 do {
903 entry = os::readdir(_dir, _entry);
904 if (entry == NULL) {
905 // error
906 _valid = false;
907 return OS_ERR;
908 }
909 if (_entry == NULL) {
910 // reached end
911 _valid = false;
912 return OS_ERR;
913 }
914 } while(!is_valid_entry(_entry));
915
916 _valid = true;
917 return OS_OK;
918 }
919
920 SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
921 _dir = NULL;
922 _entry = NULL;
923 _valid = false;
924 }
925
926 bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
927 // Not yet implemented.
928 return false;
929 }
930
931 SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
932 if (_entry != NULL) {
933 FREE_C_HEAP_ARRAY(char, _entry);
934 }
935 if (_dir != NULL) {
936 closedir(_dir);
937 }
938 }
939
940 SystemProcessInterface::SystemProcesses::SystemProcesses() {
941 _iterator = NULL;
942 }
943
944 bool SystemProcessInterface::SystemProcesses::initialize() {
945 _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
946 return NULL == _iterator ? false : _iterator->initialize();
947 }
948
949 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
950 if (_iterator != NULL) {
951 delete _iterator;
952 }
953 }
954
955 int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
956 assert(system_processes != NULL, "system_processes pointer is NULL!");
|
876 process_info->set_pid(atoi(_entry->d_name));
877
878 get_exe_name();
879 process_info->set_name(allocate_string(_exeName));
880
881 if (get_exe_path() != NULL) {
882 process_info->set_path(allocate_string(_exePath));
883 }
884
885 char* cmdline = NULL;
886 cmdline = get_cmdline();
887 if (cmdline != NULL) {
888 process_info->set_command_line(allocate_string(cmdline));
889 FREE_C_HEAP_ARRAY(char, cmdline);
890 }
891
892 return OS_OK;
893 }
894
895 int SystemProcessInterface::SystemProcesses::ProcessIterator::next_process() {
896 if (!is_valid()) {
897 return OS_ERR;
898 }
899
900 do {
901 _entry = os::readdir(_dir);
902 if (_entry == NULL) {
903 // Error or reached end. Could use errno to distinguish those cases.
904 _valid = false;
905 return OS_ERR;
906 }
907 } while(!is_valid_entry(_entry));
908
909 _valid = true;
910 return OS_OK;
911 }
912
913 SystemProcessInterface::SystemProcesses::ProcessIterator::ProcessIterator() {
914 _dir = NULL;
915 _entry = NULL;
916 _valid = false;
917 }
918
919 bool SystemProcessInterface::SystemProcesses::ProcessIterator::initialize() {
920 // Not yet implemented.
921 return false;
922 }
923
924 SystemProcessInterface::SystemProcesses::ProcessIterator::~ProcessIterator() {
925 if (_dir != NULL) {
926 os::closedir(_dir);
927 }
928 }
929
930 SystemProcessInterface::SystemProcesses::SystemProcesses() {
931 _iterator = NULL;
932 }
933
934 bool SystemProcessInterface::SystemProcesses::initialize() {
935 _iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
936 return NULL == _iterator ? false : _iterator->initialize();
937 }
938
939 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
940 if (_iterator != NULL) {
941 delete _iterator;
942 }
943 }
944
945 int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
946 assert(system_processes != NULL, "system_processes pointer is NULL!");
|