-
Notifications
You must be signed in to change notification settings - Fork 1
/
control.go
57 lines (55 loc) · 1.01 KB
/
control.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
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bufio"
"fmt"
"net"
"os"
"strings"
)
func listenUnixControl(socketName string, fileChannel chan string) {
if socketName == "" {
socketName = "/tmp/proGY-control"
}
if _, err := os.Stat(socketName); err == nil {
if os.Remove(socketName) != nil {
fmt.Println(err)
os.Exit(2)
}
}
ln, err := net.ListenUnix("unix", &net.UnixAddr{socketName, "unix"})
if err != nil {
log("%s\n", err)
os.Exit(2)
}
for {
conn, _ := ln.Accept()
go func(conn net.Conn) {
b := bufio.NewReader(conn)
s, e := b.ReadString('\n')
if e != nil {
return
}
s = strings.TrimSpace(s)
splitted := strings.Split(s, " ")
if len(splitted) < 2 {
conn.Close()
return
}
if splitted[0] != "RELOAD" {
conn.Close()
return
}
filename := ""
for i, val := range splitted[1:] {
filename += val
if i != len(splitted[1:])-1 {
filename += " "
}
}
fileChannel <- filename
conn.Write([]byte("SUCCESS\n"))
conn.Close()
return
}(conn)
}
}