Commit e12628ce authored by Jacob Vosmaer's avatar Jacob Vosmaer

Improve Unix domain socket support

parent b67e2dd2
...@@ -49,6 +49,7 @@ var repoRoot string ...@@ -49,6 +49,7 @@ var repoRoot string
var printVersion = flag.Bool("version", false, "Print version and exit") var printVersion = flag.Bool("version", false, "Print version and exit")
var listenAddr = flag.String("listenAddr", "localhost:8181", "Listen address for HTTP server") var listenAddr = flag.String("listenAddr", "localhost:8181", "Listen address for HTTP server")
var listenNetwork = flag.String("listenNetwork", "tcp", "Listen 'network' (protocol)") var listenNetwork = flag.String("listenNetwork", "tcp", "Listen 'network' (protocol)")
var listenUmask = flag.Int("listenUmask", 022, "Umask for Unix socket, default: 022")
var authBackend = flag.String("authBackend", "http://localhost:8080", "Authentication/authorization backend") var authBackend = flag.String("authBackend", "http://localhost:8080", "Authentication/authorization backend")
var gitServices = [...]gitService{ var gitServices = [...]gitService{
...@@ -77,10 +78,22 @@ func main() { ...@@ -77,10 +78,22 @@ func main() {
log.Printf("repoRoot: %s", repoRoot) log.Printf("repoRoot: %s", repoRoot)
http.HandleFunc("/", gitHandler) http.HandleFunc("/", gitHandler)
// Good housekeeping for Unix sockets: unlink before binding
if *listenNetwork == "unix" {
if err := os.Remove(*listenAddr); err != nil {
log.Fatal(err)
}
}
// Change the umask only around net.Listen()
oldUmask := syscall.Umask(*listenUmask)
listener, err := net.Listen(*listenNetwork, *listenAddr) listener, err := net.Listen(*listenNetwork, *listenAddr)
syscall.Umask(oldUmask)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
log.Fatal(http.Serve(listener, nil)) log.Fatal(http.Serve(listener, nil))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment