From 2a2d9539f08fde4436048ba449d50ce75f1f0624 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 18 May 2024 02:07:34 +0900 Subject: [PATCH] core: refuse invalid emergency actions for SuccessAction= and friends in user service manager Especially, soft-reboot is not supported by user service manager. Fixes a bug in 13ffc60749df0ca7c76cfcac317b41a05679b364 and 3cf848f6cd2151ccff89073bffb102f966d64ced. --- man/systemd.unit.xml | 5 ++--- src/core/emergency-action.c | 6 +++--- src/core/emergency-action.h | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index e7288e81ad..e19e8e1c40 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -1083,9 +1083,8 @@ , , , , , , and . In system mode, all options are - allowed. In user mode, only , , - , and are - allowed. Both options default to . + allowed. In user mode, only , , and + are allowed. Both options default to . If is set, no action will be triggered. causes a reboot following the normal shutdown procedure (i.e. equivalent to systemctl diff --git a/src/core/emergency-action.c b/src/core/emergency-action.c index 3083320966..dbda6e5457 100644 --- a/src/core/emergency-action.c +++ b/src/core/emergency-action.c @@ -14,14 +14,14 @@ static const char* const emergency_action_table[_EMERGENCY_ACTION_MAX] = { [EMERGENCY_ACTION_NONE] = "none", + [EMERGENCY_ACTION_EXIT] = "exit", + [EMERGENCY_ACTION_EXIT_FORCE] = "exit-force", [EMERGENCY_ACTION_REBOOT] = "reboot", [EMERGENCY_ACTION_REBOOT_FORCE] = "reboot-force", [EMERGENCY_ACTION_REBOOT_IMMEDIATE] = "reboot-immediate", [EMERGENCY_ACTION_POWEROFF] = "poweroff", [EMERGENCY_ACTION_POWEROFF_FORCE] = "poweroff-force", [EMERGENCY_ACTION_POWEROFF_IMMEDIATE] = "poweroff-immediate", - [EMERGENCY_ACTION_EXIT] = "exit", - [EMERGENCY_ACTION_EXIT_FORCE] = "exit-force", [EMERGENCY_ACTION_SOFT_REBOOT] = "soft-reboot", [EMERGENCY_ACTION_SOFT_REBOOT_FORCE] = "soft-reboot-force", [EMERGENCY_ACTION_KEXEC] = "kexec", @@ -216,7 +216,7 @@ int parse_emergency_action( if (x < 0) return -EINVAL; - if (runtime_scope != RUNTIME_SCOPE_SYSTEM && x != EMERGENCY_ACTION_NONE && x < _EMERGENCY_ACTION_FIRST_USER_ACTION) + if (runtime_scope != RUNTIME_SCOPE_SYSTEM && x > _EMERGENCY_ACTION_LAST_USER_ACTION) return -EOPNOTSUPP; *ret = x; diff --git a/src/core/emergency-action.h b/src/core/emergency-action.h index 33e0ec6ffc..6bec47511d 100644 --- a/src/core/emergency-action.h +++ b/src/core/emergency-action.h @@ -7,15 +7,15 @@ typedef enum EmergencyAction { EMERGENCY_ACTION_NONE, + EMERGENCY_ACTION_EXIT, + EMERGENCY_ACTION_EXIT_FORCE, + _EMERGENCY_ACTION_LAST_USER_ACTION = EMERGENCY_ACTION_EXIT_FORCE, EMERGENCY_ACTION_REBOOT, EMERGENCY_ACTION_REBOOT_FORCE, EMERGENCY_ACTION_REBOOT_IMMEDIATE, EMERGENCY_ACTION_POWEROFF, EMERGENCY_ACTION_POWEROFF_FORCE, EMERGENCY_ACTION_POWEROFF_IMMEDIATE, - EMERGENCY_ACTION_EXIT, - _EMERGENCY_ACTION_FIRST_USER_ACTION = EMERGENCY_ACTION_EXIT, - EMERGENCY_ACTION_EXIT_FORCE, EMERGENCY_ACTION_SOFT_REBOOT, EMERGENCY_ACTION_SOFT_REBOOT_FORCE, EMERGENCY_ACTION_KEXEC, -- 2.25.1