diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index ace2849c9f06..871b8002fe18 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -25,7 +25,6 @@ import ( "sort" "strconv" "strings" - "syscall" "time" "github.com/ethereum/go-ethereum/cmd/utils" @@ -40,6 +39,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/trie" "github.com/olekukonko/tablewriter" + "golang.org/x/sys/unix" "gopkg.in/urfave/cli.v1" ) @@ -597,7 +597,7 @@ func importLDBdata(ctx *cli.Context) error { stop = make(chan struct{}) ) defer stack.Close() - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM) defer signal.Stop(interrupt) defer close(interrupt) go func() { @@ -693,7 +693,7 @@ func exportChaindata(ctx *cli.Context) error { stop = make(chan struct{}) ) defer stack.Close() - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM) defer signal.Stop(interrupt) defer close(interrupt) go func() { diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 1cdbfe866863..cdbff4d8ff1a 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -26,7 +26,6 @@ import ( "sort" "strconv" "strings" - "syscall" "time" "github.com/elastic/gosigar" @@ -45,6 +44,7 @@ import ( "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/wemix" + "golang.org/x/sys/unix" // Force-load the tracer engines to trigger registration _ "github.com/ethereum/go-ethereum/eth/tracers/js" @@ -514,8 +514,8 @@ func limitMaxRss(max int64) { timer := time.NewTimer(interval) for { <-timer.C - rusage := syscall.Rusage{} - err := syscall.Getrusage(syscall.RUSAGE_SELF, &rusage) + rusage := unix.Rusage{} + err := unix.Getrusage(unix.RUSAGE_SELF, &rusage) if err != nil { log.Error("Getrusage() failed:", "reason", err) } else { diff --git a/cmd/geth/wemixcmd.go b/cmd/geth/wemixcmd.go index 632ac93f51b3..d301dd9c6a9e 100644 --- a/cmd/geth/wemixcmd.go +++ b/cmd/geth/wemixcmd.go @@ -17,7 +17,6 @@ import ( "path/filepath" "strconv" "strings" - "syscall" "github.com/charlanxcc/logrot" "github.com/ethereum/go-ethereum/accounts/keystore" @@ -29,6 +28,7 @@ import ( "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/wemix/metclient" + "golang.org/x/sys/unix" "gopkg.in/urfave/cli.v1" ) @@ -667,10 +667,10 @@ func logrota(ctx *cli.Context) error { if err != nil { return err } - syscall.Close(syscall.Stdout) - syscall.Close(syscall.Stdout) - syscall.Dup2(int(w.Fd()), syscall.Stdout) - syscall.Dup2(int(w.Fd()), syscall.Stderr) + unix.Close(unix.Stdout) + unix.Close(unix.Stdout) + unix.Dup2(int(w.Fd()), unix.Stdout) + unix.Dup2(int(w.Fd()), unix.Stderr) go logrot.LogRotate(r, logFile, logSize, logCount) diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 47ad3b22c8dd..d9d8e605b15f 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -27,7 +27,6 @@ import ( "os/signal" "runtime" "strings" - "syscall" "time" "github.com/ethereum/go-ethereum/common" @@ -41,6 +40,7 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/rlp" + "golang.org/x/sys/unix" "gopkg.in/urfave/cli.v1" ) @@ -74,7 +74,7 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) { } go func() { sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(sigc, unix.SIGINT, unix.SIGTERM) defer signal.Stop(sigc) minFreeDiskSpace := 2 * ethconfig.Defaults.TrieDirtyCache // Default 2 * 256Mb @@ -105,7 +105,7 @@ func StartNode(ctx *cli.Context, stack *node.Node, isConsole bool) { // However, SIGTERM still shuts down the node. for { sig := <-sigc - if sig == syscall.SIGTERM { + if sig == unix.SIGTERM { shutdown() return } @@ -126,7 +126,7 @@ func monitorFreeDiskSpace(sigc chan os.Signal, path string, freeDiskSpaceCritica } if freeSpace < freeDiskSpaceCritical { log.Error("Low disk space. Gracefully shutting down Geth to prevent database corruption.", "available", common.StorageSize(freeSpace)) - sigc <- syscall.SIGTERM + sigc <- unix.SIGTERM break } else if freeSpace < 2*freeDiskSpaceCritical { log.Warn("Disk space is running low. Geth will shutdown if disk space runs below critical level.", "available", common.StorageSize(freeSpace), "critical_level", common.StorageSize(freeDiskSpaceCritical)) @@ -140,7 +140,7 @@ func ImportChain(chain *core.BlockChain, fn string) error { // If a signal is received, the import will stop at the next batch. interrupt := make(chan os.Signal, 1) stop := make(chan struct{}) - signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) + signal.Notify(interrupt, unix.SIGINT, unix.SIGTERM) defer signal.Stop(interrupt) defer close(interrupt) go func() { diff --git a/common/fdlimit/fdlimit_bsd.go b/common/fdlimit/fdlimit_bsd.go index a3a6902c0925..abe73b96197a 100644 --- a/common/fdlimit/fdlimit_bsd.go +++ b/common/fdlimit/fdlimit_bsd.go @@ -19,7 +19,7 @@ package fdlimit -import "syscall" +import "golang.org/x/sys/unix" // This file is largely identical to fdlimit_unix.go, // but Rlimit fields have type int64 on *BSD so it needs @@ -29,8 +29,8 @@ import "syscall" // to the maximum hard-limit allowed by the OS. func Raise(max uint64) (uint64, error) { // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Try to update the limit to the max allowance @@ -38,10 +38,10 @@ func Raise(max uint64) (uint64, error) { if limit.Cur > int64(max) { limit.Cur = int64(max) } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return uint64(limit.Cur), nil @@ -50,8 +50,8 @@ func Raise(max uint64) (uint64, error) { // Current retrieves the number of file descriptors allowed to be opened by this // process. func Current() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Cur), nil @@ -60,8 +60,8 @@ func Current() (int, error) { // Maximum retrieves the maximum number of file descriptors this process is // allowed to request for itself. func Maximum() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Max), nil diff --git a/common/fdlimit/fdlimit_darwin.go b/common/fdlimit/fdlimit_darwin.go index 6b26fa00f12c..dc932238eae7 100644 --- a/common/fdlimit/fdlimit_darwin.go +++ b/common/fdlimit/fdlimit_darwin.go @@ -16,7 +16,7 @@ package fdlimit -import "syscall" +import "golang.org/x/sys/unix" // hardlimit is the number of file descriptors allowed at max by the kernel. const hardlimit = 10240 @@ -26,8 +26,8 @@ const hardlimit = 10240 // Returns the size it was set to (may differ from the desired 'max') func Raise(max uint64) (uint64, error) { // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Try to update the limit to the max allowance @@ -35,11 +35,11 @@ func Raise(max uint64) (uint64, error) { if limit.Cur > max { limit.Cur = max } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // MacOS can silently apply further caps, so retrieve the actually set limit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return limit.Cur, nil @@ -48,8 +48,8 @@ func Raise(max uint64) (uint64, error) { // Current retrieves the number of file descriptors allowed to be opened by this // process. func Current() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Cur), nil @@ -59,8 +59,8 @@ func Current() (int, error) { // allowed to request for itself. func Maximum() (int, error) { // Retrieve the maximum allowed by dynamic OS limits - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Cap it to OPEN_MAX (10240) because macos is a special snowflake diff --git a/common/fdlimit/fdlimit_unix.go b/common/fdlimit/fdlimit_unix.go index a1f388ebb78d..ce6bd41bceb2 100644 --- a/common/fdlimit/fdlimit_unix.go +++ b/common/fdlimit/fdlimit_unix.go @@ -19,15 +19,15 @@ package fdlimit -import "syscall" +import "golang.org/x/sys/unix" // Raise tries to maximize the file descriptor allowance of this process // to the maximum hard-limit allowed by the OS. // Returns the size it was set to (may differ from the desired 'max') func Raise(max uint64) (uint64, error) { // Get the current limit - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // Try to update the limit to the max allowance @@ -35,11 +35,11 @@ func Raise(max uint64) (uint64, error) { if limit.Cur > max { limit.Cur = max } - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } // MacOS can silently apply further caps, so retrieve the actually set limit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return limit.Cur, nil @@ -48,8 +48,8 @@ func Raise(max uint64) (uint64, error) { // Current retrieves the number of file descriptors allowed to be opened by this // process. func Current() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Cur), nil @@ -58,8 +58,8 @@ func Current() (int, error) { // Maximum retrieves the maximum number of file descriptors this process is // allowed to request for itself. func Maximum() (int, error) { - var limit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { + var limit unix.Rlimit + if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &limit); err != nil { return 0, err } return int(limit.Max), nil diff --git a/console/console.go b/console/console.go index 78706860e0cb..0b1b21165183 100644 --- a/console/console.go +++ b/console/console.go @@ -27,7 +27,6 @@ import ( "sort" "strings" "sync" - "syscall" "github.com/dop251/goja" "github.com/ethereum/go-ethereum/console/prompt" @@ -37,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/rpc" "github.com/mattn/go-colorable" "github.com/peterh/liner" + "golang.org/x/sys/unix" ) var ( @@ -371,7 +371,7 @@ func (c *Console) interruptHandler() { // Unfortunately, it is not possible to abort the prompt in this case and // the c.readLines goroutine leaks. sig := make(chan os.Signal, 1) - signal.Notify(sig, syscall.SIGINT) + signal.Notify(sig, unix.SIGINT) defer signal.Stop(sig) for { diff --git a/internal/cmdtest/test_cmd.go b/internal/cmdtest/test_cmd.go index fd7a4a8b7f4c..3abdb1fe8b5d 100644 --- a/internal/cmdtest/test_cmd.go +++ b/internal/cmdtest/test_cmd.go @@ -27,12 +27,12 @@ import ( "strings" "sync" "sync/atomic" - "syscall" "testing" "text/template" "time" "github.com/docker/docker/pkg/reexec" + "golang.org/x/sys/unix" ) func NewTestCmd(t *testing.T, data interface{}) *TestCmd { @@ -208,7 +208,7 @@ func (tt *TestCmd) ExitStatus() int { if tt.Err != nil { exitErr := tt.Err.(*exec.ExitError) if exitErr != nil { - if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { + if status, ok := exitErr.Sys().(unix.WaitStatus); ok { return status.ExitStatus() } } diff --git a/metrics/cputime_unix.go b/metrics/cputime_unix.go index 3c56a75d0077..3948ef6f8882 100644 --- a/metrics/cputime_unix.go +++ b/metrics/cputime_unix.go @@ -20,15 +20,14 @@ package metrics import ( - syscall "golang.org/x/sys/unix" - "github.com/ethereum/go-ethereum/log" + "golang.org/x/sys/unix" ) // getProcessCPUTime retrieves the process' CPU time since program startup. func getProcessCPUTime() int64 { - var usage syscall.Rusage - if err := syscall.Getrusage(syscall.RUSAGE_SELF, &usage); err != nil { + var usage unix.Rusage + if err := unix.Getrusage(unix.RUSAGE_SELF, &usage); err != nil { log.Warn("Failed to retrieve CPU time", "err", err) return 0 } diff --git a/node/errors.go b/node/errors.go index 67547bf691f1..6855c8ad6103 100644 --- a/node/errors.go +++ b/node/errors.go @@ -20,7 +20,8 @@ import ( "errors" "fmt" "reflect" - "syscall" + + "golang.org/x/sys/unix" ) var ( @@ -33,7 +34,7 @@ var ( ) func convertFileLockError(err error) error { - if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] { + if errno, ok := err.(unix.Errno); ok && datadirInUseErrnos[uint(errno)] { return ErrDatadirUsed } return err diff --git a/p2p/netutil/toobig_windows.go b/p2p/netutil/toobig_windows.go index 652903e83c30..128150f7bd1f 100644 --- a/p2p/netutil/toobig_windows.go +++ b/p2p/netutil/toobig_windows.go @@ -22,10 +22,11 @@ package netutil import ( "net" "os" - "syscall" + + "golang.org/x/sys/unix" ) -const _WSAEMSGSIZE = syscall.Errno(10040) +const _WSAEMSGSIZE = unix.Errno(10040) // isPacketTooBig reports whether err indicates that a UDP packet didn't // fit the receive buffer. On Windows, WSARecvFrom returns diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 35ccdfb06882..d6d8de89fc69 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -31,7 +31,6 @@ import ( "path/filepath" "strings" "sync" - "syscall" "time" "github.com/docker/docker/pkg/reexec" @@ -41,6 +40,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/rpc" "github.com/gorilla/websocket" + "golang.org/x/sys/unix" ) func init() { @@ -295,7 +295,7 @@ func (n *ExecNode) Stop() error { n.Info = nil } - if err := n.Cmd.Process.Signal(syscall.SIGTERM); err != nil { + if err := n.Cmd.Process.Signal(unix.SIGTERM); err != nil { return n.Cmd.Process.Kill() } waitErr := make(chan error, 1) @@ -438,7 +438,7 @@ func execP2PNode() { // Stop the stack if we get a SIGTERM signal. go func() { sigc := make(chan os.Signal, 1) - signal.Notify(sigc, syscall.SIGTERM) + signal.Notify(sigc, unix.SIGTERM) defer signal.Stop(sigc) <-sigc log.Info("Received SIGTERM, shutting down...")