mirror of
https://github.com/systemd/systemd.git
synced 2025-03-13 00:58:27 +03:00
hibernate-resume-generator: don't initiate resume if soft-rebooted
This is just paranoia, to ensure that we don't accidentally initiate resume if the initrd is entered through soft-reboot rather than the initial one for booting up.
This commit is contained in:
parent
1cfe9737cf
commit
70ae9dc4f6
@ -107,6 +107,11 @@ static int run(const char *dest, const char *dest_early, const char *dest_late)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (generator_soft_rebooted()) {
|
||||
log_debug("Running in an initrd entered through soft-reboot, not initiating resume.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "macro.h"
|
||||
#include "mkdir-label.h"
|
||||
#include "mountpoint-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "path-util.h"
|
||||
#include "process-util.h"
|
||||
#include "special.h"
|
||||
@ -974,3 +975,25 @@ void log_setup_generator(void) {
|
||||
log_parse_environment();
|
||||
log_open();
|
||||
}
|
||||
|
||||
bool generator_soft_rebooted(void) {
|
||||
static int cached = -1;
|
||||
int r;
|
||||
|
||||
if (cached >= 0)
|
||||
return cached;
|
||||
|
||||
const char *e = secure_getenv("SYSTEMD_SOFT_REBOOTS_COUNT");
|
||||
if (!e)
|
||||
return (cached = false);
|
||||
|
||||
unsigned u;
|
||||
|
||||
r = safe_atou(e, &u);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to parse $SYSTEMD_SOFT_REBOOTS_COUNT, assuming the system hasn't soft-rebooted: %m");
|
||||
return (cached = false);
|
||||
}
|
||||
|
||||
return (cached = u > 0);
|
||||
}
|
||||
|
@ -100,6 +100,8 @@ int generator_enable_remount_fs_service(const char *dir);
|
||||
|
||||
void log_setup_generator(void);
|
||||
|
||||
bool generator_soft_rebooted(void);
|
||||
|
||||
/* Similar to DEFINE_MAIN_FUNCTION, but initializes logging and assigns positional arguments. */
|
||||
#define DEFINE_MAIN_GENERATOR_FUNCTION(impl) \
|
||||
_DEFINE_MAIN_FUNCTION( \
|
||||
|
Loading…
x
Reference in New Issue
Block a user