chiark / gitweb /
shutdown: print the standard wall message even when the user provided one
authorMichal Schmidt <mschmidt@redhat.com>
Sat, 2 Jul 2011 21:40:42 +0000 (23:40 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Sat, 2 Jul 2011 22:15:43 +0000 (00:15 +0200)
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

src/shutdownd.c

index 7fd9573b2fa30ba425241857ae2f2f16bb2ada10..49ab8863e4156421461434c5af870984ea312ca4 100644 (file)
@@ -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) {
 }
 
 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);
 
         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 (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 {
         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);
         }
 }
 
         }
 }