summaryrefslogtreecommitdiff
path: root/systemd-timesyncd-wait.go
diff options
context:
space:
mode:
Diffstat (limited to 'systemd-timesyncd-wait.go')
-rw-r--r--systemd-timesyncd-wait.go29
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)
+}