Merge pull request #2502 from hamo/unlink_err_v4

rewrite protocol check with switch-case in Server.Daemon
Upstream-commit: c5d4459a02ee98f629e65402551a871c451fb6ac
Component: engine
This commit is contained in:
Victor Vieux
2013-11-04 17:46:46 -08:00

View File

@ -71,13 +71,16 @@ func (srv *Server) Daemon() error {
chErrors := make(chan error, len(protoAddrs))
for _, protoAddr := range protoAddrs {
protoAddrParts := strings.SplitN(protoAddr, "://", 2)
if protoAddrParts[0] == "unix" {
syscall.Unlink(protoAddrParts[1])
} else if protoAddrParts[0] == "tcp" {
switch protoAddrParts[0] {
case "unix":
if err := syscall.Unlink(protoAddrParts[1]); err != nil && !os.IsNotExist(err) {
log.Fatal(err)
}
case "tcp":
if !strings.HasPrefix(protoAddrParts[1], "127.0.0.1") {
log.Println("/!\\ DON'T BIND ON ANOTHER IP ADDRESS THAN 127.0.0.1 IF YOU DON'T KNOW WHAT YOU'RE DOING /!\\")
}
} else {
default:
return fmt.Errorf("Invalid protocol format.")
}
go func() {