Sophie

Sophie

distrib > Fedora > 17 > i386 > media > updates-src > by-pkgid > ab4b662b9827b6375ffd451bf4abd615 > files > 520

systemd-44-24.fc17.src.rpm

From 3cf7dd4d56b49993f5bfdd17d1bab18a92080e51 Mon Sep 17 00:00:00 2001
From: Michal Sekletar <msekleta@redhat.com>
Date: Mon, 30 Jul 2012 17:25:39 +0200
Subject: [PATCH] shutdown: allow to specify broadcast message when cancelling
 shutdown

makes shutdown behaviour more compatible
(cherry picked from commit dfcc5c33f42554a5293e68e7093da2403e363997)
---
 src/shutdownd/shutdownd.c |  4 ++++
 src/systemctl/systemctl.c | 39 ++++++++++++++++++++++++++++-----------
 2 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index 0e4b21e..f3aaaa6 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -136,6 +136,8 @@ static void warn_wall(usec_t n, struct sd_shutdown_command *c) {
                 prefix = "The system is going down for reboot at ";
         else if (c->mode == SD_SHUTDOWN_KEXEC)
                 prefix = "The system is going down for kexec reboot at ";
+        else if (c->mode == SD_SHUTDOWN_NONE)
+                prefix = "The system shutdown has been cancelled at ";
         else
                 assert_not_reached("Unknown mode!");
 
@@ -356,6 +358,8 @@ int main(int argc, char *argv[]) {
 
                                 if (!scheduled(&b.command)) {
                                         log_info("Shutdown canceled.");
+                                        if (b.command.warn_wall)
+                                                warn_wall(0, &b.command);
                                         break;
                                 }
 
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 16e0e30..e7eb9e7 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -248,12 +248,13 @@ static int translate_bus_error_to_exit_status(int r, const DBusError *error) {
 
 static void warn_wall(enum action a) {
         static const char *table[_ACTION_MAX] = {
-                [ACTION_HALT]      = "The system is going down for system halt NOW!",
-                [ACTION_REBOOT]    = "The system is going down for reboot NOW!",
-                [ACTION_POWEROFF]  = "The system is going down for power-off NOW!",
-                [ACTION_KEXEC]     = "The system is going down for kexec reboot NOW!",
-                [ACTION_RESCUE]    = "The system is going down to rescue mode NOW!",
-                [ACTION_EMERGENCY] = "The system is going down to emergency mode NOW!"
+                [ACTION_HALT]            = "The system is going down for system halt NOW!",
+                [ACTION_REBOOT]          = "The system is going down for reboot NOW!",
+                [ACTION_POWEROFF]        = "The system is going down for power-off NOW!",
+                [ACTION_KEXEC]           = "The system is going down for kexec reboot NOW!",
+                [ACTION_RESCUE]          = "The system is going down to rescue mode NOW!",
+                [ACTION_EMERGENCY]       = "The system is going down to emergency mode NOW!",
+                [ACTION_CANCEL_SHUTDOWN] = "The system shutdown has been cancelled NOW!"
         };
 
         if (arg_no_wall)
@@ -5044,7 +5045,7 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
                 }
         }
 
-        if (argc > optind) {
+        if (argc > optind && arg_action != ACTION_CANCEL_SHUTDOWN) {
                 r = parse_time_spec(argv[optind], &arg_when);
                 if (r < 0) {
                         log_error("Failed to parse time specification: %s", argv[optind]);
@@ -5053,8 +5054,11 @@ static int shutdown_parse_argv(int argc, char *argv[]) {
         } else
                 arg_when = now(CLOCK_REALTIME) + USEC_PER_MINUTE;
 
-        /* We skip the time argument */
-        if (argc > optind + 1)
+        if (argc > optind && arg_action == ACTION_CANCEL_SHUTDOWN)
+                /* No time argument for shutdown cancel */
+                arg_wall = argv + optind;
+        else if (argc > optind + 1)
+                /* We skip the time argument */
                 arg_wall = argv + optind + 1;
 
         optind = argc;
@@ -5833,9 +5837,22 @@ int main(int argc, char*argv[]) {
                 r = reload_with_fallback(bus);
                 break;
 
-        case ACTION_CANCEL_SHUTDOWN:
-                r = send_shutdownd(0, 0, false, false, NULL);
+        case ACTION_CANCEL_SHUTDOWN: {
+                char *m = NULL;
+
+                if (arg_wall) {
+                        m = strv_join(arg_wall, " ");
+                        if (!m) {
+                                retval = EXIT_FAILURE;
+                                goto finish;
+                        }
+                }
+                r = send_shutdownd(arg_when, SD_SHUTDOWN_NONE, false, !arg_no_wall, m);
+                if (r < 0)
+                        log_warning("Failed to talk to shutdownd, shutdown hasn't been cancelled: %s", strerror(-r));
+                free(m);
                 break;
+        }
 
         case ACTION_INVALID:
         case ACTION_RUNLEVEL: