[tor-commits] [meek/master] Update server shutdown procedure.
dcf at torproject.org
dcf at torproject.org
Wed Mar 21 07:32:35 UTC 2018
commit 502001aed9e40f79807b913b02ea82f7c381e47d
Author: David Fifield <david at bamsoftware.com>
Date: Tue Mar 20 23:24:10 2018 -0700
Update server shutdown procedure.
Ignore SIGINT, honor TOR_PT_EXIT_ON_STDIN_CLOSE.
---
meek-server/meek-server.go | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/meek-server/meek-server.go b/meek-server/meek-server.go
index 79dd80c..fe4c263 100644
--- a/meek-server/meek-server.go
+++ b/meek-server/meek-server.go
@@ -24,6 +24,7 @@ import (
"flag"
"fmt"
"io"
+ "io/ioutil"
"log"
"net"
"net/http"
@@ -496,9 +497,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)
+
+ 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
+ }()
+ }
- // Wait for first signal.
+ // Keep track of handlers and wait for a signal.
sig = nil
for sig == nil {
select {
@@ -508,27 +519,15 @@ func main() {
log.Printf("got signal %s", sig)
}
}
+
/*
// Not supported until go1.8.
for _, server := range servers {
server.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 numHandlers > 0 {
+ numHandlers += <-handlerChan
}
log.Printf("done")
More information about the tor-commits
mailing list