aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-08-19 12:03:57 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-08-19 12:13:45 +0200
commit741b22805b67ea3f7a147034d39769bb231c1d19 (patch)
treece6906a61e76e2f67e8344779a4972ccd95a4fb1
parentui: increase default width (diff)
downloadwireguard-windows-741b22805b67ea3f7a147034d39769bb231c1d19.tar.xz
wireguard-windows-741b22805b67ea3f7a147034d39769bb231c1d19.zip
manager: wait for UIs to quit before quitting
-rw-r--r--manager/service.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/manager/service.go b/manager/service.go
index 3649563d..30567811 100644
--- a/manager/service.go
+++ b/manager/service.go
@@ -87,10 +87,9 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
procs := make(map[uint32]*os.Process)
aliveSessions := make(map[uint32]bool)
procsLock := sync.Mutex{}
- var startProcess func(session uint32)
stoppingManager := false
- startProcess = func(session uint32) {
+ startProcess := func(session uint32) {
defer func() {
runtime.UnlockOSThread()
procsLock.Lock()
@@ -236,6 +235,14 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
}
}
}
+ procsGroup := sync.WaitGroup{}
+ goStartProcess := func(session uint32) {
+ procsGroup.Add(1)
+ go func() {
+ startProcess(session)
+ procsGroup.Done()
+ }()
+ }
go checkForUpdates()
@@ -259,7 +266,7 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
if alive := aliveSessions[session.SessionID]; !alive {
aliveSessions[session.SessionID] = true
if _, ok := procs[session.SessionID]; !ok {
- go startProcess(session.SessionID)
+ goStartProcess(session.SessionID)
}
}
procsLock.Unlock()
@@ -302,7 +309,7 @@ loop:
if alive := aliveSessions[sessionNotification.SessionID]; !alive {
aliveSessions[sessionNotification.SessionID] = true
if _, ok := procs[sessionNotification.SessionID]; !ok {
- go startProcess(sessionNotification.SessionID)
+ goStartProcess(sessionNotification.SessionID)
}
}
procsLock.Unlock()
@@ -322,6 +329,7 @@ loop:
proc.Kill()
}
procsLock.Unlock()
+ procsGroup.Wait()
if uninstall {
err = UninstallManager()
if err != nil {