aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/service/service_manager.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-05-08 17:36:28 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-08 17:36:28 +0200
commit41739492e04e99434af1050ef366c3e8d4e9f852 (patch)
treec92f34ad6148c7d1ef01f3136ac0bd11ddac2ac4 /service/service_manager.go
parentservice: print in log after UI exits (diff)
downloadwireguard-windows-41739492e04e99434af1050ef366c3e8d4e9f852.tar.xz
wireguard-windows-41739492e04e99434af1050ef366c3e8d4e9f852.zip
service: prevent against multiple routines per session
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'service/service_manager.go')
-rw-r--r--service/service_manager.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/service/service_manager.go b/service/service_manager.go
index cbe2fee0..68a864ed 100644
--- a/service/service_manager.go
+++ b/service/service_manager.go
@@ -130,6 +130,14 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
return
}
+ procsLock.Lock()
+ if _, ok := procs[session]; ok {
+ log.Printf("Session %d already has a UI process, giving up", session)
+ procsLock.Unlock()
+ return
+ }
+ procsLock.Unlock()
+
//TODO: we lock the OS thread so that these inheritable handles don't escape into other processes that
// might be running in parallel Go routines. But the Go runtime is strange and who knows what's really
// happening with these or what is inherited. We need to do some analysis to be certain of what's going on.
@@ -151,7 +159,7 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
return
}
- log.Printf("Starting UI process for user '%s@%s'", username, domain)
+ log.Printf("Starting UI process for user '%s@%s' for session %d", username, domain, session)
attr := &os.ProcAttr{
Sys: &syscall.SysProcAttr{
Token: syscall.Token(userToken),
@@ -168,19 +176,25 @@ func (service *managerService) Execute(args []string, r <-chan svc.ChangeRequest
windows.Close(theirLogMappingHandle)
runtime.UnlockOSThread()
if err != nil {
- log.Printf("Unable to start manager UI process for user '%s@%s': %v", username, domain, err)
+ log.Printf("Unable to start manager UI process for user '%s@%s' for session %d: %v", username, domain, session, err)
return
}
procsLock.Lock()
+ if _, ok := procs[session]; ok {
+ log.Printf("Session %d already has a UI process, killing newly created one", session)
+ proc.Kill()
+ procsLock.Unlock()
+ continue
+ }
procs[session] = proc
procsLock.Unlock()
processStatus, err := proc.Wait()
if err == nil {
- log.Printf("Exited UI process for user '%s@%s' with status %d", username, domain, processStatus.ExitCode())
+ log.Printf("Exited UI process for user '%s@%s' for session %d with status %d", username, domain, session, processStatus.ExitCode())
} else {
- log.Printf("Unable to wait for UI process for user '%s@%s': %v", username, domain, err)
+ log.Printf("Unable to wait for UI process for user '%s@%s' for session %d: %v", username, domain, session, err)
}
procsLock.Lock()