From c88b49abe230b380d6c1ede47b5dabb8d626d1ad Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 1 Sep 2009 14:09:46 -0700 Subject: [PATCH] (SIGAR-168) always fallback to wmi when peb fails for proc_args --- src/os/win32/peb.c | 11 ++++++----- src/os/win32/win32_sigar.c | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/os/win32/peb.c b/src/os/win32/peb.c index 153effe9..ed0147d1 100644 --- a/src/os/win32/peb.c +++ b/src/os/win32/peb.c @@ -171,15 +171,16 @@ int sigar_proc_args_peb_get(sigar_t *sigar, HANDLE proc, } size = rtl_bufsize(buf, rtl.CommandLine); + if (size <= 0) { + return ERROR_DATATYPE_MISMATCH; /* fallback to wmi */ + } memset(buf, '\0', sizeof(buf)); - - if ((size > 0) && - ReadProcessMemory(proc, rtl.CommandLine.Buffer, buf, size, NULL)) - { + + if (ReadProcessMemory(proc, rtl.CommandLine.Buffer, buf, size, NULL)) { return sigar_parse_proc_args(sigar, buf, procargs); } else { - return SIGAR_OK; + return GetLastError(); } } diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index 224edd40..ccbd4456 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -1434,20 +1434,18 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid, char cmdline[SIGAR_CMDLINE_MAX], *ptr = cmdline, *arg; HANDLE proc = open_process(pid); - if (!proc) { - return GetLastError(); + if (proc) { + status = sigar_proc_args_peb_get(sigar, proc, procargs); + + CloseHandle(proc); + + if (status == SIGAR_OK) { + return status; + } } - status = sigar_proc_args_peb_get(sigar, proc, procargs); - - CloseHandle(proc); - - if (status == ERROR_DATATYPE_MISMATCH) { - /* we are 32-bit, pid process is 64-bit */ - status = sigar_proc_args_wmi_get(sigar, pid, procargs); - } - - return status; + /* likely we are 32-bit, pid process is 64-bit */ + return sigar_proc_args_wmi_get(sigar, pid, procargs); } int sigar_os_proc_args_get(sigar_t *sigar, sigar_pid_t pid,