[libvirt] [PATCH] Add output of local time when adding the option of "--pretty" for virsh domtime

ZhiPeng Lu posted 1 patch 6 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1508725748-15281-1-git-send-email-lu.zhipeng@zte.com.cn
tools/virsh-domain-monitor.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
[libvirt] [PATCH] Add output of local time when adding the option of "--pretty" for virsh domtime
Posted by ZhiPeng Lu 6 years, 5 months ago
Add more human-friendly output of domain's system time.

Signed-off-by: ZhiPeng Lu <lu.zhipeng@zte.com.cn>
Reviewed-by: Jiyun Fan <fan.jiyun@zte.com.cn>
---
 tools/virsh-domain-monitor.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 35d04b2..d9520ff 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1384,17 +1384,22 @@ cmdDomTime(vshControl *ctl, const vshCmd *cmd)
             goto cleanup;
 
         if (pretty) {
-            char timestr[100];
+            char timestr[100], localtimestr[100];
             time_t cur_time = seconds;
-            struct tm time_info;
+            struct tm time_info, local_time_info;
 
             if (!gmtime_r(&cur_time, &time_info)) {
                 vshError(ctl, _("Unable to format time"));
                 goto cleanup;
             }
+            if (!localtime_r(&cur_time, &local_time_info)) {
+                vshError(ctl, _("Unable to format local time"));
+                goto cleanup;
+            }
             strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", &time_info);
+            strftime(localtimestr, sizeof(localtimestr), "%Y-%m-%d %H:%M:%S", &local_time_info);
 
-            vshPrint(ctl, _("Time: %s"), timestr);
+            vshPrint(ctl, _("Time: %s\n Local time: %s"), timestr, localtimestr);
         } else {
             vshPrint(ctl, _("Time: %lld"), seconds);
         }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list