<p>lynxis lazus has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/libosmocore/+/25348">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">vty: add vty_out_uptime() print the uptime to the vty<br><br>vty_out_uptime() calculates the time difference to a given timespec<br>and print it in a human readable format (days, hours,<br>minutes, seconds) to the vty.<br><br>Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793<br>---<br>M include/osmocom/vty/vty.h<br>M src/vty/vty.c<br>2 files changed, 22 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/48/25348/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/osmocom/vty/vty.h b/include/osmocom/vty/vty.h</span><br><span>index 3e6178f..a39780b 100644</span><br><span>--- a/include/osmocom/vty/vty.h</span><br><span>+++ b/include/osmocom/vty/vty.h</span><br><span>@@ -3,6 +3,7 @@</span><br><span> #include <stdio.h></span><br><span> #include <stdarg.h></span><br><span> #include <stdbool.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <time.h></span><br><span> </span><br><span> #include <osmocom/core/linuxlist.h></span><br><span> #include <osmocom/core/defs.h></span><br><span>@@ -219,6 +220,7 @@</span><br><span> int vty_out (struct vty *, const char *, ...) VTY_PRINTF_ATTRIBUTE(2, 3);</span><br><span> int vty_out_va(struct vty *vty, const char *format, va_list ap);</span><br><span> int vty_out_newline(struct vty *);</span><br><span style="color: hsl(120, 100%, 40%);">+int vty_out_uptime(struct vty *vty, const struct timespec *starttime);</span><br><span> int vty_read(struct vty *vty);</span><br><span> //void vty_time_print (struct vty *, int);</span><br><span> void vty_close (struct vty *);</span><br><span>diff --git a/src/vty/vty.c b/src/vty/vty.c</span><br><span>index a39f268..4cb0847 100644</span><br><span>--- a/src/vty/vty.c</span><br><span>+++ b/src/vty/vty.c</span><br><span>@@ -66,6 +66,7 @@</span><br><span> #include <osmocom/vty/command.h></span><br><span> #include <osmocom/vty/buffer.h></span><br><span> #include <osmocom/core/talloc.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <osmocom/core/timer.h></span><br><span> #include <osmocom/core/utils.h></span><br><span> </span><br><span> #ifndef MAXPATHLEN</span><br><span>@@ -332,6 +333,25 @@</span><br><span>         return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*! calculates the time difference of a give timespec to the current time</span><br><span style="color: hsl(120, 100%, 40%);">+ *  and prints in a human readable format (days, hours, minutes, seconds).</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int vty_out_uptime(struct vty *vty, const struct timespec *starttime)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct timespec now;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct timespec uptime;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     osmo_clock_gettime(CLOCK_MONOTONIC, &now);</span><br><span style="color: hsl(120, 100%, 40%);">+        timespecsub(&now, starttime, &uptime);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+      int d = uptime.tv_sec / (3600 * 24);</span><br><span style="color: hsl(120, 100%, 40%);">+  int h = uptime.tv_sec / 3600 % 24;</span><br><span style="color: hsl(120, 100%, 40%);">+    int m = uptime.tv_sec / 60 % 60;</span><br><span style="color: hsl(120, 100%, 40%);">+      int s = uptime.tv_sec % 60;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return vty_out(vty, "%dd %dh %dm %ds", d, h, m, s);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! return the current index of a given VTY */</span><br><span> void *vty_current_index(struct vty *vty)</span><br><span> {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/libosmocore/+/25348">change 25348</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/libosmocore/+/25348"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: libosmocore </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I264a3f49096b96646e0a1f5366623ac20d860793 </div>
<div style="display:none"> Gerrit-Change-Number: 25348 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: lynxis lazus <lynxis@fe80.eu> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>