Change in libosmocore[master]: vty: show uptime: use timespecsub

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

osmith gerrit-no-reply at lists.osmocom.org
Mon Jul 19 07:01:36 UTC 2021


osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/24958 )


Change subject: vty: show uptime: use timespecsub
......................................................................

vty: show uptime: use timespecsub

Related: OS#4609
Change-Id: If94795b3cd74040c49bdcbed8c410bf6e950afff
---
M src/vty/command.c
1 file changed, 8 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/58/24958/1

diff --git a/src/vty/command.c b/src/vty/command.c
index 3112fee..bb6a665 100644
--- a/src/vty/command.c
+++ b/src/vty/command.c
@@ -3067,13 +3067,15 @@
       show_uptime_cmd, "show uptime", SHOW_STR "Displays how long the program has been running\n")
 {
 	struct timespec now;
-	osmo_clock_gettime(CLOCK_MONOTONIC, &now);
+	struct timespec 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;
+	osmo_clock_gettime(CLOCK_MONOTONIC, &now);
+	timespecsub(&now, &starttime, &uptime);
+
+	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);
 

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/24958
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: If94795b3cd74040c49bdcbed8c410bf6e950afff
Gerrit-Change-Number: 24958
Gerrit-PatchSet: 1
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210719/20b119ae/attachment.htm>


More information about the gerrit-log mailing list