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/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has submitted this change. ( 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. Related: OS#5028 Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793 --- M include/osmocom/vty/vty.h M src/vty/command.c M src/vty/vty.c 3 files changed, 25 insertions(+), 12 deletions(-) Approvals: pespin: Looks good to me, but someone else must approve daniel: Looks good to me, but someone else must approve osmith: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h index c13f435..ed9f439 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/command.c b/src/vty/command.c index bb6a665..e5e7d15 100644 --- a/src/vty/command.c +++ b/src/vty/command.c @@ -3066,18 +3066,9 @@ 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); - - 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); + vty_out(vty, "%s has been running for ", host.app_info->name); + vty_out_uptime(vty, &starttime); + vty_out_newline(vty); return CMD_SUCCESS; } diff --git a/src/vty/vty.c b/src/vty/vty.c index 1ad84f5..3a549b4 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 @@ -338,6 +339,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: 3 Gerrit-Owner: lynxis lazus <lynxis at fe80.eu> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann at sysmocom.de> Gerrit-Reviewer: laforge <laforge at osmocom.org> Gerrit-Reviewer: osmith <osmith at sysmocom.de> Gerrit-Reviewer: pespin <pespin at sysmocom.de> Gerrit-MessageType: merged -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210923/50674e58/attachment.htm>