commit 017d0f33d7270ff102fe167f1c16def8b3e3be4a Author: David Fifield david@bamsoftware.com Date: Fri Mar 31 00:46:46 2017 -0700
Emit a CMETHOD-ERROR or SMETHOD-ERROR when failing to open log file.
This causes a message to appear in tor's log. Otherwise, with no log file to write to, there's no indication of what the error was that caused the transport plugin to fail.
https://bugs.torproject.org/20451 --- meek-client/meek-client.go | 13 ++++++++----- meek-server/meek-server.go | 15 +++++++++------ 2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/meek-client/meek-client.go b/meek-client/meek-client.go index 9706c66..8cbc84a 100644 --- a/meek-client/meek-client.go +++ b/meek-client/meek-client.go @@ -363,10 +363,18 @@ func main() { flag.StringVar(&options.URL, "url", "", "URL to request if no url= SOCKS arg") flag.Parse()
+ ptInfo, err = pt.ClientSetup(nil) + if err != nil { + log.Fatalf("error in ClientSetup: %s", err) + } + log.SetFlags(log.LstdFlags | log.LUTC) if logFilename != "" { f, err := os.OpenFile(logFilename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { + // If we fail to open the log, emit a message that will + // appear in tor's log. + pt.CmethodError(ptMethodName, fmt.Sprintf("error opening log file: %s", err)) log.Fatalf("error opening log file: %s", err) } defer f.Close() @@ -395,11 +403,6 @@ func main() { httpTransport = *http.DefaultTransport.(*http.Transport) httpTransport.Proxy = nil
- ptInfo, err = pt.ClientSetup(nil) - if err != nil { - log.Fatalf("error in ClientSetup: %s", err) - } - // Command-line proxy overrides managed configuration. if options.ProxyURL == nil { options.ProxyURL = ptInfo.ProxyURL diff --git a/meek-server/meek-server.go b/meek-server/meek-server.go index ee53d83..d0be266 100644 --- a/meek-server/meek-server.go +++ b/meek-server/meek-server.go @@ -359,22 +359,25 @@ func main() { flag.IntVar(&port, "port", 0, "port to listen on") flag.Parse()
+ var err error + ptInfo, err = pt.ServerSetup(nil) + if err != nil { + log.Fatalf("error in ServerSetup: %s", err) + } + log.SetFlags(log.LstdFlags | log.LUTC) if logFilename != "" { f, err := os.OpenFile(logFilename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { + // If we fail to open the log, emit a message that will + // appear in tor's log. + pt.SmethodError(ptMethodName, fmt.Sprintf("error opening log file: %s", err)) log.Fatalf("error opening log file: %s", err) } defer f.Close() log.SetOutput(f) }
- var err error - ptInfo, err = pt.ServerSetup(nil) - if err != nil { - log.Fatalf("error in ServerSetup: %s", err) - } - // Handle the various ways of setting up TLS. The legal configurations // are: // --acme-hostnames (with optional --acme-email)
tor-commits@lists.torproject.org