diff --git a/cmd/cli/cli.go b/cmd/cli/cli.go index d5ca749..91ae1fa 100644 --- a/cmd/cli/cli.go +++ b/cmd/cli/cli.go @@ -802,6 +802,15 @@ func RunMobile(appConfig *AppConfig, appCallback *AppCallback, stopCh chan struc run(appCallback, stopCh) } +// CheckDeactivationPin checks if deactivation pin is valid +func CheckDeactivationPin(pin int64) int { + deactivationPin = pin + if err := checkDeactivationPin(nil); errors.Is(err, errInvalidDeactivationPin) { + return deactivationPinInvalidExitCode + } + return 0 +} + // run runs ctrld cli with given app callback and stop channel. func run(appCallback *AppCallback, stopCh chan struct{}) { if stopCh == nil { @@ -2090,7 +2099,12 @@ func checkDeactivationPin(s service.Service) error { mainLog.Load().Err(err).Msg("could not check deactivation pin") return err } - cc := newSocketControlClient(s, dir) + var cc *controlClient + if s == nil { + cc = newControlClient(filepath.Join(dir, ctrldControlUnixSock)) + } else { + cc = newSocketControlClient(s, dir) + } if cc == nil { return nil // ctrld is not running. } diff --git a/cmd/ctrld_library/main.go b/cmd/ctrld_library/main.go index 9bcc151..ec42b9c 100644 --- a/cmd/ctrld_library/main.go +++ b/cmd/ctrld_library/main.go @@ -61,13 +61,13 @@ func mapCallback(callback AppCallback) cli.AppCallback { } } -func (c *Controller) Stop() bool { - if c.stopCh != nil { +func (c *Controller) Stop(Pin int64) int { + errorCode := cli.CheckDeactivationPin(Pin) + if errorCode == 0 && c.stopCh != nil { close(c.stopCh) c.stopCh = nil - return true } - return false + return errorCode } func (c *Controller) IsRunning() bool {