Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Inglis <Brian.Inglis@SystematicSW.ab.ca>2019-03-24 05:22:39 +0300
committerCorinna Vinschen <corinna@vinschen.de>2019-03-25 13:26:17 +0300
commit23bb2f660807bbc7321a143fa35ce659d79ba245 (patch)
tree808fc21d6c55b0c91ec088fbccb160a22472a80e /winsup/utils/ps.cc
parentee1ad64234b61f9deaae64b28313492188c1de43 (diff)
get and convert boot time once and use as needed
Diffstat (limited to 'winsup/utils/ps.cc')
-rw-r--r--winsup/utils/ps.cc25
1 files changed, 16 insertions, 9 deletions
diff --git a/winsup/utils/ps.cc b/winsup/utils/ps.cc
index c81805ab6..75a91f5be 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;
}
}