Merge pull request #16142 from karalabe/graceful-sigterm

cmd, console: support all termination signals
pull/16153/head
Péter Szilágyi 7 years ago committed by GitHub
commit 7d57824663
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      cmd/geth/consolecmd.go
  2. 5
      cmd/utils/cmd.go
  3. 3
      console/console.go

@ -22,6 +22,7 @@ import (
"os/signal" "os/signal"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/console"
@ -207,7 +208,7 @@ func ephemeralConsole(ctx *cli.Context) error {
} }
// Wait for pending callbacks, but stop for Ctrl-C. // Wait for pending callbacks, but stop for Ctrl-C.
abort := make(chan os.Signal, 1) abort := make(chan os.Signal, 1)
signal.Notify(abort, os.Interrupt) signal.Notify(abort, syscall.SIGINT, syscall.SIGTERM)
go func() { go func() {
<-abort <-abort

@ -25,6 +25,7 @@ import (
"os/signal" "os/signal"
"runtime" "runtime"
"strings" "strings"
"syscall"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -64,7 +65,7 @@ func StartNode(stack *node.Node) {
} }
go func() { go func() {
sigc := make(chan os.Signal, 1) sigc := make(chan os.Signal, 1)
signal.Notify(sigc, os.Interrupt) signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(sigc) defer signal.Stop(sigc)
<-sigc <-sigc
log.Info("Got interrupt, shutting down...") log.Info("Got interrupt, shutting down...")
@ -85,7 +86,7 @@ func ImportChain(chain *core.BlockChain, fn string) error {
// If a signal is received, the import will stop at the next batch. // If a signal is received, the import will stop at the next batch.
interrupt := make(chan os.Signal, 1) interrupt := make(chan os.Signal, 1)
stop := make(chan struct{}) stop := make(chan struct{})
signal.Notify(interrupt, os.Interrupt) signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(interrupt) defer signal.Stop(interrupt)
defer close(interrupt) defer close(interrupt)
go func() { go func() {

@ -26,6 +26,7 @@ import (
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"syscall"
"github.com/ethereum/go-ethereum/internal/jsre" "github.com/ethereum/go-ethereum/internal/jsre"
"github.com/ethereum/go-ethereum/internal/web3ext" "github.com/ethereum/go-ethereum/internal/web3ext"
@ -332,7 +333,7 @@ func (c *Console) Interactive() {
}() }()
// Monitor Ctrl-C too in case the input is empty and we need to bail // Monitor Ctrl-C too in case the input is empty and we need to bail
abort := make(chan os.Signal, 1) abort := make(chan os.Signal, 1)
signal.Notify(abort, os.Interrupt) signal.Notify(abort, syscall.SIGINT, syscall.SIGTERM)
// Start sending prompts to the user and reading back inputs // Start sending prompts to the user and reading back inputs
for { for {

Loading…
Cancel
Save