-
- multiple_sessions = r > 0;
- inhibit = manager_is_inhibited(m, INHIBIT_SHUTDOWN, NULL);
-
- if (multiple_sessions) {
- action = streq(dbus_message_get_member(message), "PowerOff") ?
- "org.freedesktop.login1.power-off-multiple-sessions" :
- "org.freedesktop.login1.reboot-multiple-sessions";
-
- r = verify_polkit(connection, message, action, interactive, NULL, &error);
- if (r < 0)
- return bus_send_error_reply(connection, message, &error, r);
- }
-
- if (inhibit) {
- action = streq(dbus_message_get_member(message), "PowerOff") ?
- "org.freedesktop.login1.power-off-ignore-inhibit" :
- "org.freedesktop.login1.reboot-ignore-inhibit";
-
- r = verify_polkit(connection, message, action, interactive, NULL, &error);
- if (r < 0)
- return bus_send_error_reply(connection, message, &error, r);
- }
-
- if (!multiple_sessions && !inhibit) {
- action = streq(dbus_message_get_member(message), "PowerOff") ?
- "org.freedesktop.login1.power-off" :
- "org.freedesktop.login1.reboot";
-
- r = verify_polkit(connection, message, action, interactive, NULL, &error);
- if (r < 0)
- return bus_send_error_reply(connection, message, &error, r);
- }
-
- forward = dbus_message_new_method_call(
- "org.freedesktop.systemd1",
- "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager",
- "StartUnit");
- if (!forward)
- return bus_send_error_reply(connection, message, NULL, -ENOMEM);
-
- name = streq(dbus_message_get_member(message), "PowerOff") ?
- SPECIAL_POWEROFF_TARGET : SPECIAL_REBOOT_TARGET;
-
- if (!dbus_message_append_args(forward,
- DBUS_TYPE_STRING, &name,
- DBUS_TYPE_STRING, &mode,
- DBUS_TYPE_INVALID)) {
- dbus_message_unref(forward);
- return bus_send_error_reply(connection, message, NULL, -ENOMEM);
- }
-
- freply = dbus_connection_send_with_reply_and_block(connection, forward, -1, &error);
- dbus_message_unref(forward);
-
- if (!freply)
- return bus_send_error_reply(connection, message, &error, -EIO);
-
- dbus_message_unref(freply);
-
- reply = dbus_message_new_method_return(message);
- if (!reply)
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CanPowerOff") ||
- dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "CanReboot")) {
-
- bool multiple_sessions, challenge, inhibit, b;
- const char *action, *result;
-
- r = have_multiple_sessions(connection, m, message, &error);