Skip to content

Commit

Permalink
Fix: replace deprecated syscall pkg to golang.org/x/sys/unix pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-ahn-wm committed May 23, 2024
1 parent cad51f5 commit 5028477
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 58 deletions.
6 changes: 3 additions & 3 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"time"

"github.com/ethereum/go-ethereum/cmd/utils"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"sort"
"strconv"
"strings"
"syscall"
"time"

"github.com/elastic/gosigar"
Expand All @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions cmd/geth/wemixcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"path/filepath"
"strconv"
"strings"
"syscall"

"github.com/charlanxcc/logrot"
"github.com/ethereum/go-ethereum/accounts/keystore"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"os/signal"
"runtime"
"strings"
"syscall"
"time"

"github.com/ethereum/go-ethereum/common"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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))
Expand All @@ -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() {
Expand Down
18 changes: 9 additions & 9 deletions common/fdlimit/fdlimit_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,19 +29,19 @@ 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
limit.Cur = limit.Max
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
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions common/fdlimit/fdlimit_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,20 +26,20 @@ 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
limit.Cur = limit.Max
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
Expand All @@ -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
Expand All @@ -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
Expand Down
18 changes: 9 additions & 9 deletions common/fdlimit/fdlimit_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@

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
limit.Cur = limit.Max
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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sort"
"strings"
"sync"
"syscall"

"github.com/dop251/goja"
"github.com/ethereum/go-ethereum/console/prompt"
Expand All @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/cmdtest/test_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
Expand Down
7 changes: 3 additions & 4 deletions metrics/cputime_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions node/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"errors"
"fmt"
"reflect"
"syscall"

"golang.org/x/sys/unix"
)

var (
Expand All @@ -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
Expand Down
Loading

0 comments on commit 5028477

Please sign in to comment.