summaryrefslogtreecommitdiff
path: root/server_config.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2019-12-23 15:20:57 +0300
committerWolfy-J <[email protected]>2019-12-23 15:20:57 +0300
commitd39e20a58c8a40eefe6e5d6761f78f38f024b46e (patch)
treecd4f7f514cc1b735bef07f0228e7f41bf52c5d8d /server_config.go
parent1d225f1e88d176c955111d2a033ab0f14834f93e (diff)
- check before erasing unix sock
Diffstat (limited to 'server_config.go')
-rw-r--r--server_config.go12
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()
+}