From: Mike Yuan Date: Wed, 8 May 2024 05:41:05 +0000 (+0800) Subject: systemctl: do not fall back to StartUnit automatically for sleep operations X-Git-Tag: v256-rc2~74^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F32705%2Fhead;p=thirdparty%2Fsystemd.git systemctl: do not fall back to StartUnit automatically for sleep operations In the majority of cases, this is caused by sleep_supported() returning error. Hence it's very likely that it would fail again, so the fallback is not really useful. Instead, honor the --force option for these verbs. --- diff --git a/man/systemctl.xml b/man/systemctl.xml index 287decffb21..def2f8e0111 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -1843,6 +1843,10 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err Suspend the system. This will trigger activation of the special target unit suspend.target. This command is asynchronous, and will return after the suspend operation is successfully enqueued. It will not wait for the suspend/resume cycle to complete. + + If is specified, and systemd-logind returned + error for the operation, the error will be ignored and the operation will be tried again directly + through starting the target unit. @@ -1853,6 +1857,8 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err Hibernate the system. This will trigger activation of the special target unit hibernate.target. This command is asynchronous, and will return after the hibernation operation is successfully enqueued. It will not wait for the hibernate/thaw cycle to complete. + + This command honors in the same way as suspend. @@ -1864,6 +1870,8 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err hybrid-sleep.target. This command is asynchronous, and will return after the hybrid sleep operation is successfully enqueued. It will not wait for the sleep/wake-up cycle to complete. + This command honors in the same way as suspend. + @@ -1872,12 +1880,15 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err suspend-then-hibernate - Suspend the system and hibernate it after the delay specified in systemd-sleep.conf. - This will trigger activation of the special target unit suspend-then-hibernate.target. - This command is asynchronous, and will return after the hybrid sleep operation is successfully enqueued. + Suspend the system and hibernate it when the battery is low, or when the delay specified + in systemd-sleep.conf elapsed. This will trigger activation of the special + target unit suspend-then-hibernate.target. This command is asynchronous, + and will return after the hybrid sleep operation is successfully enqueued. It will not wait for the sleep/wake-up or hibernate/thaw cycle to complete. - + This command honors in the same way as suspend. + + @@ -2531,25 +2542,27 @@ Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output err - When used with enable, overwrite - any existing conflicting symlinks. + When used with enable, overwrite any existing conflicting symlinks. + + When used with edit, create all of the specified units which do not already exist. - When used with edit, create all of the - specified units which do not already exist. + When used with suspend, hibernate, hybrid-sleep, + or suspend-then-hibernate, the error returned by systemd-logind + will be ignored, and the operation will be performed directly through starting the corresponding units. + - When used with halt, poweroff, reboot or - kexec, execute the selected operation without shutting down all units. However, all - processes will be killed forcibly and all file systems are unmounted or remounted read-only. This is hence a - drastic but relatively safe option to request an immediate reboot. If is specified - twice for these operations (with the exception of kexec), they will be executed - immediately, without terminating any processes or unmounting any file systems. + When used with halt, poweroff, reboot, + or kexec, execute the selected operation without shutting down all units. However, + all processes will be killed forcibly and all file systems are unmounted or remounted read-only. + This is hence a drastic but relatively safe option to request an immediate reboot. If + is specified twice for these operations (with the exception of kexec), they will + be executed immediately, without terminating any processes or unmounting any file systems. - Specifying - twice with any of these operations might result in data loss. Note that when - is specified twice the selected operation is executed by - systemctl itself, and the system manager is not contacted. This means the command should - succeed even when the system manager has crashed. + Specifying twice with any of these operations might result in data loss. + Note that when is specified twice the selected operation is executed by + systemctl itself, and the system manager is not contacted. This means the command + should succeed even when the system manager has crashed. diff --git a/src/systemctl/systemctl-start-special.c b/src/systemctl/systemctl-start-special.c index 4b99d0c6294..95cf00fc81b 100644 --- a/src/systemctl/systemctl-start-special.c +++ b/src/systemctl/systemctl-start-special.c @@ -223,8 +223,11 @@ int verb_start_special(int argc, char *argv[], void *userdata) { case ACTION_HYBRID_SLEEP: case ACTION_SUSPEND_THEN_HIBERNATE: + /* For sleep operations, do not automatically fall back to low-level operation for + * errors other than logind not available. There's a high chance that logind did + * some extra sanity check and that didn't pass. */ r = logind_reboot(a); - if (r >= 0 || IN_SET(r, -EACCES, -EOPNOTSUPP, -EINPROGRESS)) + if (r >= 0 || (r != -ENOSYS && arg_force == 0)) return r; arg_no_block = true;