rpc: get max socket path length from OS headers

This commit is contained in:
Guillaume Ballet 2019-01-02 10:52:18 +01:00
parent ecb2ec9b06
commit e97307b8e0

View file

@ -20,6 +20,7 @@ package rpc
import ( import (
"context" "context"
"fmt"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@ -27,11 +28,21 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
/*
#include <sys/un.h>
int max_socket_path_size() {
struct sockaddr_un s;
return sizeof(s.sun_path);
}
*/
import "C"
// ipcListen will create a Unix socket on the given endpoint. // ipcListen will create a Unix socket on the given endpoint.
func ipcListen(endpoint string) (net.Listener, error) { func ipcListen(endpoint string) (net.Listener, error) {
if len(endpoint) > 107 { if len(endpoint) > int(C.max_socket_path_size()) {
log.Warn("The ipc endpoint is longer than 107 characters and is restricted to this size by linux. "+ log.Warn(fmt.Sprintf("The ipc endpoint is longer than %d characters. ", C.max_socket_path_size()),
"Shorten this path to less than 108 characters.", "endpoint", endpoint) "endpoint", endpoint)
} }
// Ensure the IPC path exists and remove any previous leftover // Ensure the IPC path exists and remove any previous leftover