rpc/comms: fix #1795, ensure IPC path exists before binding

This commit is contained in:
Péter Szilágyi 2015-09-11 17:03:31 +03:00
parent 4e075e4013
commit 3e6964b841
1 changed files with 6 additions and 1 deletions

View File

@ -21,6 +21,7 @@ package comms
import ( import (
"net" "net"
"os" "os"
"path/filepath"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/logger/glog"
@ -69,7 +70,11 @@ func (self *ipcClient) reconnect() error {
} }
func startIpc(cfg IpcConfig, codec codec.Codec, initializer func(conn net.Conn) (shared.EthereumApi, error)) error { func startIpc(cfg IpcConfig, codec codec.Codec, initializer func(conn net.Conn) (shared.EthereumApi, error)) error {
os.Remove(cfg.Endpoint) // in case it still exists from a previous run // Ensure the IPC path exists and remove any previous leftover
if err := os.MkdirAll(filepath.Dir(cfg.Endpoint), 0751); err != nil {
return err
}
os.Remove(cfg.Endpoint)
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: cfg.Endpoint, Net: "unix"}) l, err := net.ListenUnix("unix", &net.UnixAddr{Name: cfg.Endpoint, Net: "unix"})
if err != nil { if err != nil {