[systemd-commits] 3 commits - src/shutdownd.c src/shutdownd.h src/systemctl.c

Michal Schmidt michich at kemper.freedesktop.org
Sat Jul 2 15:23:56 PDT 2011


 src/shutdownd.c |   40 ++++++++++++++++++----------------------
 src/shutdownd.h |    1 +
 src/systemctl.c |   10 ++++++----
 3 files changed, 25 insertions(+), 26 deletions(-)

New commits:
commit 30923233b34e23ed1b3ffa7317f6219f695fec2f
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Sat Jul 2 23:40:42 2011 +0200

    shutdown: print the standard wall message even when the user provided one
    
    Print the user-provided wall message in addition to the standard one, not
    instead of it.
    
    Related to: https://bugzilla.redhat.com/show_bug.cgi?id=624149

diff --git a/src/shutdownd.c b/src/shutdownd.c
index 7fd9573..49ab886 100644
--- a/src/shutdownd.c
+++ b/src/shutdownd.c
@@ -100,6 +100,9 @@ static int read_packet(int fd, struct shutdownd_command *_c) {
 }
 
 static void warn_wall(usec_t n, struct shutdownd_command *c) {
+        char date[FORMAT_TIMESTAMP_MAX];
+        const char *prefix;
+        char *l = NULL;
 
         assert(c);
         assert(c->warn_wall);
@@ -107,28 +110,21 @@ static void warn_wall(usec_t n, struct shutdownd_command *c) {
         if (n >= c->elapse)
                 return;
 
-        if (c->wall_message[0])
-                utmp_wall(c->wall_message, NULL);
+        if (c->mode == 'H')
+                prefix = "The system is going down for system halt at ";
+        else if (c->mode == 'P')
+                prefix = "The system is going down for power-off at ";
+        else if (c->mode == 'r')
+                prefix = "The system is going down for reboot at ";
+        else
+                assert_not_reached("Unknown mode!");
+
+        if (asprintf(&l, "%s%s%s%s!", c->wall_message, c->wall_message[0] ? "\n" : "",
+                     prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0)
+                log_error("Failed to allocate wall message");
         else {
-                char date[FORMAT_TIMESTAMP_MAX];
-                const char* prefix;
-                char *l = NULL;
-
-                if (c->mode == 'H')
-                        prefix = "The system is going down for system halt at ";
-                else if (c->mode == 'P')
-                        prefix = "The system is going down for power-off at ";
-                else if (c->mode == 'r')
-                        prefix = "The system is going down for reboot at ";
-                else
-                        assert_not_reached("Unknown mode!");
-
-                if (asprintf(&l, "%s%s!", prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0)
-                        log_error("Failed to allocate wall message");
-                else {
-                        utmp_wall(l, NULL);
-                        free(l);
-                }
+                utmp_wall(l, NULL);
+                free(l);
         }
 }
 

commit 52c002150a34c07a59369ee952bcd3a1f8f316ca
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Sat Jul 2 23:09:59 2011 +0200

    shutdown: respect the dry run option '-k'
    
    Don't do the actual power-off/reboot when '-k' is passed to shutdown.
    
    Related to: https://bugzilla.redhat.com/show_bug.cgi?id=624149

diff --git a/src/shutdownd.c b/src/shutdownd.c
index 1381941..7fd9573 100644
--- a/src/shutdownd.c
+++ b/src/shutdownd.c
@@ -348,7 +348,7 @@ finish:
         if (unlink_nologin)
                 unlink("/run/nologin");
 
-        if (exec_shutdown) {
+        if (exec_shutdown && !c.dry_run) {
                 char sw[3];
 
                 sw[0] = '-';
diff --git a/src/shutdownd.h b/src/shutdownd.h
index ed8a704..4581649 100644
--- a/src/shutdownd.h
+++ b/src/shutdownd.h
@@ -33,6 +33,7 @@ _packed_ struct shutdownd_command {
         char mode; /* H, P, r, i.e. the switches usually passed to
                     * shutdown to select whether to halt, power-off or
                     * reboot the machine */
+        bool dry_run;
         bool warn_wall;
 
         /* Yepp, sometimes we are lazy and use fixed-size strings like
diff --git a/src/systemctl.c b/src/systemctl.c
index b584e70..8f904c1 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -5422,7 +5422,7 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
         return verbs[i].dispatch(bus, argv + optind, left);
 }
 
-static int send_shutdownd(usec_t t, char mode, bool warn, const char *message) {
+static int send_shutdownd(usec_t t, char mode, bool dry_run, bool warn, const char *message) {
         int fd = -1;
         struct msghdr msghdr;
         struct iovec iovec;
@@ -5432,6 +5432,7 @@ static int send_shutdownd(usec_t t, char mode, bool warn, const char *message) {
         zero(c);
         c.elapse = t;
         c.mode = mode;
+        c.dry_run = dry_run;
         c.warn_wall = warn;
 
         if (message)
@@ -5527,6 +5528,7 @@ static int halt_main(DBusConnection *bus) {
                                    arg_action == ACTION_HALT     ? 'H' :
                                    arg_action == ACTION_POWEROFF ? 'P' :
                                                                    'r',
+                                   arg_dry,
                                    !arg_no_wall,
                                    m);
                 free(m);
@@ -5774,7 +5776,7 @@ int main(int argc, char*argv[]) {
                 break;
 
         case ACTION_CANCEL_SHUTDOWN:
-                r = send_shutdownd(0, 0, false, NULL);
+                r = send_shutdownd(0, 0, false, false, NULL);
                 break;
 
         case ACTION_INVALID:

commit 1a63987788624a8819b94b199aa6748665f5e957
Author: Michal Schmidt <mschmidt at redhat.com>
Date:   Sat Jul 2 20:41:36 2011 +0200

    shutdown: accept minutes argument without '+'
    
    Both SysVinit's and upstart's shutdown commands accept the number of
    minutes with or without the plus sign.
    'shutdown -h 1' works in RHEL 5, Fedora 14, Debian 6.
    Let's be compatible.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=708886

diff --git a/src/systemctl.c b/src/systemctl.c
index f6dca5b..b584e70 100644
--- a/src/systemctl.c
+++ b/src/systemctl.c
@@ -4815,10 +4815,10 @@ static int parse_time_spec(const char *t, usec_t *_u) {
 
         if (streq(t, "now"))
                 *_u = 0;
-        else if (t[0] == '+') {
+        else if (!strchr(t, ':')) {
                 uint64_t u;
 
-                if (safe_atou64(t + 1, &u) < 0)
+                if (safe_atou64(t, &u) < 0)
                         return -EINVAL;
 
                 *_u = now(CLOCK_REALTIME) + USEC_PER_MINUTE * u;



More information about the systemd-commits mailing list