aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Smith <osmith@sysmocom.de>2021-07-19 09:00:01 +0200
committerOliver Smith <osmith@sysmocom.de>2021-07-19 09:01:15 +0200
commit95a03e54efa9798199aa3342280d071183300b57 (patch)
tree474f4f6df820214624f3fe4badf2d465fec016b1
parent6fe865daae9dd1823eb98c819d4f99b4f0d5ac23 (diff)
vty: show uptime: use timespecsub
-rw-r--r--src/vty/command.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/vty/command.c b/src/vty/command.c
index 3112fee4..bb6a6651 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -3067,13 +3067,15 @@ DEFUN(show_uptime,
show_uptime_cmd, "show uptime", SHOW_STR "Displays how long the program has been running\n")
{
struct timespec now;
+ struct timespec uptime;
+
osmo_clock_gettime(CLOCK_MONOTONIC, &now);
+ timespecsub(&now, &starttime, &uptime);
- time_t uptime = now.tv_sec - starttime.tv_sec;
- int d = uptime / (3600 * 24);
- int h = uptime / 3600 % 24;
- int m = uptime / 60 % 60;
- int s = uptime % 60;
+ int d = uptime.tv_sec / (3600 * 24);
+ int h = uptime.tv_sec / 3600 % 24;
+ int m = uptime.tv_sec / 60 % 60;
+ int s = uptime.tv_sec % 60;
vty_out(vty, "%s has been running for %dd %dh %dm %ds%s", host.app_info->name, d, h, m, s, VTY_NEWLINE);