Skip to content

Commit

Permalink
User server clock in session.ls (#973)
Browse files Browse the repository at this point in the history
Avoids negative time deltas in the case of clock skew between ESX/VC and the client host.
  • Loading branch information
dougm authored Dec 20, 2017
1 parent 2892ed5 commit 1d8b92d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions govc/session/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -67,6 +68,7 @@ func (cmd *ls) Process(ctx context.Context) error {

type sessionInfo struct {
cmd *ls
now *time.Time
mo.SessionManager
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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})
}

0 comments on commit 1d8b92d

Please sign in to comment.