hibernate-resume: split out the logic of finding hibernate location
authorMike Yuan <me@yhndnzj.com>
Tue, 5 Sep 2023 13:50:04 +0000 (21:50 +0800)
committerMike Yuan <me@yhndnzj.com>
Thu, 7 Sep 2023 12:21:16 +0000 (20:21 +0800)
commita628d933cc67cc8b183dc809ba1451aa5b2996e5
tree4440309c1b40d99372a6dffcded8f680e4f541f7
parent82b7bf8c1c8c6ded6f56b43998c803843a3b944b
hibernate-resume: split out the logic of finding hibernate location

Before this commit, the hibernate location logic only exists in
the generator. Also, we compare device nodes (devnode_same()) and
clear EFI variable HibernateLocation in the generator too. This is
not ideal though: when the generator gets to run, udev hasn't yet
started, so effectively devnode_same() always fails. Moreover, if
the boot process is interrupted by e.g. battery-check, the hibernate
information is lost.

Therefore, let's split out the logic of finding hibernate location.
The generator only does the initial validation of system info and
enables systemd-hibernate-resume.service, and when the service
actually runs we validate everything again, which includes comparing
the device nodes and clearing the EFI variable. This should make
things more robust, plus systems that don't utilize a systemd-enabled
initrd can use the exact same logic to resume using the EFI variable.
I.e., systemd-hibernate-resume can be used standalone.
src/hibernate-resume/hibernate-resume-config.c [new file with mode: 0644]
src/hibernate-resume/hibernate-resume-config.h [new file with mode: 0644]
src/hibernate-resume/hibernate-resume-generator.c
src/hibernate-resume/hibernate-resume.c
src/hibernate-resume/meson.build
units/meson.build
units/systemd-hibernate-resume.service.in [new file with mode: 0644]