commit 82a68236b1a150961d777ef9073044c88a9f9aa4 Author: David Fifield david@bamsoftware.com Date: Mon Apr 7 23:24:17 2014 -0700
Add processterminate-buffer program.
This program insulates a transport plugin from tor on Windows, so that the transport plugin can clean up after itself. --- .gitignore | 1 + processterminate-buffer/main.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+)
diff --git a/.gitignore b/.gitignore index 3d5729c..d442bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /meek-client/meek-client /meek-client-torbrowser/meek-client-torbrowser /meek-server/meek-server +/processterminate-buffer/processterminate-buffer diff --git a/processterminate-buffer/main.go b/processterminate-buffer/main.go new file mode 100644 index 0000000..cb68ee4 --- /dev/null +++ b/processterminate-buffer/main.go @@ -0,0 +1,33 @@ +// This program is designed to sit between tor and a transport plugin on +// Windows. On Windows, transport plugins are killed with a ProcessTerminate, +// which doesn't give them a chance to clean up before exiting. +// https://trac.torproject.org/projects/tor/ticket/9330 +// The idea of this program is that the transport plugin can read from its +// standard input, which will be closed when this program is terminated. The +// transport plugin can then treat the stdin-closed event like a SIGTERM. +package main + +import ( + "log" + "os" + "os/exec" +) + +func main() { + args := os.Args[1:] + if len(args) < 1 { + log.Fatalf("%s needs a command to run", os.Args[0]) + } + cmd := exec.Command(args[0], args[1:]...) + cmd.Stdin = os.Stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Start() + if err != nil { + log.Fatal(err) + } + err = cmd.Wait() + if err != nil { + log.Fatal(err) + } +}