Ignore:
Timestamp:
04/28/05 20:17:32 (8 years ago)
Author:
Michael Medin <michael@…>
Children:
7b04f88
Parents:
ae192e3
Message:
  • Fixed multitasking socket listsner (had a hard-to-find memory leak)
  • Changed ProcessEnumeration? class to one that should work on NT4 New option to set this in the config file. + Added some more options to the config file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/modules/CheckSystem/CheckSystem.cpp

    rae192e3 rf22f5a9  
    77#include <tlhelp32.h> 
    88#include <EnumNtSrv.h> 
     9#include <EnumProcess.h> 
    910 
    1011CheckSystem gNSClientCompat; 
     
    2728 * @return  
    2829 */ 
    29 CheckSystem::CheckSystem() {} 
     30CheckSystem::CheckSystem() : processMethod_(0) {} 
    3031/** 
    3132 * Default d-tor 
     
    4041bool CheckSystem::loadModule() { 
    4142  pdhThread.createThread(); 
     43 
     44  std::string wantedMethod = NSCModuleHelper::getSettingsString(C_SYSTEM_SECTION_TITLE, C_SYSTEM_ENUMPROC_METHOD, C_SYSTEM_ENUMPROC_METHOD_DEFAULT); 
     45 
     46  CEnumProcess tmp; 
     47  int method = tmp.GetAvailableMethods(); 
     48 
     49  if (wantedMethod == C_SYSTEM_ENUMPROC_METHOD_PSAPI) { 
     50    if (method == (method|ENUM_METHOD::PSAPI)) { 
     51      processMethod_ = ENUM_METHOD::PSAPI; 
     52    } else { 
     53      NSC_LOG_ERROR_STD("PSAPI method not avalible, check " C_SYSTEM_ENUMPROC_METHOD " option."); 
     54    } 
     55  } else { 
     56    if (method == (method|ENUM_METHOD::TOOLHELP)) { 
     57      processMethod_ = ENUM_METHOD::TOOLHELP; 
     58    } else { 
     59      NSC_LOG_ERROR_STD("TOOLHELP method not avalible, check " C_SYSTEM_ENUMPROC_METHOD " option."); 
     60    } 
     61  } 
    4262  return true; 
    4363} 
     
    109129    return checkCounter(command, argLen, char_args, msg, perf); 
    110130  } 
    111 /* 
    112     case REQ_PROCSTATE: 
    113       rb = NSCommands::procState(arrayBuffer::arrayBuffer2list(argLen, char_args)); 
    114       msg = rb.msg_; 
    115       perf = rb.perf_; 
    116       return rb.code_; 
    117   */ 
    118131  return NSCAPI::returnIgnored; 
    119132} 
     
    390403* @return a hash_map with all running processes 
    391404*/ 
    392 NSPROCLST GetProcessList(void) 
    393 { 
    394   HANDLE hProcessSnap; 
    395   PROCESSENTRY32 pe32; 
     405NSPROCLST GetProcessList(int processMethod) 
     406{ 
    396407  NSPROCLST ret; 
    397  
    398   // Take a snapshot of all processes in the system. 
    399   hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 ); 
    400   if( hProcessSnap == INVALID_HANDLE_VALUE ) 
    401     throw "CreateToolhelp32Snapshot (of processes) failed"; 
    402  
    403   // Set the size of the structure before using it. 
    404   pe32.dwSize = sizeof( PROCESSENTRY32 ); 
    405  
    406   // Retrieve information about the first process, 
    407   // and exit if unsuccessful 
    408   if( !Process32First( hProcessSnap, &pe32 ) ) { 
    409     CloseHandle( hProcessSnap );     // Must clean up the snapshot object! 
    410     throw "Process32First failed!"; 
    411   } 
    412  
    413   // Now walk the snapshot of processes, and 
    414   // display information about each process in turn 
    415   do { 
    416     ret[pe32.szExeFile] = pe32.th32ProcessID; 
    417   } while( Process32Next( hProcessSnap, &pe32 ) ); 
    418  
    419   // Don't forget to clean up the snapshot object! 
    420   CloseHandle( hProcessSnap ); 
     408  if (processMethod == 0) { 
     409    NSC_LOG_ERROR_STD("ProcessMethod not defined or not available."); 
     410    return ret; 
     411  } 
     412  CEnumProcess enumeration; 
     413  enumeration.SetMethod(processMethod); 
     414  CEnumProcess::CProcessEntry entry; 
     415  for (BOOL OK = enumeration.GetProcessFirst(&entry); OK; OK = enumeration.GetProcessNext(&entry) ) { 
     416    ret[entry.lpFilename] = entry.dwPID; 
     417  } 
    421418  return ret; 
    422419} 
     
    452449  NSPROCLST runningProcs; 
    453450  try { 
    454     runningProcs = GetProcessList(); 
     451    runningProcs = GetProcessList(processMethod_); 
    455452  } catch (char *c) { 
    456453    NSC_LOG_ERROR_STD("ERROR: " + c); 
Note: See TracChangeset for help on using the changeset viewer.