aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-07-06 21:32:24 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-07-06 21:32:24 +0800
commit4c30f0f9ac33e02908c6848744dafff9031b86f3 (patch)
tree7b87722425ca1c170aa99ee467cf91bfbb6e82f2
parentfa7b3b72765aa49e3ddffdd7c99cf7e94afd34ca (diff)
parent5615fc47149ea5db6ad6f5b1b716e5af9900f848 (diff)
downloaddexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.tar
dexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.tar.gz
dexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.tar.bz2
dexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.tar.lz
dexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.tar.xz
dexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.tar.zst
dexon-4c30f0f9ac33e02908c6848744dafff9031b86f3.zip
Merge pull request #1416 from fjl/one-interrupt
cmd/geth, cmd/utils: improve interrupt handling
-rw-r--r--cmd/geth/main.go4
-rw-r--r--cmd/utils/cmd.go50
2 files changed, 17 insertions, 37 deletions
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index ffd26a7c2..3428bb4cf 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -347,7 +347,6 @@ func main() {
}
func run(ctx *cli.Context) {
- utils.HandleInterrupt()
cfg := utils.MakeEthConfig(ClientIdentifier, nodeNameVersion, ctx)
ethereum, err := eth.New(cfg)
if err != nil {
@@ -527,10 +526,9 @@ func blockRecovery(ctx *cli.Context) {
func startEth(ctx *cli.Context, eth *eth.Ethereum) {
// Start Ethereum itself
-
utils.StartEthereum(eth)
- am := eth.AccountManager()
+ am := eth.AccountManager()
account := ctx.GlobalString(utils.UnlockedAccountFlag.Name)
accounts := strings.Split(account, " ")
for i, account := range accounts {
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index f7520a8e4..33a6c1cb2 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -46,29 +46,6 @@ const (
var interruptCallbacks = []func(os.Signal){}
-// Register interrupt handlers callbacks
-func RegisterInterrupt(cb func(os.Signal)) {
- interruptCallbacks = append(interruptCallbacks, cb)
-}
-
-// go routine that call interrupt handlers in order of registering
-func HandleInterrupt() {
- c := make(chan os.Signal, 1)
- go func() {
- signal.Notify(c, os.Interrupt)
- for sig := range c {
- glog.V(logger.Error).Infof("Shutting down (%v) ... \n", sig)
- RunInterruptCallbacks(sig)
- }
- }()
-}
-
-func RunInterruptCallbacks(sig os.Signal) {
- for _, cb := range interruptCallbacks {
- cb(sig)
- }
-}
-
func openLogFile(Datadir string, filename string) *os.File {
path := common.AbsolutePath(Datadir, filename)
file, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
@@ -149,19 +126,24 @@ func StartEthereum(ethereum *eth.Ethereum) {
if err := ethereum.Start(); err != nil {
Fatalf("Error starting Ethereum: %v", err)
}
- RegisterInterrupt(func(sig os.Signal) {
- ethereum.Stop()
- logger.Flush()
- })
-}
-
-func StartEthereumForTest(ethereum *eth.Ethereum) {
- glog.V(logger.Info).Infoln("Starting ", ethereum.Name())
- ethereum.StartForTest()
- RegisterInterrupt(func(sig os.Signal) {
+ go func() {
+ sigc := make(chan os.Signal, 1)
+ signal.Notify(sigc, os.Interrupt)
+ defer signal.Stop(sigc)
+ <-sigc
+ glog.V(logger.Info).Infoln("Got interrupt, shutting down...")
ethereum.Stop()
logger.Flush()
- })
+ for i := 10; i > 0; i-- {
+ <-sigc
+ if i > 1 {
+ glog.V(logger.Info).Infoln("Already shutting down, please be patient.")
+ glog.V(logger.Info).Infoln("Interrupt", i-1, "more times to induce panic.")
+ }
+ }
+ glog.V(logger.Error).Infof("Force quitting: this might not end so well.")
+ panic("boom")
+ }()
}
func FormatTransactionData(data string) []byte {