From 811ddd71c63ac5df6d212861e3bf0d084385b681 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 19 Dec 2017 10:18:26 -0800 Subject: [PATCH] User server clock in session.ls Avoids negative time deltas in the case of clock skew between ESX/VC and the client host. --- govc/session/ls.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/govc/session/ls.go b/govc/session/ls.go index ae077dece..d87aee8c7 100644 --- a/govc/session/ls.go +++ b/govc/session/ls.go @@ -27,6 +27,7 @@ import ( "github.com/vmware/govmomi/govc/cli" "github.com/vmware/govmomi/govc/flags" "github.com/vmware/govmomi/property" + "github.com/vmware/govmomi/vim25/methods" "github.com/vmware/govmomi/vim25/mo" ) @@ -67,6 +68,7 @@ func (cmd *ls) Process(ctx context.Context) error { type sessionInfo struct { cmd *ls + now *time.Time mo.SessionManager } @@ -85,7 +87,7 @@ func (s *sessionInfo) Write(w io.Writer) error { for _, v := range s.SessionList { idle := " ." if v.Key != s.CurrentSession.Key { - since := time.Since(v.LastActiveTime) + since := s.now.Sub(v.LastActiveTime) if since > time.Hour { idle = "old" } else { @@ -117,5 +119,10 @@ func (cmd *ls) Run(ctx context.Context, f *flag.FlagSet) error { return nil } - return cmd.WriteResult(&sessionInfo{cmd, m}) + now, err := methods.GetCurrentTime(ctx, c) + if err != nil { + return err + } + + return cmd.WriteResult(&sessionInfo{cmd, now, m}) }