Ticket #20030: 0001-Ignore-SIGPIPE-in-meek-client-torbrowser.patch

File 0001-Ignore-SIGPIPE-in-meek-client-torbrowser.patch, 1.7 KB (added by dcf, 3 years ago)
  • meek-client-torbrowser/meek-client-torbrowser.go

    From 0ac9bc648254d79dd203b0ce3b55cf72a937107e Mon Sep 17 00:00:00 2001
    From: David Fifield <david@bamsoftware.com>
    Date: Sun, 25 Sep 2016 22:23:57 -0700
    Subject: [PATCH] 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 b func main() { 
    289289                log.SetOutput(f)
    290290        }
    291291
     292        // By default, writes to file descriptor 1 and 2 when the descriptor has
     293        // been closed will terminate the program with a SIGPIPE signal. This is
     294        // a problem because the default log destination is stderr (file
     295        // descriptor 2). When the parent process (tor) terminates and closes
     296        // its stderr, any attempt to log will cause us to die, before we can do
     297        // our own cleanup. Therefore ignore SIGPIPE, causing writes to a closed
     298        // stderr to return syscall.EPIPE rather than terminate.
     299        // https://golang.org/pkg/os/signal/#hdr-SIGPIPE
     300        // https://bugs.torproject.org/20030#comment:6
     301        signal.Notify(make(chan os.Signal, 1), syscall.SIGPIPE)
     302
    292303        sigChan := make(chan os.Signal, 1)
    293304        signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
    294305