aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-06-26 17:47:45 +0800
committerzelig <viktor.tron@gmail.com>2014-06-26 17:47:45 +0800
commit2f96652bb408e65c205317403d749ba9a395c6bb (patch)
tree401b515d2a1d1d668ed692c8a39788f06ebc2b73
parent9a06efd0809c370451c5e85ce4688104cd5df461 (diff)
downloadgo-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.tar
go-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.tar.gz
go-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.tar.bz2
go-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.tar.lz
go-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.tar.xz
go-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.tar.zst
go-tangerine-2f96652bb408e65c205317403d749ba9a395c6bb.zip
interrupt handlers now ordered
-rw-r--r--ethereal/main.go12
-rw-r--r--ethereum/cmd.go1
-rw-r--r--ethereum/main.go2
-rw-r--r--utils/cmd.go25
4 files changed, 24 insertions, 16 deletions
diff --git a/ethereal/main.go b/ethereal/main.go
index 10571be7b..5dfab4c45 100644
--- a/ethereal/main.go
+++ b/ethereal/main.go
@@ -8,10 +8,12 @@ import (
)
func main() {
- qml.Init(nil)
-
runtime.GOMAXPROCS(runtime.NumCPU())
+ utils.HandleInterrupt()
+
+ qml.Init(nil)
+
// precedence: code-internal flag default < config file < environment variables < command line
Init() // parsing command line
utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
@@ -33,8 +35,10 @@ func main() {
utils.StartRpc(ethereum, RpcPort)
}
- utils.StartEthereum(ethereum, UseSeed)
-
gui := ethui.New(ethereum, LogLevel)
gui.Start(AssetPath)
+
+ utils.StartEthereum(ethereum, UseSeed)
+
+
}
diff --git a/ethereum/cmd.go b/ethereum/cmd.go
index 0e9c2be8c..2dfd54666 100644
--- a/ethereum/cmd.go
+++ b/ethereum/cmd.go
@@ -12,7 +12,6 @@ func InitJsConsole(ethereum *eth.Ethereum) {
go repl.Start()
utils.RegisterInterrupt(func(os.Signal) {
repl.Stop()
- ethereum.Stop()
})
}
diff --git a/ethereum/main.go b/ethereum/main.go
index bbbaf5541..800486e56 100644
--- a/ethereum/main.go
+++ b/ethereum/main.go
@@ -11,6 +11,8 @@ var logger = ethlog.NewLogger("CLI")
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
+ utils.HandleInterrupt()
+
// precedence: code-internal flag default < config file < environment variables < command line
Init() // parsing command line
utils.InitConfig(ConfigFile, Datadir, Identifier, "ETH")
diff --git a/utils/cmd.go b/utils/cmd.go
index 34716b94a..da05c6d83 100644
--- a/utils/cmd.go
+++ b/utils/cmd.go
@@ -18,16 +18,23 @@ import (
)
var logger = ethlog.NewLogger("CLI")
+var interruptCallbacks = []func(os.Signal){}
-// Register interrupt handlers
+// 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() {
- // Buffered chan of one is enough
- c := make(chan os.Signal, 1)
- // Notify about interrupts for now
signal.Notify(c, os.Interrupt)
for sig := range c {
- cb(sig)
+ logger.Errorf("Shutting down (%v) ... \n", sig)
+ for _, cb := range interruptCallbacks {
+ cb(sig)
+ }
}
}()
}
@@ -109,13 +116,12 @@ func NewEthereum(UseUPnP bool, OutboundPort string, MaxPeer int) *eth.Ethereum {
func StartEthereum(ethereum *eth.Ethereum, UseSeed bool) {
logger.Infof("Starting Ethereum v%s", ethutil.Config.Ver)
ethereum.Start(UseSeed)
- // Wait for shutdown
- ethereum.WaitForShutdown()
RegisterInterrupt(func(sig os.Signal) {
- logger.Errorf("Shutting down (%v) ... \n", sig)
ethereum.Stop()
ethlog.Flush()
})
+ // this blocks the thread
+ ethereum.WaitForShutdown()
}
func ShowGenesis(ethereum *eth.Ethereum) {
@@ -174,9 +180,6 @@ func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
logger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
} else {
go ethereum.RpcServer.Start()
- RegisterInterrupt(func(os.Signal) {
- ethereum.RpcServer.Stop()
- })
}
}