mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #7646 from andelf/fix-unix-socket-url
*: fix a bug in handling unix socket urls
This commit is contained in:
commit
d42c1f5131
@ -184,6 +184,7 @@ func parseEndpoint(endpoint string) (proto string, host string, scheme string) {
|
|||||||
case "http", "https":
|
case "http", "https":
|
||||||
case "unix":
|
case "unix":
|
||||||
proto = "unix"
|
proto = "unix"
|
||||||
|
host = url.Host + url.Path
|
||||||
default:
|
default:
|
||||||
proto, host = "", ""
|
proto, host = "", ""
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ func (ep *etcdProcess) Stop() error {
|
|||||||
<-ep.donec
|
<-ep.donec
|
||||||
|
|
||||||
if ep.cfg.purl.Scheme == "unix" || ep.cfg.purl.Scheme == "unixs" {
|
if ep.cfg.purl.Scheme == "unix" || ep.cfg.purl.Scheme == "unixs" {
|
||||||
os.RemoveAll(ep.cfg.purl.Host)
|
os.Remove(ep.cfg.purl.Host + ep.cfg.purl.Path)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -258,19 +258,21 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
proto := "tcp"
|
proto := "tcp"
|
||||||
|
addr := u.Host
|
||||||
if u.Scheme == "unix" || u.Scheme == "unixs" {
|
if u.Scheme == "unix" || u.Scheme == "unixs" {
|
||||||
proto = "unix"
|
proto = "unix"
|
||||||
|
addr = u.Host + u.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
sctx.secure = u.Scheme == "https" || u.Scheme == "unixs"
|
sctx.secure = u.Scheme == "https" || u.Scheme == "unixs"
|
||||||
sctx.insecure = !sctx.secure
|
sctx.insecure = !sctx.secure
|
||||||
if oldctx := sctxs[u.Host]; oldctx != nil {
|
if oldctx := sctxs[addr]; oldctx != nil {
|
||||||
oldctx.secure = oldctx.secure || sctx.secure
|
oldctx.secure = oldctx.secure || sctx.secure
|
||||||
oldctx.insecure = oldctx.insecure || sctx.insecure
|
oldctx.insecure = oldctx.insecure || sctx.insecure
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if sctx.l, err = net.Listen(proto, u.Host); err != nil {
|
if sctx.l, err = net.Listen(proto, addr); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +306,7 @@ func startClientListeners(cfg *Config) (sctxs map[string]*serveCtx, err error) {
|
|||||||
if cfg.Debug {
|
if cfg.Debug {
|
||||||
sctx.registerTrace()
|
sctx.registerTrace()
|
||||||
}
|
}
|
||||||
sctxs[u.Host] = sctx
|
sctxs[addr] = sctx
|
||||||
}
|
}
|
||||||
return sctxs, nil
|
return sctxs, nil
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
type unixListener struct{ net.Listener }
|
type unixListener struct{ net.Listener }
|
||||||
|
|
||||||
func NewUnixListener(addr string) (net.Listener, error) {
|
func NewUnixListener(addr string) (net.Listener, error) {
|
||||||
if err := os.RemoveAll(addr); err != nil {
|
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
l, err := net.Listen("unix", addr)
|
l, err := net.Listen("unix", addr)
|
||||||
@ -33,7 +33,7 @@ func NewUnixListener(addr string) (net.Listener, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ul *unixListener) Close() error {
|
func (ul *unixListener) Close() error {
|
||||||
if err := os.RemoveAll(ul.Addr().String()); err != nil {
|
if err := os.Remove(ul.Addr().String()); err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return ul.Listener.Close()
|
return ul.Listener.Close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user