https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=57f1c81fb3e4a2581f5421350315755b07e509c8

commit 57f1c81fb3e4a2581f5421350315755b07e509c8
Author: Corinna Vinschen <[email protected]>
Date:   Tue Mar 12 11:34:50 2019 +0100

    Cygwin: proc: let stat info always succeed
    
    There's no good reason to return blank if some of the info
    couldn't be collected.  Drop useless call collecting
    SystemProcessorPerformanceInformation.  Always return some
    valid start_time, even if we couldn't collect ProcessTimes.
    
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/fhandler_process.cc | 70 +++++++++++++++++++++------------------
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/winsup/cygwin/fhandler_process.cc 
b/winsup/cygwin/fhandler_process.cc
index 576c5cb..31cd507 100644
--- a/winsup/cygwin/fhandler_process.cc
+++ b/winsup/cygwin/fhandler_process.cc
@@ -1091,12 +1091,12 @@ format_process_stat (void *data, char *&destbuf)
 
   NTSTATUS status;
   HANDLE hProcess;
-  VM_COUNTERS vmc;
-  KERNEL_USER_TIMES put;
-  PROCESS_BASIC_INFORMATION pbi;
-  QUOTA_LIMITS ql;
-  SYSTEM_TIMEOFDAY_INFORMATION stodi;
-  SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION spt;
+  VM_COUNTERS vmc = { 0 };
+  KERNEL_USER_TIMES put = { 0 };
+  PROCESS_BASIC_INFORMATION pbi = { 0 };
+  QUOTA_LIMITS ql = { 0 };
+  SYSTEM_TIMEOFDAY_INFORMATION stodi = { 0 };
+
   hProcess = OpenProcess (PROCESS_QUERY_LIMITED_INFORMATION,
                          FALSE, p->dwProcessId);
   if (hProcess == NULL)
@@ -1104,38 +1104,44 @@ format_process_stat (void *data, char *&destbuf)
       DWORD error = GetLastError ();
       __seterrno_from_win_error (error);
       debug_printf ("OpenProcess: ret %u", error);
-      return 0;
     }
-
-  status = NtQueryInformationProcess (hProcess, ProcessVmCounters,
-                                     (PVOID) &vmc, sizeof vmc, NULL);
-  if (NT_SUCCESS (status))
-    status = NtQueryInformationProcess (hProcess, ProcessTimes,
-                                       (PVOID) &put, sizeof put, NULL);
-  if (NT_SUCCESS (status))
-    status = NtQueryInformationProcess (hProcess, ProcessBasicInformation,
-                                       (PVOID) &pbi, sizeof pbi, NULL);
-  if (NT_SUCCESS (status))
-    status = NtQueryInformationProcess (hProcess, ProcessQuotaLimits,
-                                       (PVOID) &ql, sizeof ql, NULL);
-  CloseHandle (hProcess);
-  if (NT_SUCCESS (status))
-    status = NtQuerySystemInformation (SystemTimeOfDayInformation,
-                                      (PVOID) &stodi, sizeof stodi, NULL);
-  if (NT_SUCCESS (status))
-    status = NtQuerySystemInformation (SystemProcessorPerformanceInformation,
-                                      (PVOID) &spt, sizeof spt, NULL);
-  if (!NT_SUCCESS (status))
+  else
     {
-      __seterrno_from_nt_status (status);
-      debug_printf ("NtQueryInformationProcess: status %y, %E", status);
-      return 0;
+      status = NtQueryInformationProcess (hProcess, ProcessVmCounters,
+                                         (PVOID) &vmc, sizeof vmc, NULL);
+      if (!NT_SUCCESS (status))
+       debug_printf ("NtQueryInformationProcess(ProcessVmCounters): status %y",
+                     status);
+      status = NtQueryInformationProcess (hProcess, ProcessTimes,
+                                         (PVOID) &put, sizeof put, NULL);
+      if (!NT_SUCCESS (status))
+       debug_printf ("NtQueryInformationProcess(ProcessTimes): status %y",
+                     status);
+      status = NtQueryInformationProcess (hProcess, ProcessBasicInformation,
+                                         (PVOID) &pbi, sizeof pbi, NULL);
+      if (!NT_SUCCESS (status))
+       debug_printf ("NtQueryInformationProcess(ProcessBasicInformation): "
+                     "status %y", status);
+      status = NtQueryInformationProcess (hProcess, ProcessQuotaLimits,
+                                         (PVOID) &ql, sizeof ql, NULL);
+      if (!NT_SUCCESS (status))
+       debug_printf ("NtQueryInformationProcess(ProcessQuotaLimits): "
+                     "status %y", status);
+      CloseHandle (hProcess);
     }
+  status = NtQuerySystemInformation (SystemTimeOfDayInformation,
+                                    (PVOID) &stodi, sizeof stodi, NULL);
+  if (!NT_SUCCESS (status))
+    debug_printf ("NtQuerySystemInformation(SystemTimeOfDayInformation): "
+                 "status %y", status);
   fault_count = vmc.PageFaultCount;
   utime = put.UserTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
   stime = put.KernelTime.QuadPart * CLOCKS_PER_SEC / NS100PERSEC;
-  start_time = (put.CreateTime.QuadPart - stodi.BootTime.QuadPart)
-              * CLOCKS_PER_SEC / NS100PERSEC;
+  if (put.CreateTime.QuadPart)
+    start_time = (put.CreateTime.QuadPart - stodi.BootTime.QuadPart)
+                * CLOCKS_PER_SEC / NS100PERSEC;
+  else
+    start_time = (p->start_time - to_time_t (&stodi.BootTime)) * 
CLOCKS_PER_SEC;
   /* The BasePriority returned to a 32 bit process under WOW64 is
      apparently broken, for 32 and 64 bit target processes.  64 bit
      processes get the correct base priority, even for 32 bit processes. */

Reply via email to