mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
cmd/dockerd: loadDaemonCliConfig() safeguard for unparsed flags
This function depends on flags having been parsed before it's used; add a safety-net in case this function would be called before that. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
0281f50efa
commit
fce7ebdaa5
2 changed files with 5 additions and 0 deletions
|
@ -384,6 +384,9 @@ func shutdownDaemon(d *daemon.Daemon) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
|
func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
|
||||||
|
if !opts.flags.Parsed() {
|
||||||
|
return nil, errors.New(`cannot load CLI config before flags are parsed`)
|
||||||
|
}
|
||||||
opts.setDefaultOptions()
|
opts.setDefaultOptions()
|
||||||
|
|
||||||
conf := opts.daemonConfig
|
conf := opts.daemonConfig
|
||||||
|
|
|
@ -22,6 +22,8 @@ func defaultOptions(t *testing.T, configFile string) *daemonOptions {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
opts.flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "")
|
opts.flags.StringVar(&opts.configFile, "config-file", defaultDaemonConfigFile, "")
|
||||||
opts.configFile = configFile
|
opts.configFile = configFile
|
||||||
|
err = opts.flags.Parse([]string{})
|
||||||
|
assert.NilError(t, err)
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue