[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sandboxed-tor-browser/master] Try harder to ensure that the tor process dies properly.



commit 8aebab2c046c398efd601ca986edbfe26d0825f4
Author: Yawning Angel <yawning@xxxxxxxxxxxxxxx>
Date:   Wed Nov 30 17:55:20 2016 +0000

    Try harder to ensure that the tor process dies properly.
---
 src/cmd/sandboxed-tor-browser/internal/tor/tor.go | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/cmd/sandboxed-tor-browser/internal/tor/tor.go b/src/cmd/sandboxed-tor-browser/internal/tor/tor.go
index 58b34d0..ecb53e3 100644
--- a/src/cmd/sandboxed-tor-browser/internal/tor/tor.go
+++ b/src/cmd/sandboxed-tor-browser/internal/tor/tor.go
@@ -161,8 +161,22 @@ func (t *Tor) Shutdown() {
 	}
 
 	if t.cmd != nil {
-		t.cmd.Process.Signal(syscall.SIGKILL)
-		t.ctrl = nil
+		waitCh := make(chan bool)
+		go func() {
+			t.cmd.Process.Signal(syscall.SIGTERM)
+			t.cmd.Process.Wait()
+			waitCh <- true
+		}()
+
+		select {
+		case <-waitCh:
+			Debugf("tor: Process exited after SIGTERM")
+		case <-time.After(5 * time.Second):
+			Debugf("tor: Process timed out waiting after SIGTERM, killing.")
+			t.cmd.Process.Signal(syscall.SIGKILL)
+		}
+
+		t.cmd = nil
 	}
 
 	if t.ctrlSurrogate != nil {

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits