logind: add Halt() and CanHalt() APIs
This adds new method calls Halt() and CanHalt() to the logind bus APIs. They aren't overly useful (as the whole concept of halting isn't really too useful), however they clean up one major asymmetry: currently, using the "shutdown" legacy commands it is possibly to enqueue a "halt" operation through logind, while logind officially doesn't actually support this. Moreover, the path through "shutdown" currently ultimately fails, since the referenced "halt" action isn't actually defined in PolicyKit. Finally, the current logic results in an unexpected asymmetry in systemctl: "systemctl poweroff", "systemctl reboot" are currently asynchronous (due to the logind involvement) while "systemctl halt" isnt. Let's clean this up, and make all three APIs implemented by logind natively, and all three hence asynchronous in "systemctl". Moreover, let's add the missing PK action. Fixes: #6957
This commit is contained in:
@@ -3267,14 +3267,19 @@ static int logind_reboot(enum action a) {
|
||||
|
||||
switch (a) {
|
||||
|
||||
case ACTION_POWEROFF:
|
||||
method = "PowerOff";
|
||||
description = "power off system";
|
||||
break;
|
||||
|
||||
case ACTION_REBOOT:
|
||||
method = "Reboot";
|
||||
description = "reboot system";
|
||||
break;
|
||||
|
||||
case ACTION_POWEROFF:
|
||||
method = "PowerOff";
|
||||
description = "power off system";
|
||||
case ACTION_HALT:
|
||||
method = "Halt";
|
||||
description = "halt system";
|
||||
break;
|
||||
|
||||
case ACTION_SUSPEND:
|
||||
@@ -3568,6 +3573,7 @@ static int start_special(int argc, char *argv[], void *userdata) {
|
||||
if (IN_SET(a,
|
||||
ACTION_POWEROFF,
|
||||
ACTION_REBOOT,
|
||||
ACTION_HALT,
|
||||
ACTION_SUSPEND,
|
||||
ACTION_HIBERNATE,
|
||||
ACTION_HYBRID_SLEEP)) {
|
||||
@@ -8503,7 +8509,7 @@ static int halt_main(void) {
|
||||
/* Try logind if we are a normal user and no special
|
||||
* mode applies. Maybe PolicyKit allows us to shutdown
|
||||
* the machine. */
|
||||
if (IN_SET(arg_action, ACTION_POWEROFF, ACTION_REBOOT)) {
|
||||
if (IN_SET(arg_action, ACTION_POWEROFF, ACTION_REBOOT, ACTION_HALT)) {
|
||||
r = logind_reboot(arg_action);
|
||||
if (r >= 0)
|
||||
return r;
|
||||
|
||||
Reference in New Issue
Block a user