Fix UNIX socket support.

This commit is contained in:
luk3yx 2020-06-15 17:55:43 +12:00
parent a29e6f1cd6
commit fce0e42307
2 changed files with 14 additions and 1 deletions

View File

@ -8,7 +8,8 @@ name: Test
address: "[::]"
port: 5000
# Alternatively, lurkcoin can bind on a UNIX domain socket.
# Alternatively, lurkcoin can bind on a UNIX domain socket. The socket will be
# world-writable.
# network_protocol: unix
# address: "/tmp/lurkcoin.sock"

View File

@ -151,6 +151,11 @@ func StartServer(config *Config) {
log.Printf("Starting server on http://%s/", urlAddress)
}
// Remove any socket file that already exists
if networkProtocol == "unix" {
os.Remove(address)
}
// Bind to the address
var ln net.Listener
ln, err = net.Listen(networkProtocol, address)
@ -158,6 +163,13 @@ func StartServer(config *Config) {
log.Fatal(err)
}
// Change permissions on the UNIX socket
if networkProtocol == "unix" {
if err := os.Chmod(address, 0777); err != nil {
log.Fatal(err)
}
}
// Switch to the logfile
if config.Logfile != "" {
f, err := os.OpenFile(