Skip to content

Commit

Permalink
cmd/ctrld: only write to config file if listener config changed
Browse files Browse the repository at this point in the history
Updates #149
  • Loading branch information
cuonglm committed Aug 29, 2023
1 parent 7ce62cc commit f39512b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,18 @@ func initCLI() {
processCDFlags()
}

updateListenerConfig()
updated := updateListenerConfig()

if cdUID != "" {
processLogAndCacheFlags()
}

if err := writeConfigFile(); err != nil {
mainLog.Load().Fatal().Err(err).Msg("failed to write config file")
} else {
mainLog.Load().Info().Msg("writing config file to: " + defaultConfigFile)
if updated {
if err := writeConfigFile(); err != nil {
mainLog.Load().Fatal().Err(err).Msg("failed to write config file")
} else {
mainLog.Load().Info().Msg("writing config file to: " + defaultConfigFile)
}
}

if newLogPath := cfg.Service.LogPath; newLogPath != "" && oldLogPath != newLogPath {
Expand Down Expand Up @@ -1412,8 +1414,8 @@ type listenerConfigCheck struct {

// updateListenerConfig updates the config for listeners if not defined,
// or defined but invalid to be used, e.g: using loopback address other
// than 127.0.0.1 with sytemd-resolved.
func updateListenerConfig() {
// than 127.0.0.1 with systemd-resolved.
func updateListenerConfig() (updated bool) {
lcc := make(map[string]*listenerConfigCheck)
cdMode := cdUID != ""
for n, listener := range cfg.Listener {
Expand All @@ -1431,6 +1433,7 @@ func updateListenerConfig() {
lcc[n].IP = true
lcc[n].Port = true
}
updated = updated || lcc[n].IP || lcc[n].Port
}

var closers []io.Closer
Expand Down Expand Up @@ -1603,6 +1606,7 @@ func updateListenerConfig() {
}
}
}
return
}

func dirWritable(dir string) (bool, error) {
Expand Down

0 comments on commit f39512b

Please sign in to comment.