signal: handle shutdown properly
This addresses issues related to the mobile lnd builds, where calling `stopDaemon` and subsequently calling LndMobile's `Start` results in crash.
This commit is contained in:
1 parent
6046c5cf86
commit
ada1bc701c
11 files changed
+170
-129
No files matched your search
+7
-6
@@ -45,17 +45,18 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
|
||||
// LoadConfig below.
|
||||
os.Args = append(os.Args, splitArgs...)
|
||||
|
||||
// Load the configuration, and parse the extra arguments as command
|
||||
// line options. This function will also set up logging properly.
|
||||
loadedConfig, err := lnd.LoadConfig()
|
||||
// Hook interceptor for os signals.
|
||||
shutdownInterceptor, err := signal.Intercept()
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Hook interceptor for os signals.
|
||||
if err := signal.Intercept(); err != nil {
|
||||
// Load the configuration, and parse the extra arguments as command
|
||||
// line options. This function will also set up logging properly.
|
||||
loadedConfig, err := lnd.LoadConfig(shutdownInterceptor)
|
||||
if err != nil {
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
@@ -85,7 +86,7 @@ func Start(extraArgs string, unlockerReady, rpcReady Callback) {
|
||||
// be executed in the case of a graceful shutdown.
|
||||
go func() {
|
||||
if err := lnd.Main(
|
||||
loadedConfig, cfg, signal.ShutdownChannel(),
|
||||
loadedConfig, cfg, shutdownInterceptor,
|
||||
); err != nil {
|
||||
if e, ok := err.(*flags.Error); ok &&
|
||||
e.Type == flags.ErrHelp {
|
||||
|
||||
Reference in new issue
Block a user