_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
int r;
+ r = elogind_set_wall_message(bus, NULL);
+
+ 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",
}
static void elogind_log_special(enum elogind_action a) {
+#ifdef ENABLE_DEBUG_ELOGIND
switch (a) {
case ACTION_HALT:
log_struct(LOG_INFO,
LOG_MESSAGE("Hibernate action called."),
LOG_MESSAGE_ID(SD_MESSAGE_SLEEP_START),
NULL);
+ break;
case ACTION_HYBRID_SLEEP:
log_struct(LOG_INFO,
LOG_MESSAGE("Hybrid-Sleep action called."),
LOG_MESSAGE_ID(SD_MESSAGE_SLEEP_START),
NULL);
+ break;
case ACTION_CANCEL_SHUTDOWN:
log_struct(LOG_INFO,
LOG_MESSAGE("Cancel Shutdown called."),
default:
break;
}
+#endif // ENABLE_DEBUG_ELOGIND
}
static int elogind_reboot(sd_bus *bus, enum elogind_action a) {
if (!bus)
return -EIO;
- polkit_agent_open_if_enabled();
-
switch (a) {
case ACTION_POWEROFF:
return -EINVAL;
}
- r = elogind_set_wall_message(bus, table[a]);
+ polkit_agent_open_if_enabled();
- if (r < 0) {
- log_warning_errno(r, "Failed to set wall message, ignoring: %s",
- bus_error_message(&error, r));
- sd_bus_error_free(&error);
+ if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) ) {
+ r = elogind_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);
+ }
}
/* Now call elogind itself to request the operation */
method,
&error,
NULL,
- "b",
- arg_ask_password);
+ "b", arg_ask_password);
if (r < 0)
log_error("Failed to execute operation: %s", bus_error_message(&error, r));
if (!bus)
return -EIO;
- polkit_agent_open_if_enabled();
-
switch (a) {
case ACTION_POWEROFF:
elogind_log_special(a);
+ /* For poweroff and reboot, some extra checks are performed: */
+ if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT) ) {
+
+ /* No power off actions in chroot environments */
+ if ( running_in_chroot() > 0 ) {
+ log_info("Running in chroot, ignoring request.");
+ return 0;
+ }
+
+ /* Check time argument */
+ if ( (argc > 1) && (ACTION_CANCEL_SHUTDOWN != arg_action)) {
+ r = parse_shutdown_time_spec(argv[1], &arg_when);
+ if (r < 0) {
+ log_error("Failed to parse time specification: %s", argv[optind]);
+ return r;
+ }
+ }
+
+ /* The optional user wall message must be set */
+ if ( (argc > 1)
+ && ( (arg_action == ACTION_CANCEL_SHUTDOWN)
+ || (0 == arg_when) ) )
+ /* No time argument for shutdown cancel, or no
+ * time argument given. */
+ wall = argv + 1;
+ else if (argc > 2)
+ /* We skip the time argument */
+ wall = argv + 2;
+
+ if (wall) {
+ arg_wall = strv_copy(wall);
+ if (!arg_wall)
+ return log_oom();
+ }
+ }
+
/* Switch to cancel shutdown, if a shutdown action was requested,
and the option to cancel it was set: */
if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT)
if (r < 0)
return r;
- /* No power off actions in chroot environments */
- if ((a == ACTION_POWEROFF ||
- a == ACTION_REBOOT) &&
- (running_in_chroot() > 0) ) {
- log_info("Running in chroot, ignoring request.");
- return 0;
- }
-
- /* Check time arguments */
- if ( IN_SET(a, ACTION_POWEROFF, ACTION_REBOOT)
- && (argc > 1)
- && (arg_action != ACTION_CANCEL_SHUTDOWN) ) {
- r = parse_shutdown_time_spec(argv[1], &arg_when);
- if (r < 0) {
- log_error("Failed to parse time specification: %s", argv[optind]);
- return r;
- }
- } else
- arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE;
-
- /* The optional user wall message must be set */
- if ((argc > 1) && (arg_action == ACTION_CANCEL_SHUTDOWN) )
- /* No time argument for shutdown cancel */
- wall = argv + 1;
- else if (argc > 2)
- /* We skip the time argument */
- wall = argv + 2;
-
- if (wall) {
- arg_wall = strv_copy(wall);
- if (!arg_wall)
- return log_oom();
- }
-
/* Perform requested action */
if (IN_SET(a,
ACTION_POWEROFF,