@@ -46,29 +46,6 @@ const (
46
46
47
47
var interruptCallbacks = []func (os.Signal ){}
48
48
49
- // Register interrupt handlers callbacks
50
- func RegisterInterrupt (cb func (os.Signal )) {
51
- interruptCallbacks = append (interruptCallbacks , cb )
52
- }
53
-
54
- // go routine that call interrupt handlers in order of registering
55
- func HandleInterrupt () {
56
- c := make (chan os.Signal , 1 )
57
- go func () {
58
- signal .Notify (c , os .Interrupt )
59
- for sig := range c {
60
- glog .V (logger .Error ).Infof ("Shutting down (%v) ... \n " , sig )
61
- RunInterruptCallbacks (sig )
62
- }
63
- }()
64
- }
65
-
66
- func RunInterruptCallbacks (sig os.Signal ) {
67
- for _ , cb := range interruptCallbacks {
68
- cb (sig )
69
- }
70
- }
71
-
72
49
func openLogFile (Datadir string , filename string ) * os.File {
73
50
path := common .AbsolutePath (Datadir , filename )
74
51
file , err := os .OpenFile (path , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0666 )
@@ -149,19 +126,24 @@ func StartEthereum(ethereum *eth.Ethereum) {
149
126
if err := ethereum .Start (); err != nil {
150
127
Fatalf ("Error starting Ethereum: %v" , err )
151
128
}
152
- RegisterInterrupt (func (sig os.Signal ) {
153
- ethereum .Stop ()
154
- logger .Flush ()
155
- })
156
- }
157
-
158
- func StartEthereumForTest (ethereum * eth.Ethereum ) {
159
- glog .V (logger .Info ).Infoln ("Starting " , ethereum .Name ())
160
- ethereum .StartForTest ()
161
- RegisterInterrupt (func (sig os.Signal ) {
129
+ go func () {
130
+ sigc := make (chan os.Signal , 1 )
131
+ signal .Notify (sigc , os .Interrupt )
132
+ defer signal .Stop (sigc )
133
+ <- sigc
134
+ glog .V (logger .Info ).Infoln ("Got interrupt, shutting down..." )
162
135
ethereum .Stop ()
163
136
logger .Flush ()
164
- })
137
+ for i := 10 ; i > 0 ; i -- {
138
+ <- sigc
139
+ if i > 1 {
140
+ glog .V (logger .Info ).Infoln ("Already shutting down, please be patient." )
141
+ glog .V (logger .Info ).Infoln ("Interrupt" , i - 1 , "more times to induce panic." )
142
+ }
143
+ }
144
+ glog .V (logger .Error ).Infof ("Force quitting: this might not end so well." )
145
+ panic ("boom" )
146
+ }()
165
147
}
166
148
167
149
func FormatTransactionData (data string ) []byte {
0 commit comments