diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-18 22:24:27 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-18 22:24:27 -0500 |
commit | 58861a7cbcd8f745ec0cc99e7dced13da07eff68 (patch) | |
tree | b83769fe0fe6b72d13a6de2c7b833d6946fe63ca /systemd-timesyncd-wait.go |
initial commit
Diffstat (limited to 'systemd-timesyncd-wait.go')
-rw-r--r-- | systemd-timesyncd-wait.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/systemd-timesyncd-wait.go b/systemd-timesyncd-wait.go new file mode 100644 index 0000000..9275502 --- /dev/null +++ b/systemd-timesyncd-wait.go @@ -0,0 +1,29 @@ +package main + +import ( + "net" + "os" +) + +func main() { + sync_sockname := "/run/timesyncd/time-sync.sock" + + sync_sock, err := net.ListenUnixgram("unixgram", &net.UnixAddr{Net: "unixgram", Name: sync_sockname}) + if err != nil { + os.Stderr.WriteString(err.Error()) + os.Stderr.Write([]byte{'\n'}) + os.Exit(127) + } + + var dat [4096]byte + n, err := sync_sock.Read(dat[:]) + if err != nil { + os.Stderr.WriteString(err.Error()) + os.Stderr.Write([]byte{'\n'}) + os.Exit(127) + } + if string(dat[:n]) != "READY=1" { + os.Exit(127) + } + os.Exit(0) +} |