Skip to content
Snippets Groups Projects
Commit 0c879c41 authored by Zygmunt Krynicki's avatar Zygmunt Krynicki
Browse files

boot/piboot: allow returning error from visitSections


We want to be able to traverse sections and make local decisions,
including that of failure, and having visitSections support an error
value is the easiest way to do that.

Signed-off-by: default avatarZygmunt Krynicki <zygmunt.krynicki@huawei.com>
parent bae96628
No related branches found
No related tags found
No related merge requests found
...@@ -148,7 +148,7 @@ func (pi *PiBoot) QueryActive() (slot boot.Slot, err error) { ...@@ -148,7 +148,7 @@ func (pi *PiBoot) QueryActive() (slot boot.Slot, err error) {
// Find the configured kernel and kernel cmdline // Find the configured kernel and kernel cmdline
var kernel, initramfs, cmdline string var kernel, initramfs, cmdline string
err = visitSections(&configTxt, pi.FilterPredicate, func(sect *picfg.Section) { err = visitSections(&configTxt, pi.FilterPredicate, func(sect *picfg.Section) error {
for _, param := range sect.Parameters { for _, param := range sect.Parameters {
switch param.Name { switch param.Name {
case kernelParameter: case kernelParameter:
...@@ -159,6 +159,7 @@ func (pi *PiBoot) QueryActive() (slot boot.Slot, err error) { ...@@ -159,6 +159,7 @@ func (pi *PiBoot) QueryActive() (slot boot.Slot, err error) {
cmdline = param.Value cmdline = param.Value
} }
} }
return nil
}) })
if err != nil { if err != nil {
return boot.InvalidSlot, &UnknownActiveSlotError{Err: err} return boot.InvalidSlot, &UnknownActiveSlotError{Err: err}
...@@ -218,7 +219,7 @@ func (pi *PiBoot) TrySwitch(to boot.Slot) (err error) { ...@@ -218,7 +219,7 @@ func (pi *PiBoot) TrySwitch(to boot.Slot) (err error) {
} }
// Find the values to modify, swapping A and B around // Find the values to modify, swapping A and B around
err = visitSections(&configTxt, pi.FilterPredicate, func(sect *picfg.Section) { err = visitSections(&configTxt, pi.FilterPredicate, func(sect *picfg.Section) error {
for paramIdx, param := range sect.Parameters { for paramIdx, param := range sect.Parameters {
switch param.Name { switch param.Name {
case kernelParameter, cmdlineParameter, initramfsParameter: case kernelParameter, cmdlineParameter, initramfsParameter:
...@@ -236,6 +237,7 @@ func (pi *PiBoot) TrySwitch(to boot.Slot) (err error) { ...@@ -236,6 +237,7 @@ func (pi *PiBoot) TrySwitch(to boot.Slot) (err error) {
sect.Parameters[paramIdx].Value = strings.Replace(param.Value, oldPrefix, newPrefix, -1) sect.Parameters[paramIdx].Value = strings.Replace(param.Value, oldPrefix, newPrefix, -1)
} }
} }
return nil
}) })
if err != nil { if err != nil {
return err return err
...@@ -296,7 +298,7 @@ func (pi *PiBoot) CancelSwitch() error { ...@@ -296,7 +298,7 @@ func (pi *PiBoot) CancelSwitch() error {
// An optional predicate function may be used to visit only matching sections. // An optional predicate function may be used to visit only matching sections.
// The predicate is called with the effective fiters that are in effect at each // The predicate is called with the effective fiters that are in effect at each
// phase of the traversal process. Sections can be mutated by the visitor. // phase of the traversal process. Sections can be mutated by the visitor.
func visitSections(configTxt *picfg.ConfigTxt, pred func([]condfilter.ConditionalFilter) bool, visitor func(sect *picfg.Section)) error { func visitSections(configTxt *picfg.ConfigTxt, pred func([]condfilter.ConditionalFilter) bool, visitor func(sect *picfg.Section) error) error {
var tracker condfilter.StateTracker var tracker condfilter.StateTracker
for _, sect := range *configTxt { for _, sect := range *configTxt {
...@@ -313,7 +315,9 @@ func visitSections(configTxt *picfg.ConfigTxt, pred func([]condfilter.Conditiona ...@@ -313,7 +315,9 @@ func visitSections(configTxt *picfg.ConfigTxt, pred func([]condfilter.Conditiona
} }
} }
visitor(&sect) if err := visitor(&sect); err != nil {
return err
}
} }
return nil return nil
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment