rpc: enable building with CGO_ENABLED=0

This commit is contained in:
Jeremy Schlatter 2019-05-22 16:59:50 -07:00
parent 2cd6059e51
commit c21e983c22
2 changed files with 44 additions and 11 deletions

View file

@ -28,20 +28,19 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
) )
/* // maxIPCPathLength is a conservative estimate of the OS-dependent IPC
#include <sys/un.h> // path length limit. If we are built with CGO enabled, we will use
// an OS-specific limit from <sys/un.h>.
int max_socket_path_size() { // See:
struct sockaddr_un s; // https://unix.stackexchange.com/questions/367008/why-is-socket-path-length-limited-to-a-hundred-chars/367012#367012
return sizeof(s.sun_path); // and
} // https://github.com/ethereum/go-ethereum/issues/16342
*/ var maxIPCPathLength = 103
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) > int(C.max_socket_path_size()) { if len(endpoint) > maxIPCPathLength {
log.Warn(fmt.Sprintf("The ipc endpoint is longer than %d characters. ", C.max_socket_path_size()), log.Warn(fmt.Sprintf("The ipc endpoint is longer than %d characters. ", maxIPCPathLength),
"endpoint", endpoint) "endpoint", endpoint)
} }

34
rpc/ipc_unix_cgo.go Normal file
View 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())
}