unix: add ioctl wrappers to get and set RTC time on Linux

Add IoctlGetRTCTime and IoctlSetRTCTime to get and set the RTC time via
the RTC_RD_TIME and RTC_SET_TIME ioctls.

Change-Id: I63190026be39746599c2cd7116603d4a1d5bd695
Reviewed-on: https://go-review.googlesource.com/c/160397
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Tobias Klauser
2019-01-30 15:09:45 +00:00
committed by Tobias Klauser
parent 302c3dd5f1
commit aca44879d5
2 changed files with 28 additions and 0 deletions
+15
View File
@@ -32,6 +32,21 @@ func TestIoctlGetInt(t *testing.T) {
t.Logf("%d bits of entropy available", v)
}
func TestIoctlGetRTCTime(t *testing.T) {
f, err := os.Open("/dev/rtc0")
if err != nil {
t.Skipf("skipping test, %v", err)
}
defer f.Close()
v, err := unix.IoctlGetRTCTime(int(f.Fd()))
if err != nil {
t.Fatalf("failed to perform ioctl: %v", err)
}
t.Logf("RTC time: %04d-%02d-%02d %02d:%02d:%02d", v.Year+1900, v.Mon+1, v.Mday, v.Hour, v.Min, v.Sec)
}
func TestPpoll(t *testing.T) {
if runtime.GOOS == "android" {
t.Skip("mkfifo syscall is not available on android, skipping test")