mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
mobile: Move lndStarted check to the top of the Start function
This commit is contained in:
parent
5c5b91216a
commit
e1ebdb311a
@ -31,6 +31,15 @@ var lndStarted int32
|
||||
// current app directory in order to ensure lnd has the permissions needed to
|
||||
// write to it.
|
||||
func Start(extraArgs string, rpcReady Callback) {
|
||||
// We only support a single lnd instance at a time (singleton) for now,
|
||||
// so we make sure to return immediately if it has already been
|
||||
// started.
|
||||
if !atomic.CompareAndSwapInt32(&lndStarted, 0, 1) {
|
||||
err := errors.New("lnd already started")
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
}
|
||||
|
||||
// (Re-)initialize the in-mem gRPC listeners we're going to give to lnd.
|
||||
// This is required each time lnd is started, because when lnd shuts
|
||||
// down, the in-mem listeners are closed.
|
||||
@ -58,6 +67,7 @@ func Start(extraArgs string, rpcReady Callback) {
|
||||
// Hook interceptor for os signals.
|
||||
shutdownInterceptor, err := signal.Intercept()
|
||||
if err != nil {
|
||||
atomic.StoreInt32(&lndStarted, 0)
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
@ -67,6 +77,7 @@ func Start(extraArgs string, rpcReady Callback) {
|
||||
// line options. This function will also set up logging properly.
|
||||
loadedConfig, err := lnd.LoadConfig(shutdownInterceptor)
|
||||
if err != nil {
|
||||
atomic.StoreInt32(&lndStarted, 0)
|
||||
_, _ = fmt.Fprintln(os.Stderr, err)
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
@ -88,15 +99,6 @@ func Start(extraArgs string, rpcReady Callback) {
|
||||
},
|
||||
}
|
||||
|
||||
// We only support a single lnd instance at a time (singleton) for now,
|
||||
// so we make sure to return immediately if it has already been
|
||||
// started.
|
||||
if !atomic.CompareAndSwapInt32(&lndStarted, 0, 1) {
|
||||
err := errors.New("lnd already started")
|
||||
rpcReady.OnError(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Call the "real" main in a nested manner so the defers will properly
|
||||
// be executed in the case of a graceful shutdown.
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user