Merge pull request #204 from letsrock-today/master

Unix domain socket permissions settings (issue #203)
This commit is contained in:
siddontang 2015-11-24 08:40:32 +08:00
commit 62e4c0d7f4
3 changed files with 21 additions and 1 deletions

View File

@ -97,6 +97,8 @@ type Config struct {
Addr string `toml:"addr"` Addr string `toml:"addr"`
AddrUnixSocketPerm string `toml:"addr_unixsocketperm"`
HttpAddr string `toml:"http_addr"` HttpAddr string `toml:"http_addr"`
SlaveOf string `toml:"slaveof"` SlaveOf string `toml:"slaveof"`

View File

@ -3,6 +3,10 @@
# Server listen address # Server listen address
addr = "127.0.0.1:6380" addr = "127.0.0.1:6380"
# Unix socket permissions, 755 by default.
# Ignored for tcp socket.
addr_unixsocketperm = "0770"
# Server http listen address, set empty to disable # Server http listen address, set empty to disable
http_addr = "127.0.0.1:11181" http_addr = "127.0.0.1:11181"

View File

@ -3,7 +3,9 @@ package server
import ( import (
"net" "net"
"net/http" "net/http"
"os"
"path" "path"
"strconv"
"strings" "strings"
"sync" "sync"
@ -86,10 +88,22 @@ func NewApp(cfg *config.Config) (*App, error) {
return nil, err return nil, err
} }
if app.listener, err = net.Listen(netType(cfg.Addr), cfg.Addr); err != nil { addrNetType := netType(cfg.Addr)
if app.listener, err = net.Listen(addrNetType, cfg.Addr); err != nil {
return nil, err return nil, err
} }
if addrNetType == "unix" && len(cfg.AddrUnixSocketPerm) > 0 {
var perm int64
if perm, err = strconv.ParseInt(cfg.AddrUnixSocketPerm, 8, 32); err != nil {
return nil, err
}
if err = os.Chmod(cfg.Addr, os.FileMode(perm)); err != nil {
return nil, err
}
}
if len(cfg.HttpAddr) > 0 { if len(cfg.HttpAddr) > 0 {
if app.httpListener, err = net.Listen(netType(cfg.HttpAddr), cfg.HttpAddr); err != nil { if app.httpListener, err = net.Listen(netType(cfg.HttpAddr), cfg.HttpAddr); err != nil {
return nil, err return nil, err