Skip to content

Commit

Permalink
Merge pull request #2801 from afbjorklund/rtc-warning
Browse files Browse the repository at this point in the history
Avoid spamming the log when /dev/rtc does not exist
  • Loading branch information
AkihiroSuda authored Oct 30, 2024
2 parents f93c601 + 92ce4be commit 1a07d5f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/guestagent/guestagent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ const deltaLimit = 2 * time.Second

func (a *agent) fixSystemTimeSkew() {
for {
ok, err := timesync.HasRTC()
if !ok {
logrus.Warnf("fixSystemTimeSkew: error: %s", err.Error())
break
}
ticker := time.NewTicker(10 * time.Second)
for now := range ticker.C {
rtc, err := timesync.GetRTCTime()
Expand Down
6 changes: 6 additions & 0 deletions pkg/guestagent/timesync/timesync_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package timesync

import (
"errors"
"os"
"time"

Expand All @@ -9,6 +10,11 @@ import (

const rtc = "/dev/rtc"

func HasRTC() (bool, error) {
_, err := os.Stat(rtc)
return !errors.Is(err, os.ErrNotExist), err
}

func GetRTCTime() (t time.Time, err error) {
f, err := os.Open(rtc)
if err != nil {
Expand Down

0 comments on commit 1a07d5f

Please sign in to comment.