mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
rpc: get max socket path length from OS headers
This commit is contained in:
parent
ecb2ec9b06
commit
e97307b8e0
1 changed files with 14 additions and 3 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue