forked from 89luca89/transactional-update-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
44 lines (37 loc) · 1.01 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// main package
package main
import (
"log"
"net"
"os"
"path/filepath"
"strings"
"time"
)
// NotifyDaemonClient will search througt all files in /run/user, to find all
// running transactionalupdatenotification socket files, then send a message
// to each one of them in order to trigger the notification for all.
func NotifyDaemonClient(success string) {
transactionalUpdateSockets := []string{}
err := filepath.Walk("/run/user", func(path string, info os.FileInfo, err error) error {
if strings.Contains(path, "transactionalupdatenotification.socket") {
transactionalUpdateSockets = append(transactionalUpdateSockets, path)
}
return nil
})
if err != nil {
log.Fatal(err)
}
for _, socketFile := range transactionalUpdateSockets {
connection, err := net.Dial("unix", socketFile)
if err != nil {
log.Fatal(err)
}
defer connection.Close()
_, err = connection.Write([]byte(Message + ":" + success))
if err != nil {
log.Println("write error:", err)
}
time.Sleep(100 * time.Millisecond)
}
}