Always unmount the config partition in get-recore-serial-number - #100
Merged
Conversation
set -euo pipefail means a missing serial_number file (a board that hasn't been provisioned yet - exactly the case this script exists to detect) makes cat fail and the script exit before reaching unmount-config, leaving the mount - and its transient systemd unit - dangling. That stale mount can then make a later mount-config call fail with "Unit mnt-config.mount was already loaded". Use a trap so the unmount always runs once the mount has succeeded, regardless of how the read afterward turns out. Live-tested on real hardware: deleted serial_number, confirmed the script now fails cleanly (exit 1, no stale mount) instead of leaving /mnt/config mounted, then restored the serial number via create-recore-config and confirmed the whole flow still works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
set -euo pipefailmeans a missingserial_numberfile (a board that hasn't been provisioned yet - exactly the case this script exists to detect) makescatfail and the script exit before reachingunmount-config, leaving the mount - and its transient systemd unit - dangling. That stale mount can then make a latermount-configcall fail withUnit mnt-config.mount was already loaded.Use a
trapso the unmount always runs once the mount has succeeded, regardless of how the read afterward turns out.Testing
make test-bats- added a regression test assertingunmount-configis still called whenserial_numberis missing.serial_number, confirmed the script now fails cleanly (exit 1, no stale/mnt/configmount) instead of leaving it mounted, then restored the serial number viacreate-recore-configand confirmed the whole flow (including the UI popup) still works.Found while testing #83/#85.