Change in libosmocore[master]: vty: add vty_out_uptime() print the uptime to the vty

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/.

lynxis lazus gerrit-no-reply at lists.osmocom.org
Sun Sep 5 21:24:31 UTC 2021


lynxis lazus has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/25348 )


Change subject: vty: add vty_out_uptime() print the uptime to the vty
......................................................................

vty: add vty_out_uptime() print the uptime to the vty

vty_out_uptime() calculates the time difference to a given timespec
and print it in a human readable format (days, hours,
minutes, seconds) to the vty.

Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793
---
M include/osmocom/vty/vty.h
M src/vty/vty.c
2 files changed, 22 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/48/25348/1

diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h
index 3e6178f..a39780b 100644
--- a/include/osmocom/vty/vty.h
+++ b/include/osmocom/vty/vty.h
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdbool.h>
+#include <time.h>
 
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/defs.h>
@@ -219,6 +220,7 @@
 int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);
 int vty_out_va(struct vty *vty, const char *format, va_list ap);
 int vty_out_newline(struct vty *);
+int vty_out_uptime(struct vty *vty, const struct timespec *starttime);
 int vty_read(struct vty *vty);
 //void vty_time_print (struct vty *, int);
 void vty_close (struct vty *);
diff --git a/src/vty/vty.c b/src/vty/vty.c
index a39f268..4cb0847 100644
--- a/src/vty/vty.c
+++ b/src/vty/vty.c
@@ -66,6 +66,7 @@
 #include <osmocom/vty/command.h>
 #include <osmocom/vty/buffer.h>
 #include <osmocom/core/talloc.h>
+#include <osmocom/core/timer.h>
 #include <osmocom/core/utils.h>
 
 #ifndef MAXPATHLEN
@@ -332,6 +333,25 @@
 	return 0;
 }
 
+/*! calculates the time difference of a give timespec to the current time
+ *  and prints in a human readable format (days, hours, minutes, seconds).
+ */
+int vty_out_uptime(struct vty *vty, const struct timespec *starttime)
+{
+	struct timespec now;
+	struct timespec uptime;
+
+	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;
+
+	return vty_out(vty, "%dd %dh %dm %ds", d, h, m, s);
+}
+
 /*! return the current index of a given VTY */
 void *vty_current_index(struct vty *vty)
 {

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793
Gerrit-Change-Number: 25348
Gerrit-PatchSet: 1
Gerrit-Owner: lynxis lazus <lynxis at fe80.eu>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210905/aee8cb02/attachment.htm>


More information about the gerrit-log mailing list