commit 0ec986eb2b4bc23d81e6e8beffd382890f55bfb1
Author: David Fifield <[email protected]>
Date:   Thu Jun 29 16:43:01 2017 -0700

    Update client shutdown procedure.
    
    Ignore SIGINT, handle TOR_PT_EXIT_ON_STDIN_CLOSE.
---
 meek-client-torbrowser/meek-client-torbrowser.go |  2 +-
 meek-client/meek-client.go                       | 34 +++++++++++++-----------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/meek-client-torbrowser/meek-client-torbrowser.go 
b/meek-client-torbrowser/meek-client-torbrowser.go
index cbbf9ca..691a566 100644
--- a/meek-client-torbrowser/meek-client-torbrowser.go
+++ b/meek-client-torbrowser/meek-client-torbrowser.go
@@ -308,7 +308,7 @@ func main() {
        signal.Notify(make(chan os.Signal, 1), syscall.SIGPIPE)
 
        sigChan := make(chan os.Signal, 1)
-       signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+       signal.Notify(sigChan, syscall.SIGTERM)
 
        // Unset environment variables that Firefox sets after a restart (as
        // caused by, for example, an update or the installation of an add-on).
diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go
index c3eadc4..9a818d0 100644
--- a/meek-client/meek-client.go
+++ b/meek-client/meek-client.go
@@ -36,6 +36,7 @@ import (
        "flag"
        "fmt"
        "io"
+       "io/ioutil"
        "log"
        "net"
        "net/http"
@@ -441,9 +442,19 @@ func main() {
        var numHandlers int = 0
        var sig os.Signal
        sigChan := make(chan os.Signal, 1)
-       signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
+       signal.Notify(sigChan, syscall.SIGTERM)
 
-       // Wait for first signal.
+       if os.Getenv("TOR_PT_EXIT_ON_STDIN_CLOSE") == "1" {
+               // This environment variable means we should treat EOF on stdin
+               // just like SIGTERM: https://bugs.torproject.org/15435.
+               go func() {
+                       io.Copy(ioutil.Discard, os.Stdin)
+                       log.Printf("synthesizing SIGTERM because of stdin 
close")
+                       sigChan <- syscall.SIGTERM
+               }()
+       }
+
+       // Keep track of handlers and wait for a signal.
        sig = nil
        for sig == nil {
                select {
@@ -453,23 +464,14 @@ func main() {
                        log.Printf("got signal %s", sig)
                }
        }
+
        for _, ln := range listeners {
                ln.Close()
        }
-
-       if sig == syscall.SIGTERM {
-               log.Printf("done")
-               return
-       }
-
-       // Wait for second signal or no more handlers.
-       sig = nil
-       for sig == nil && numHandlers != 0 {
-               select {
-               case n := <-handlerChan:
-                       numHandlers += n
-               case sig = <-sigChan:
-                       log.Printf("got second signal %s", sig)
+       for n := range handlerChan {
+               numHandlers += n
+               if numHandlers == 0 {
+                       break
                }
        }
 

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

Reply via email to