summaryrefslogtreecommitdiff
path: root/src/uptime.c
diff options
context:
space:
mode:
authored neville <ed@s5h.net>2023-03-29 18:19:36 +0100
committerCraig Small <csmall@dropbear.xyz>2023-05-02 09:08:37 +0000
commit4a315c923067dea8fb985e5791cd118a256ec209 (patch)
treea581ba68e0505d6c3af22b8251c33e9323324717 /src/uptime.c
parent29f06ff8e713754636c5163b46c04fba22ce8737 (diff)
downloadprocps-ng-4a315c923067dea8fb985e5791cd118a256ec209.tar.gz
Store sec and usec in terms of usec
Rather than attempt to convert usec to sec with division, add both together and then divide. This reduced the rounding errors on my system.
Diffstat (limited to 'src/uptime.c')
-rw-r--r--src/uptime.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/uptime.c b/src/uptime.c
index 6d6e739..91e89c7 100644
--- a/src/uptime.c
+++ b/src/uptime.c
@@ -44,12 +44,12 @@ static void print_uptime_since()
/* Get the current time and convert it to a double */
if (gettimeofday(&tim, NULL) != 0)
xerr(EXIT_FAILURE, "gettimeofday");
- now = tim.tv_sec + (tim.tv_usec / 1000000.0);
+ now = (tim.tv_sec * 1000000.0) + tim.tv_usec;
/* Get the uptime and calculate when that was */
if (procps_uptime(&uptime_secs, &idle_secs) < 0)
xerr(EXIT_FAILURE, _("Cannot get system uptime"));
- up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
+ up_since_secs = (time_t) ((now/1000000.0) - uptime_secs);
/* Show this */
if ((up_since = localtime(&up_since_secs)) == NULL)