CHROMIUM: power: Check for imminent suspend before writing/erasing
Flashrom normally creates a lock file to stop powerd from suspending the
system during write/erase ops, however this leaves the possibility of a
race condition where:
1. powerd starts preparing to suspend and stops checking for lock files
2. flashrom starts before processes have been frozen
3. flashrom creates a lock file & starts writing
4. powerd freezes processes and interrupts the write
To mitigate this, make flashrom abort before starting write/erase ops if
powerd has created a suspend_announced file.
Note: the stat() and stat64() mocks in tests.c have been updated to
return 1 in order to mock a system state where the suspend announced
file does not exist. In future, these mocks may need to be updated with
proper IO handlers, i.e. dispatch to a `get_io()->iom_stat` function.
BUG=b:308833364
BRANCH=none
TEST=manually created /run/power_manager/power/suspend_announced file \
and checked that `flashrom -E` aborted
TEST=ninja test
Change-Id: I79b4b38a6339ff23287ce8066365f675afa721cb
Signed-off-by: Nikolai Artemiev <nartemiev@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/5065230
Commit-Queue: ChromeOS Auto Retry <chromeos-auto-retry@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
5 files changed