[tor-commits] [goptlib/master] Add TOR_PT_EXIT_ON_STDIN_CLOSE to dummy example programs.
dcf at torproject.org
dcf at torproject.org
Wed Mar 21 06:17:58 UTC 2018
commit c03acac8316d24ac99cf9bfcb72da1dc9a6ff3c3
Author: David Fifield <david at bamsoftware.com>
Date: Tue Mar 20 23:00:40 2018 -0700
Add TOR_PT_EXIT_ON_STDIN_CLOSE to dummy example programs.
---
examples/dummy-client/dummy-client.go | 10 ++++++++++
examples/dummy-server/dummy-server.go | 10 ++++++++++
2 files changed, 20 insertions(+)
diff --git a/examples/dummy-client/dummy-client.go b/examples/dummy-client/dummy-client.go
index a15189c..de7f367 100644
--- a/examples/dummy-client/dummy-client.go
+++ b/examples/dummy-client/dummy-client.go
@@ -12,6 +12,7 @@ package main
import (
"io"
+ "io/ioutil"
"net"
"os"
"os/signal"
@@ -116,6 +117,15 @@ func main() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM)
+ 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)
+ sigChan <- syscall.SIGTERM
+ }()
+ }
+
// keep track of handlers and wait for a signal
sig = nil
for sig == nil {
diff --git a/examples/dummy-server/dummy-server.go b/examples/dummy-server/dummy-server.go
index c31c63f..aea4df4 100644
--- a/examples/dummy-server/dummy-server.go
+++ b/examples/dummy-server/dummy-server.go
@@ -13,6 +13,7 @@ package main
import (
"io"
+ "io/ioutil"
"net"
"os"
"os/signal"
@@ -108,6 +109,15 @@ func main() {
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM)
+ 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)
+ sigChan <- syscall.SIGTERM
+ }()
+ }
+
// keep track of handlers and wait for a signal
sig = nil
for sig == nil {
More information about the tor-commits
mailing list