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 92ce4be
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 92ce4be

Please sign in to comment.