+static int elogind_cancel_shutdown(sd_bus *bus, enum action a) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ int r;
+ static const char *table[_ACTION_MAX] = {
+ [ACTION_REBOOT] = "The system reboot has been cancelled!",
+ [ACTION_POWEROFF] = "The system shutdown has been cancelled!"
+ };
+
+ r = logind_set_wall_message(bus, table[a]);
+
+ if (r < 0) {
+ log_warning_errno(r, "Failed to set wall message, ignoring: %s",
+ bus_error_message(&error, r));
+ sd_bus_error_free(&error);
+ }
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "CancelScheduledShutdown",
+ &error,
+ NULL, NULL);
+ if (r < 0)
+ return log_warning_errno(r, "Failed to talk to logind, shutdown hasn't been cancelled: %s", bus_error_message(&error, r));
+
+ return 0;
+}
+
+static int elogind_schedule_shutdown(sd_bus *bus, enum action a) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+ const char *method = NULL;
+ char date[FORMAT_TIMESTAMP_MAX];
+ char sched_wall[128] = { 0x0 };
+ int r;
+
+ if (!bus)
+ return -EIO;
+
+ polkit_agent_open_if_enabled();
+
+ switch (a) {
+
+ case ACTION_POWEROFF:
+ method = "poweroff";
+ break;
+
+ case ACTION_REBOOT:
+ method = "reboot";
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ xsprintf(sched_wall,
+ "%s scheduled for %s, use 'loginctl -c' to cancel.",
+ ACTION_POWEROFF == a ? "Shutdown" : "Reboot",
+ format_timestamp(date, sizeof(date), arg_when));
+ r = logind_set_wall_message(bus, sched_wall);
+
+ if (r < 0) {
+ log_warning_errno(r, "Failed to set wall message, ignoring: %s",
+ bus_error_message(&error, r));
+ sd_bus_error_free(&error);
+ }
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "ScheduleShutdown",
+ &error,
+ NULL,
+ "st",
+ method,
+ arg_when);
+
+ if (r < 0)
+ log_error("Failed to execute operation: %s", bus_error_message(&error, r));
+
+ return r;
+}
+