add mapping from wmi HRESULT to NTRESULT

This commit is contained in:
Doug MacEachern 2009-09-01 15:39:33 -07:00
parent c6b35167c8
commit fdc0cf5c1f
2 changed files with 35 additions and 8 deletions

View File

@ -1445,7 +1445,11 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
} }
/* likely we are 32-bit, pid process is 64-bit */ /* likely we are 32-bit, pid process is 64-bit */
return sigar_proc_args_wmi_get(sigar, pid, procargs); status = sigar_proc_args_wmi_get(sigar, pid, procargs);
if (status == ERROR_NOT_FOUND) {
status = SIGAR_NO_SUCH_PROCESS;
}
return status;
} }
int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid, int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
@ -1609,6 +1613,9 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
/* likely we are 32-bit, pid process is 64-bit */ /* likely we are 32-bit, pid process is 64-bit */
/* procexe->cwd[0] = XXX where else can we try? */ /* procexe->cwd[0] = XXX where else can we try? */
status = sigar_proc_exe_wmi_get(sigar, pid, procexe); status = sigar_proc_exe_wmi_get(sigar, pid, procexe);
if (status == ERROR_NOT_FOUND) {
status = SIGAR_NO_SUCH_PROCESS;
}
} }
if (procexe->cwd[0] != '\0') { if (procexe->cwd[0] != '\0') {

View File

@ -42,15 +42,18 @@ class WMI {
HRESULT GetProcStringProperty(DWORD pid, TCHAR *name, TCHAR *value, DWORD len); HRESULT GetProcStringProperty(DWORD pid, TCHAR *name, TCHAR *value, DWORD len);
HRESULT GetProcExecutablePath(DWORD pid, TCHAR *value); HRESULT GetProcExecutablePath(DWORD pid, TCHAR *value);
HRESULT GetProcCommandLine(DWORD pid, TCHAR *value); HRESULT GetProcCommandLine(DWORD pid, TCHAR *value);
int GetLastError();
private: private:
IWbemServices *wbem; IWbemServices *wbem;
HRESULT result;
BSTR GetProcQuery(DWORD pid); BSTR GetProcQuery(DWORD pid);
}; };
WMI::WMI() WMI::WMI()
{ {
wbem = NULL; wbem = NULL;
result = S_OK;
CoInitializeEx(NULL, COINIT_MULTITHREADED); CoInitializeEx(NULL, COINIT_MULTITHREADED);
} }
@ -60,14 +63,31 @@ WMI::~WMI()
CoUninitialize(); CoUninitialize();
} }
/* XXX must be a better way to map HRESULT */
int WMI::GetLastError()
{
switch (result) {
case S_OK:
return ERROR_SUCCESS;
case WBEM_E_NOT_FOUND:
return ERROR_NOT_FOUND;
case WBEM_E_ACCESS_DENIED:
return ERROR_ACCESS_DENIED;
case WBEM_E_NOT_SUPPORTED:
return SIGAR_ENOTIMPL;
default:
return ERROR_INVALID_FUNCTION;
}
}
HRESULT WMI::Open(LPCTSTR machine, LPCTSTR user, LPCTSTR pass) HRESULT WMI::Open(LPCTSTR machine, LPCTSTR user, LPCTSTR pass)
{ {
HRESULT result;
IWbemLocator *locator; IWbemLocator *locator;
wchar_t path[MAX_PATH]; wchar_t path[MAX_PATH];
if (wbem) { if (wbem) {
return S_OK; result = S_OK;
return result;
} }
result = result =
@ -116,6 +136,7 @@ void WMI::Close()
if (wbem) { if (wbem) {
wbem->Release(); wbem->Release();
wbem = NULL; wbem = NULL;
result = S_OK;
} }
} }
@ -128,7 +149,6 @@ BSTR WMI::GetProcQuery(DWORD pid)
HRESULT WMI::GetProcStringProperty(DWORD pid, TCHAR *name, TCHAR *value, DWORD len) HRESULT WMI::GetProcStringProperty(DWORD pid, TCHAR *name, TCHAR *value, DWORD len)
{ {
HRESULT result;
IWbemClassObject *obj; IWbemClassObject *obj;
VARIANT var; VARIANT var;
@ -177,11 +197,11 @@ extern "C" int sigar_proc_args_wmi_get(sigar_t *sigar, sigar_pid_t pid,
WMI *wmi = new WMI(); WMI *wmi = new WMI();
if (FAILED(wmi->Open())) { if (FAILED(wmi->Open())) {
return GetLastError(); return wmi->GetLastError();
} }
if (FAILED(wmi->GetProcCommandLine(pid, buf))) { if (FAILED(wmi->GetProcCommandLine(pid, buf))) {
status = GetLastError(); status = wmi->GetLastError();
} }
else { else {
status = sigar_parse_proc_args(sigar, buf, procargs); status = sigar_parse_proc_args(sigar, buf, procargs);
@ -201,13 +221,13 @@ extern "C" int sigar_proc_exe_wmi_get(sigar_t *sigar, sigar_pid_t pid,
WMI *wmi = new WMI(); WMI *wmi = new WMI();
if (FAILED(wmi->Open())) { if (FAILED(wmi->Open())) {
return GetLastError(); return wmi->GetLastError();
} }
procexe->name[0] = '\0'; procexe->name[0] = '\0';
if (FAILED(wmi->GetProcExecutablePath(pid, buf))) { if (FAILED(wmi->GetProcExecutablePath(pid, buf))) {
status = GetLastError(); status = wmi->GetLastError();
} }
else { else {
status = SIGAR_OK; status = SIGAR_OK;