diff options
author | Brian Inglis <Brian.Inglis@SystematicSW.ab.ca> | 2019-03-23 20:22:39 -0600 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2019-03-25 11:26:17 +0100 |
commit | 23bb2f660807bbc7321a143fa35ce659d79ba245 (patch) | |
tree | 808fc21d6c55b0c91ec088fbccb160a22472a80e /winsup/utils | |
parent | ee1ad64234b61f9deaae64b28313492188c1de43 (diff) | |
download | newlib-23bb2f660807bbc7321a143fa35ce659d79ba245.zip newlib-23bb2f660807bbc7321a143fa35ce659d79ba245.tar.gz newlib-23bb2f660807bbc7321a143fa35ce659d79ba245.tar.bz2 |
get and convert boot time once and use as needed
Diffstat (limited to 'winsup/utils')
-rw-r--r-- | winsup/utils/ps.cc | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc index c81805a..75a91f5 100644 --- a/winsup/utils/ps.cc +++ b/winsup/utils/ps.cc @@ -164,6 +164,7 @@ main (int argc, char *argv[]) const char *lfmt = "%c %7d %7d %7d %10u %4s %8u %8s %s\n"; char ch; void *drive_map = NULL; + time_t boot_time = -1; aflag = lflag = fflag = sflag = 0; uid = getuid (); @@ -237,9 +238,12 @@ main (int argc, char *argv[]) if (query == CW_GETPINFO_FULL) { + HANDLE tok; + NTSTATUS status; + SYSTEM_TIMEOFDAY_INFORMATION stodi; + /* Enable debug privilege to allow to enumerate all processes, not only processes in current session. */ - HANDLE tok; if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY | TOKEN_ADJUST_PRIVILEGES, &tok)) @@ -256,6 +260,15 @@ main (int argc, char *argv[]) } drive_map = (void *) cygwin_internal (CW_ALLOC_DRIVE_MAP); + + /* Get system boot time to default process start time */ + status = NtQuerySystemInformation (SystemTimeOfDayInformation, + (PVOID) &stodi, sizeof stodi, NULL); + if (!NT_SUCCESS (status)) + fprintf (stderr, + "NtQuerySystemInformation(SystemTimeOfDayInformation), " + "status %#010x\n", status); + boot_time = to_time_t ((FILETIME*)&stodi.BootTime); } for (int pid = 0; @@ -337,16 +350,10 @@ main (int argc, char *argv[]) p->start_time = to_time_t (&ct); CloseHandle (h); } + /* Default to boot time when process start time inaccessible, 0, -1 */ if (!h || 0 == p->start_time || -1 == p->start_time) { - SYSTEM_TIMEOFDAY_INFORMATION stodi; - status = NtQuerySystemInformation (SystemTimeOfDayInformation, - (PVOID) &stodi, sizeof stodi, NULL); - if (!NT_SUCCESS (status)) - fprintf (stderr, - "NtQuerySystemInformation(SystemTimeOfDayInformation), " - "status %08x", status); - p->start_time = to_time_t ((FILETIME*)&stodi.BootTime); + p->start_time = boot_time; } } |