aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-01 12:14:38 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-01 12:15:20 +0200
commitb03a6ab1b1ef422d832a5451312ecae1363fa171 (patch)
treef40c86a1d23a8efc823df28035445888b0e05a49 /src
parentVerify source address (diff)
downloadwireguard-go-b03a6ab1b1ef422d832a5451312ecae1363fa171.tar.xz
wireguard-go-b03a6ab1b1ef422d832a5451312ecae1363fa171.zip
Close UAPI socket before exit
Diffstat (limited to 'src')
-rw-r--r--src/device.go4
-rw-r--r--src/logger.go4
-rw-r--r--src/main.go28
3 files changed, 29 insertions, 7 deletions
diff --git a/src/device.go b/src/device.go
index d32d648..1185d60 100644
--- a/src/device.go
+++ b/src/device.go
@@ -186,6 +186,6 @@ func (device *Device) Close() {
close(device.signal.stop)
}
-func (device *Device) Wait() {
- <-device.signal.stop
+func (device *Device) WaitChannel() chan struct{} {
+ return device.signal.stop
}
diff --git a/src/logger.go b/src/logger.go
index 827f9e9..9fe73b4 100644
--- a/src/logger.go
+++ b/src/logger.go
@@ -40,11 +40,11 @@ func NewLogger(level int) *Logger {
logger.Info = log.New(logInfo,
"INFO: ",
- log.Ldate|log.Ltime|log.Lshortfile,
+ log.Ldate|log.Ltime,
)
logger.Error = log.New(logErr,
"ERROR: ",
- log.Ldate|log.Ltime|log.Lshortfile,
+ log.Ldate|log.Ltime,
)
return logger
}
diff --git a/src/main.go b/src/main.go
index 0857999..dde21fb 100644
--- a/src/main.go
+++ b/src/main.go
@@ -4,6 +4,7 @@ import (
"fmt"
"log"
"os"
+ "os/signal"
"runtime"
)
@@ -78,17 +79,38 @@ func main() {
if err != nil {
logError.Fatal("UAPI listen error:", err)
}
- defer uapi.Close()
+
+ errs := make(chan error)
+ term := make(chan os.Signal)
+ wait := device.WaitChannel()
go func() {
for {
conn, err := uapi.Accept()
if err != nil {
- logError.Fatal("UAPI accept error:", err)
+ errs <- err
+ return
}
go ipcHandle(device, conn)
}
}()
- device.Wait()
+ logInfo.Println("UAPI listener started")
+
+ // wait for program to terminate
+
+ signal.Notify(term, os.Kill)
+ signal.Notify(term, os.Interrupt)
+
+ select {
+ case <-wait:
+ case <-term:
+ case <-errs:
+ }
+
+ // clean up UAPI bind
+
+ uapi.Close()
+
+ logInfo.Println("Closing")
}