diff options
Diffstat (limited to 'server_config.go')
-rw-r--r-- | server_config.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/server_config.go b/server_config.go index 641c1866..5403ff01 100644 --- a/server_config.go +++ b/server_config.go @@ -127,7 +127,7 @@ func (cfg *ServerConfig) makeFactory() (Factory, error) { return nil, errors.New("invalid relay DSN (pipes, tcp://:6001, unix://rr.sock)") } - if dsn[0] == "unix" { + if dsn[0] == "unix" && fileExists(dsn[1]) { err := syscall.Unlink(dsn[1]) if err != nil { return nil, err @@ -141,3 +141,13 @@ func (cfg *ServerConfig) makeFactory() (Factory, error) { return NewSocketFactory(ln, cfg.RelayTimeout), nil } + +// fileExists checks if a file exists and is not a directory before we +// try using it to prevent further errors. +func fileExists(filename string) bool { + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() +} |