cmd/cli: re-fetch pin code during deactivation checking

So if the pin code was updated/removed, it will be checked correctly by
ctrld during stop/uninstall commands.
This commit is contained in:
Cuong Manh Le
2024-11-08 18:30:48 +07:00
committed by Cuong Manh Le
parent 2875e22d0b
commit 47a90ec2a1
4 changed files with 35 additions and 12 deletions
+8 -3
View File
@@ -22,6 +22,7 @@ import (
"sort"
"strconv"
"strings"
"sync/atomic"
"time"
"github.com/Masterminds/semver"
@@ -1552,11 +1553,15 @@ func processNoConfigFlags(noConfigStart bool) {
const defaultDeactivationPin = -1
// cdDeactivationPin is used in cd mode to decide whether stop and uninstall commands can be run.
var cdDeactivationPin int64 = defaultDeactivationPin
var cdDeactivationPin atomic.Int64
func init() {
cdDeactivationPin.Store(defaultDeactivationPin)
}
// deactivationPinNotSet reports whether cdDeactivationPin was not set by processCDFlags.
func deactivationPinNotSet() bool {
return cdDeactivationPin == defaultDeactivationPin
return cdDeactivationPin.Load() == defaultDeactivationPin
}
func processCDFlags(cfg *ctrld.Config) error {
@@ -1585,7 +1590,7 @@ func processCDFlags(cfg *ctrld.Config) error {
if resolverConfig.DeactivationPin != nil {
logger.Debug().Msg("saving deactivation pin")
cdDeactivationPin = *resolverConfig.DeactivationPin
cdDeactivationPin.Store(*resolverConfig.DeactivationPin)
}
logger.Info().Msg("generating ctrld config from Control-D configuration")