1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-03 17:47:28 +03:00

Merge pull request #29440 from evelikov/more-auto-entries

sd-boot: add auto-reboot and auto-poweroff entries
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2023-10-06 18:54:03 +02:00 committed by GitHub
commit faa6964fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 14 deletions

View File

@ -100,6 +100,14 @@
<entry>auto-osx</entry>
<entry>macOS</entry>
</row>
<row>
<entry>auto-poweroff</entry>
<entry>Power Off The System</entry>
</row>
<row>
<entry>auto-reboot</entry>
<entry>Reboot The System</entry>
</row>
<row>
<entry>auto-reboot-to-firmware-setup</entry>
<entry>Reboot Into Firmware Interface</entry>

View File

@ -86,6 +86,8 @@ typedef struct {
bool editor;
bool auto_entries;
bool auto_firmware;
bool auto_poweroff;
bool auto_reboot;
bool reboot_for_bitlocker;
secure_boot_enroll secure_boot_enroll;
bool force_menu;
@ -512,6 +514,8 @@ static void print_status(Config *config, char16_t *loaded_image_path) {
printf(" editor: %ls\n", yes_no(config->editor));
printf(" auto-entries: %ls\n", yes_no(config->auto_entries));
printf(" auto-firmware: %ls\n", yes_no(config->auto_firmware));
printf(" auto-poweroff: %ls\n", yes_no(config->auto_poweroff));
printf(" auto-reboot: %ls\n", yes_no(config->auto_reboot));
printf(" beep: %ls\n", yes_no(config->beep));
printf(" reboot-for-bitlocker: %ls\n", yes_no(config->reboot_for_bitlocker));
@ -618,6 +622,16 @@ static EFI_STATUS reboot_into_firmware(void) {
assert_not_reached();
}
static EFI_STATUS poweroff_system(void) {
RT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
assert_not_reached();
}
static EFI_STATUS reboot_system(void) {
RT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
assert_not_reached();
}
static bool menu_run(
Config *config,
ConfigEntry **chosen_entry,
@ -825,7 +839,7 @@ static bool menu_run(
if (firmware_setup) {
firmware_setup = false;
if (IN_SET(key, KEYPRESS(0, 0, '\r'), KEYPRESS(0, 0, '\n')))
reboot_into_firmware();
(void) reboot_into_firmware();
continue;
}
@ -886,7 +900,9 @@ static bool menu_run(
case KEYPRESS(0, 0, 'H'):
case KEYPRESS(0, 0, '?'):
/* This must stay below 80 characters! Q/v/Ctrl+l/f deliberately not advertised. */
status = xstrdup16(u"(d)efault (t/T)imeout (e)dit (r/R)esolution (p)rint (O)ff re(B)oot (h)elp");
status = xasprintf("(d)efault (t/T)imeout (e)dit (r/R)esolution (p)rint %s%s(h)elp",
config->auto_poweroff ? "" : "(O)ff ",
config->auto_reboot ? "" : "re(B)oot ");
break;
case KEYPRESS(0, 0, 'Q'):
@ -1019,11 +1035,11 @@ static bool menu_run(
break;
case KEYPRESS(0, 0, 'O'): /* Only uppercase, so that it can't be hit so easily fat-fingered, but still works safely over serial */
RT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
(void) poweroff_system();
break;
case KEYPRESS(0, 0, 'B'): /* ditto */
RT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
(void) reboot_system();
break;
default:
@ -1217,7 +1233,8 @@ static void config_defaults_load_from_file(Config *config, char *content) {
else {
uint64_t u;
if (!parse_number8(value, &u, NULL) || u > TIMEOUT_TYPE_MAX) {
log_error("Error parsing 'timeout' config option: %s", value);
log_error("Error parsing 'timeout' config option, ignoring: %s",
value);
continue;
}
config->timeout_sec_config = u;
@ -1228,7 +1245,7 @@ static void config_defaults_load_from_file(Config *config, char *content) {
if (streq8(key, "default")) {
if (value[0] == '@' && !strcaseeq8(value, "@saved")) {
log_error("Unsupported special entry identifier: %s", value);
log_error("Unsupported special entry identifier, ignoring: %s", value);
continue;
}
free(config->entry_default_config);
@ -1239,35 +1256,50 @@ static void config_defaults_load_from_file(Config *config, char *content) {
if (streq8(key, "editor")) {
err = parse_boolean(value, &config->editor);
if (err != EFI_SUCCESS)
log_error("Error parsing 'editor' config option: %s", value);
log_error("Error parsing 'editor' config option, ignoring: %s", value);
continue;
}
if (streq8(key, "auto-entries")) {
err = parse_boolean(value, &config->auto_entries);
if (err != EFI_SUCCESS)
log_error("Error parsing 'auto-entries' config option: %s", value);
log_error("Error parsing 'auto-entries' config option, ignoring: %s", value);
continue;
}
if (streq8(key, "auto-firmware")) {
err = parse_boolean(value, &config->auto_firmware);
if (err != EFI_SUCCESS)
log_error("Error parsing 'auto-firmware' config option: %s", value);
log_error("Error parsing 'auto-firmware' config option, ignoring: %s", value);
continue;
}
if (streq8(key, "auto-poweroff")) {
err = parse_boolean(value, &config->auto_poweroff);
if (err != EFI_SUCCESS)
log_error("Error parsing 'auto-poweroff' config option, ignoring: %s", value);
continue;
}
if (streq8(key, "auto-reboot")) {
err = parse_boolean(value, &config->auto_reboot);
if (err != EFI_SUCCESS)
log_error("Error parsing 'auto-reboot' config option, ignoring: %s", value);
continue;
}
if (streq8(key, "beep")) {
err = parse_boolean(value, &config->beep);
if (err != EFI_SUCCESS)
log_error("Error parsing 'beep' config option: %s", value);
log_error("Error parsing 'beep' config option, ignoring: %s", value);
continue;
}
if (streq8(key, "reboot-for-bitlocker")) {
err = parse_boolean(value, &config->reboot_for_bitlocker);
if (err != EFI_SUCCESS)
log_error("Error parsing 'reboot-for-bitlocker' config option: %s", value);
log_error("Error parsing 'reboot-for-bitlocker' config option, ignoring: %s",
value);
}
if (streq8(key, "secure-boot-enroll")) {
@ -1280,7 +1312,8 @@ static void config_defaults_load_from_file(Config *config, char *content) {
else if (streq8(value, "off"))
config->secure_boot_enroll = ENROLL_OFF;
else
log_error("Error parsing 'secure-boot-enroll' config option: %s", value);
log_error("Error parsing 'secure-boot-enroll' config option, ignoring: %s",
value);
continue;
}
@ -1294,7 +1327,8 @@ static void config_defaults_load_from_file(Config *config, char *content) {
else {
uint64_t u;
if (!parse_number8(value, &u, NULL) || u > CONSOLE_MODE_RANGE_MAX) {
log_error("Error parsing 'console-mode' config option: %s", value);
log_error("Error parsing 'console-mode' config option, ignoring: %s",
value);
continue;
}
config->console_mode = u;
@ -1596,7 +1630,6 @@ static void config_load_defaults(Config *config, EFI_FILE *root_dir) {
.editor = true,
.auto_entries = true,
.auto_firmware = true,
.reboot_for_bitlocker = false,
.secure_boot_enroll = ENROLL_IF_SAFE,
.idx_default_efivar = IDX_INVALID,
.console_mode = CONSOLE_MODE_KEEP,
@ -2645,6 +2678,30 @@ static void config_load_all_entries(
config_add_entry(config, entry);
}
if (config->auto_poweroff) {
ConfigEntry *entry = xnew(ConfigEntry, 1);
*entry = (ConfigEntry) {
.id = xstrdup16(u"auto-poweroff"),
.title = xstrdup16(u"Power Off The System"),
.call = poweroff_system,
.tries_done = -1,
.tries_left = -1,
};
config_add_entry(config, entry);
}
if (config->auto_reboot) {
ConfigEntry *entry = xnew(ConfigEntry, 1);
*entry = (ConfigEntry) {
.id = xstrdup16(u"auto-reboot"),
.title = xstrdup16(u"Reboot The System"),
.call = reboot_system,
.tries_done = -1,
.tries_left = -1,
};
config_add_entry(config, entry);
}
/* find if secure boot signing keys exist and autoload them if necessary
otherwise creates menu entries so that the user can load them manually
if the secure-boot-enroll variable is set to no (the default), we do not

View File

@ -1145,6 +1145,8 @@ int boot_config_augment_from_loader(
"auto-windows", "Windows Boot Manager",
"auto-efi-shell", "EFI Shell",
"auto-efi-default", "EFI Default Loader",
"auto-poweroff", "Power Off The System",
"auto-reboot", "Reboot The System",
"auto-reboot-to-firmware-setup", "Reboot Into Firmware Interface",
NULL,
};