commit 125b0ca14312085def735bc8c239097972a166c5
Author: David Fifield <[email protected]>
Date:   Sun Sep 25 22:23:57 2016 -0700

    Ignore SIGPIPE in meek-client-torbrowser.
    
    See https://bugs.torproject.org/20030 for discussion. Since Go 1.6,
    writes to fd 1 or 2 when they are closed causes the program to terminate
    with a SIGPIPE. Because the default log location is stderr (fd 2), we
    would get a SIGPIPE when logging once the parent process had died and
    closed its stderr. This prevented meek-client-torbrowser from cleaning
    up its subprocesses.
---
 meek-client-torbrowser/meek-client-torbrowser.go | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/meek-client-torbrowser/meek-client-torbrowser.go 
b/meek-client-torbrowser/meek-client-torbrowser.go
index 450f9fa..4f3531d 100644
--- a/meek-client-torbrowser/meek-client-torbrowser.go
+++ b/meek-client-torbrowser/meek-client-torbrowser.go
@@ -289,6 +289,17 @@ func main() {
                log.SetOutput(f)
        }
 
+       // By default, writes to file descriptor 1 and 2 when the descriptor has
+       // been closed will terminate the program with a SIGPIPE signal. This is
+       // a problem because the default log destination is stderr (file
+       // descriptor 2). When the parent process (tor) terminates and closes
+       // its stderr, any attempt to log will cause us to die, before we can do
+       // our own cleanup. Therefore ignore SIGPIPE, causing writes to a closed
+       // stderr to return syscall.EPIPE rather than terminate.
+       // https://golang.org/pkg/os/signal/#hdr-SIGPIPE
+       // https://bugs.torproject.org/20030#comment:6
+       signal.Notify(make(chan os.Signal, 1), syscall.SIGPIPE)
+
        sigChan := make(chan os.Signal, 1)
        signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
 

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

Reply via email to