mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
rpc: enable building with CGO_ENABLED=0
This commit is contained in:
parent
2cd6059e51
commit
c21e983c22
2 changed files with 44 additions and 11 deletions
|
|
@ -28,20 +28,19 @@ import (
|
|||
"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"
|
||||
// maxIPCPathLength is a conservative estimate of the OS-dependent IPC
|
||||
// path length limit. If we are built with CGO enabled, we will use
|
||||
// an OS-specific limit from <sys/un.h>.
|
||||
// See:
|
||||
// https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars/367012#367012
|
||||
// and
|
||||
// https://github.com/ethereum/go-ethereum/issues/16342
|
||||
var maxIPCPathLength = 103
|
||||
|
||||
// ipcListen will create a Unix socket on the given endpoint.
|
||||
func ipcListen(endpoint string) (net.Listener, error) {
|
||||
if len(endpoint) > int(C.max_socket_path_size()) {
|
||||
log.Warn(fmt.Sprintf("The ipc endpoint is longer than %d characters. ", C.max_socket_path_size()),
|
||||
if len(endpoint) > maxIPCPathLength {
|
||||
log.Warn(fmt.Sprintf("The ipc endpoint is longer than %d characters. ", maxIPCPathLength),
|
||||
"endpoint", endpoint)
|
||||
}
|
||||
|
||||
|
|
|
|||
34
rpc/ipc_unix_cgo.go
Normal file
34
rpc/ipc_unix_cgo.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2015 The go-ethereum Authors
|
||||
// This file is part of the go-ethereum library.
|
||||
//
|
||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public License
|
||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
// +build cgo
|
||||
// +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
|
||||
|
||||
package rpc
|
||||
|
||||
/*
|
||||
#include <sys/un.h>
|
||||
|
||||
int max_socket_path_size() {
|
||||
struct sockaddr_un s;
|
||||
return sizeof(s.sun_path);
|
||||
}
|
||||
*/
|
||||
import "C"
|
||||
|
||||
func init() {
|
||||
maxIPCPathLength = int(C.max_socket_path_size())
|
||||
}
|
||||
Loading…
Reference in a new issue