chiark / gitweb /
util: never ellipsize welcome message
authorLennart Poettering <lennart@poettering.net>
Thu, 5 Jan 2012 14:35:16 +0000 (15:35 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 5 Jan 2012 14:39:07 +0000 (15:39 +0100)
src/unit.c
src/util.c
src/util.h

index dea8f4a7faa6b2e9144c9bdde8a20c1a3f2ea1d8..3191071ae2c9337823814cd9decc12e259fb4924 100644 (file)
@@ -2455,7 +2455,7 @@ void unit_status_printf(Unit *u, const char *status, const char *format, ...) {
                 return;
 
         va_start(ap, format);
-        status_vprintf(status, format, ap);
+        status_vprintf(status, true, format, ap);
         va_end(ap);
 }
 
index 72eb05954b3d7952e3e054aec5610240c8f8ba84..d3d521b9280833518d793e293dbb24f14757fc16 100644 (file)
@@ -3577,7 +3577,7 @@ cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
         }
 }
 
-void status_vprintf(const char *status, const char *format, va_list ap) {
+void status_vprintf(const char *status, bool ellipse, const char *format, va_list ap) {
         char *s = NULL, *spaces = NULL, *e;
         int fd = -1, c;
         size_t emax, sl, left;
@@ -3592,38 +3592,42 @@ void status_vprintf(const char *status, const char *format, va_list ap) {
         if (vasprintf(&s, format, ap) < 0)
                 goto finish;
 
-        fd = open_terminal("/dev/tty", O_WRONLY|O_NOCTTY|O_CLOEXEC);
+        fd = open_terminal("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC);
         if (fd < 0)
                 goto finish;
 
-        c = fd_columns(fd);
-        if (c <= 0)
-                c = 80;
+        if (ellipse) {
+                c = fd_columns(fd);
+                if (c <= 0)
+                        c = 80;
 
-        if (status) {
-                sl = 2 + 6 + 1; /* " [" status "]" */
-                emax = (size_t) c > sl ? c - sl - 1 : 0;
-        } else
-                emax = c - 1;
+                if (status) {
+                        sl = 2 + 6 + 1; /* " [" status "]" */
+                        emax = (size_t) c > sl ? c - sl - 1 : 0;
+                } else
+                        emax = c - 1;
 
-        e = ellipsize(s, emax, 75);
-        if (e) {
-                free(s);
-                s = e;
+                e = ellipsize(s, emax, 75);
+                if (e) {
+                        free(s);
+                        s = e;
+                }
         }
 
         zero(iovec);
         IOVEC_SET_STRING(iovec[n++], s);
 
-        sl = strlen(s);
-        left = emax > sl ? emax - sl : 0;
-        if (left > 0) {
-                spaces = malloc(left);
-                if (spaces) {
-                        memset(spaces, ' ', left);
-                        iovec[n].iov_base = spaces;
-                        iovec[n].iov_len = left;
-                        n++;
+        if (ellipse) {
+                sl = strlen(s);
+                left = emax > sl ? emax - sl : 0;
+                if (left > 0) {
+                        spaces = malloc(left);
+                        if (spaces) {
+                                memset(spaces, ' ', left);
+                                iovec[n].iov_base = spaces;
+                                iovec[n].iov_len = left;
+                                n++;
+                        }
                 }
         }
 
@@ -3644,13 +3648,13 @@ finish:
                 close_nointr_nofail(fd);
 }
 
-void status_printf(const char *status, const char *format, ...) {
+void status_printf(const char *status, bool ellipse, const char *format, ...) {
         va_list ap;
 
         assert(format);
 
         va_start(ap, format);
-        status_vprintf(status, format, ap);
+        status_vprintf(status, ellipse, format, ap);
         va_end(ap);
 }
 
@@ -3808,6 +3812,7 @@ void status_welcome(void) {
                 const_color = "1";
 
         status_printf(NULL,
+                      false,
                       "\nWelcome to \x1B[%sm%s\x1B[0m!\n",
                       const_color ? const_color : ansi_color,
                       const_pretty ? const_pretty : pretty_name);
index d96ce7e77ba314b2f7cc1951830909ea7eeb83c1..4d27c4bd516b2d222fb1dc3e2701b6c3651c0988 100644 (file)
@@ -374,8 +374,8 @@ int pipe_eof(int fd);
 
 cpu_set_t* cpu_set_malloc(unsigned *ncpus);
 
-void status_vprintf(const char *status, const char *format, va_list ap);
-void status_printf(const char *status, const char *format, ...);
+void status_vprintf(const char *status, bool ellipse, const char *format, va_list ap);
+void status_printf(const char *status, bool ellipse, const char *format, ...);
 void status_welcome(void);
 
 int fd_columns(int fd);