Skip to content

Commit

Permalink
Avoid warning message when /dev/rtc does not exist
Browse files Browse the repository at this point in the history
For instance the Raspberry Pi does not have any real-time clock,
so rely on network time synchronization instead (systemd-timesyncd).

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Oct 25, 2024
1 parent dd8ded2 commit 6a9c144
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/guestagent/guestagent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func (a *agent) fixSystemTimeSkew() {
for {
ticker := time.NewTicker(10 * time.Second)
for now := range ticker.C {
if !timesync.DeviceExists() {
logrus.Infof("fixSystemTimeSkew: device does not exist")
break
}
rtc, err := timesync.GetRTCTime()
if err != nil {
logrus.Warnf("fixSystemTimeSkew: lookup error: %s", err.Error())
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 DeviceExists() bool {
_, err := os.Stat(rtc)
return !errors.Is(err, os.ErrNotExist)
}

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

0 comments on commit 6a9c144

Please sign in to comment.