Skip to content

Commit 1a07d5f

Browse files
authored
Merge pull request #2801 from afbjorklund/rtc-warning
Avoid spamming the log when /dev/rtc does not exist
2 parents f93c601 + 92ce4be commit 1a07d5f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pkg/guestagent/guestagent_linux.go

+5
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ const deltaLimit = 2 * time.Second
324324

325325
func (a *agent) fixSystemTimeSkew() {
326326
for {
327+
ok, err := timesync.HasRTC()
328+
if !ok {
329+
logrus.Warnf("fixSystemTimeSkew: error: %s", err.Error())
330+
break
331+
}
327332
ticker := time.NewTicker(10 * time.Second)
328333
for now := range ticker.C {
329334
rtc, err := timesync.GetRTCTime()

pkg/guestagent/timesync/timesync_linux.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package timesync
22

33
import (
4+
"errors"
45
"os"
56
"time"
67

@@ -9,6 +10,11 @@ import (
910

1011
const rtc = "/dev/rtc"
1112

13+
func HasRTC() (bool, error) {
14+
_, err := os.Stat(rtc)
15+
return !errors.Is(err, os.ErrNotExist), err
16+
}
17+
1218
func GetRTCTime() (t time.Time, err error) {
1319
f, err := os.Open(rtc)
1420
if err != nil {

0 commit comments

Comments
 (0)