commit 1b3a72f3c7208dd7c0471bb3e9077667091874c8
Author: David Fifield <[email protected]>
Date:   Thu Apr 18 23:15:49 2019 -0600

    Be more careful about terminating Firefox.
    
    First send it a SIGTERM; then kill it if that doesn't work. On Windows,
    just kill it immediately without waiting.
---
 meek-client-torbrowser/meek-client-torbrowser.go | 14 ++++++++++++-
 meek-client-torbrowser/terminate_other.go        | 25 ++++++++++++++++--------
 meek-client-torbrowser/terminate_windows.go      |  6 ++++++
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/meek-client-torbrowser/meek-client-torbrowser.go 
b/meek-client-torbrowser/meek-client-torbrowser.go
index 0f295ff..1274327 100644
--- a/meek-client-torbrowser/meek-client-torbrowser.go
+++ b/meek-client-torbrowser/meek-client-torbrowser.go
@@ -434,7 +434,19 @@ func main() {
        }
 
        if firefoxCmd != nil {
-               logKill(firefoxCmd.Process)
+               err := terminateCmd(firefoxCmd)
+               // We terminate Firefox with SIGTERM, so don't log an error
+               // if the exit status is "terminated by SIGTERM."
+               if err2, ok := err.(*exec.ExitError); ok {
+                       if status, ok := err2.Sys().(syscall.WaitStatus); ok {
+                               if status.Signaled() && status.Signal() == 
syscall.SIGTERM {
+                                       err = nil
+                               }
+                       }
+               }
+               if err != nil {
+                       log.Printf("error terminating firefox: %v", err)
+               }
        }
        if meekClientCmd != nil {
                err := terminatePTCmd(meekClientCmd)
diff --git a/meek-client-torbrowser/terminate_other.go 
b/meek-client-torbrowser/terminate_other.go
index d38e27b..19bf2b8 100644
--- a/meek-client-torbrowser/terminate_other.go
+++ b/meek-client-torbrowser/terminate_other.go
@@ -5,22 +5,20 @@
 package main
 
 import (
+       "os/exec"
        "syscall"
        "time"
 )
 
-// Terminate a PT subprocess: first close its stdin and send it SIGTERM; then
-// kill it if that doesn't work.
-func terminatePTCmd(cmd *ptCmd) error {
-       err := cmd.StdinCloser.Close()
-       err2 := cmd.Process.Signal(syscall.SIGTERM)
-       if err == nil {
-               err = err2
-       }
+// Terminate a subprocess: first send it SIGTERM; then kill it if that doesn't
+// work.
+func terminateCmd(cmd *exec.Cmd) error {
+       err := cmd.Process.Signal(syscall.SIGTERM)
        ch := make(chan error, 1)
        go func() {
                ch <- cmd.Wait()
        }()
+       var err2 error
        select {
        case <-time.After(terminateTimeout):
                err2 = cmd.Process.Kill()
@@ -31,3 +29,14 @@ func terminatePTCmd(cmd *ptCmd) error {
        }
        return err
 }
+
+// Terminate a PT subprocess: first close its stdin and send it SIGTERM; then
+// kill it if that doesn't work.
+func terminatePTCmd(cmd *ptCmd) error {
+       err := cmd.StdinCloser.Close()
+       err2 := terminateCmd(cmd.Cmd)
+       if err == nil {
+               err = err2
+       }
+       return err
+}
diff --git a/meek-client-torbrowser/terminate_windows.go 
b/meek-client-torbrowser/terminate_windows.go
index c00c44f..0bbdcab 100644
--- a/meek-client-torbrowser/terminate_windows.go
+++ b/meek-client-torbrowser/terminate_windows.go
@@ -6,9 +6,15 @@
 package main
 
 import (
+       "os/exec"
        "time"
 )
 
+// Terminate a subprocess: on Windows all we can do is kill it.
+func terminateCmd(cmd *exec.Cmd) error {
+       return cmd.Process.Kill()
+}
+
 // Terminate a PT subprocess: first close its stdin; then kill it if that
 // doesn't work.
 func terminatePTCmd(cmd *ptCmd) error {



_______________________________________________
tor-commits mailing list
[email protected]
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits

Reply via email to