commit 7a215efea0d6277d24c700b2b4e629a93b1cac45
Author: Yawning Angel <yawning(a)schwanenlied.me>
Date: Mon Nov 28 02:25:37 2016 +0000
Clean up tor's socket files on Shutdown().
---
src/cmd/sandboxed-tor-browser/internal/tor/tor.go | 11 ++++++++++-
src/cmd/sandboxed-tor-browser/internal/ui/install.go | 2 +-
src/cmd/sandboxed-tor-browser/internal/ui/launch.go | 2 +-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/cmd/sandboxed-tor-browser/internal/tor/tor.go b/src/cmd/sandboxed-tor-browser/internal/tor/tor.go
index 64a9fd9..58b34d0 100644
--- a/src/cmd/sandboxed-tor-browser/internal/tor/tor.go
+++ b/src/cmd/sandboxed-tor-browser/internal/tor/tor.go
@@ -62,10 +62,13 @@ type Tor struct {
socksNet string
socksAddr string
+ ctrlAddr string
ctrlSurrogate *ctrlProxy
socksSurrogate *socksProxy
socksPassthrough *passthroughProxy
+
+ unlinkOnExit []string
}
// IsSystem returns if the tor instance is a OS service not being actively
@@ -176,6 +179,10 @@ func (t *Tor) Shutdown() {
t.socksPassthrough.close()
t.socksPassthrough = nil
}
+
+ for _, fn := range t.unlinkOnExit {
+ os.Remove(fn)
+ }
}
// SocksSurrogatePath returns the socks port surrogate AF_UNIX path.
@@ -266,7 +273,9 @@ func NewSandboxedTor(cfg *config.Config, cmd *exec.Cmd) *Tor {
t.cmd = cmd
t.socksNet = "unix"
t.socksAddr = filepath.Join(cfg.TorDataDir, "socks")
+ t.ctrlAddr = filepath.Join(cfg.TorDataDir, "control")
t.ctrlEvents = make(chan *bulb.Response, 16)
+ t.unlinkOnExit = []string{t.socksAddr, t.ctrlAddr}
return t
}
@@ -307,7 +316,7 @@ func (t *Tor) DoBootstrap(cfg *config.Config, async *Async) (err error) {
// Dial the control port.
async.UpdateProgress("Connecting to the Tor Control Port.")
- if t.ctrl, err = bulb.Dial("unix", filepath.Join(cfg.TorDataDir, "control")); err != nil {
+ if t.ctrl, err = bulb.Dial("unix", t.ctrlAddr); err != nil {
return err
}
diff --git a/src/cmd/sandboxed-tor-browser/internal/ui/install.go b/src/cmd/sandboxed-tor-browser/internal/ui/install.go
index 208e019..16bde15 100644
--- a/src/cmd/sandboxed-tor-browser/internal/ui/install.go
+++ b/src/cmd/sandboxed-tor-browser/internal/ui/install.go
@@ -43,7 +43,7 @@ func (c *Common) DoInstall(async *Async) {
async.Err = nil
defer func() {
if len(async.Cancel) > 0 {
- <- async.Cancel
+ <-async.Cancel
}
if async.Err != nil {
log.Printf("install: Failing with error: %v", async.Err)
diff --git a/src/cmd/sandboxed-tor-browser/internal/ui/launch.go b/src/cmd/sandboxed-tor-browser/internal/ui/launch.go
index 56c0f54..6a86dba 100644
--- a/src/cmd/sandboxed-tor-browser/internal/ui/launch.go
+++ b/src/cmd/sandboxed-tor-browser/internal/ui/launch.go
@@ -32,7 +32,7 @@ func (c *Common) DoLaunch(async *Async, checkUpdates bool) {
async.Err = nil
defer func() {
if len(async.Cancel) > 0 {
- <- async.Cancel
+ <-async.Cancel
}
if async.Err != nil {
log.Printf("launch: Failing with error: %v", async.Err)