- assert(bus);
-
- r = check_inhibitors(bus, "poweroff", "shutdown");
- if (r < 0)
- return r;
-
- polkit_agent_open_if_enabled();
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "PowerOff",
- &error,
- NULL,
- "b", arg_ask_password);
- if (r < 0)
- log_error("Failed to power off: %s", bus_error_message(&error, r));
-
- return r;
-}
-
-static int reboot(int argc, char *argv[], void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- sd_bus *bus = userdata;
- int r;
-
- assert(bus);
-
- r = check_inhibitors(bus, "reboot", "shutdown");
- if (r < 0)
- return r;
-
- polkit_agent_open_if_enabled();
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Reboot",
- &error,
- NULL,
- "b", arg_ask_password);
- if (r < 0)
- log_error("Failed to reboot: %s", bus_error_message(&error, r));
-
- return r;
-}
-
-static int suspend(int argc, char *argv[], void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- sd_bus *bus = userdata;
- int r;
-
- assert(bus);
-
- r = check_inhibitors(bus, "suspend", "sleep");
- if (r < 0)
- return r;
-
- polkit_agent_open_if_enabled();
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Suspend",
- &error,
- NULL,
- "b", arg_ask_password);
- if (r < 0)
- log_error("Failed to suspend: %s", bus_error_message(&error, r));
-
- return r;
-}
-
-static int hibernate(int argc, char *argv[], void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- sd_bus *bus = userdata;
- int r;
-
- assert(bus);
-
- r = check_inhibitors(bus, "hibernate", "sleep");
- if (r < 0)
- return r;
-
- polkit_agent_open_if_enabled();
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "Hibernate",
- &error,
- NULL,
- "b", arg_ask_password);
- if (r < 0)
- log_error("Failed to hibernate: %s", bus_error_message(&error, r));
-
- return r;
-}
-
-static int hybrid_sleep(int argc, char *argv[], void *userdata) {
- _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
- _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
- sd_bus *bus = userdata;
- int r;