Hello,
>From bug report: https://bugzilla.redhat.com/show_bug.cgi?id=858693
"There is no easy way how to force "systemctl status" not to crop long
lines with ellipsis in a virtual terminal. "-a" or "--full" options
doesn't help (and they even shouldn't help, according to the man page)"

I am not sure if there should be additional parameter or extend --full,
but systemctl has already enough parameters.

Regards
Lukas
>From a7f8b7492c273b3878122822f517be7d7e185b5c Mon Sep 17 00:00:00 2001
From: Lukas Nykryn <[email protected]>
Date: Thu, 20 Sep 2012 16:17:52 +0200
Subject: [PATCH] systemctl: do not ellipsize cgroup members in full status

---
 man/systemctl.xml         |    2 +-
 src/shared/cgroup-show.c  |   13 ++++---
 src/shared/util.c         |   79 +++++++++++++++++++++++++++-----------------
 src/systemctl/systemctl.c |   15 +++++---
 4 files changed, 65 insertions(+), 44 deletions(-)

diff --git a/man/systemctl.xml b/man/systemctl.xml
index fedc588..eacd2ed 100644
--- a/man/systemctl.xml
+++ b/man/systemctl.xml
@@ -151,7 +151,7 @@
                                 <term><option>--full</option></term>
 
                                 <listitem><para>Do not ellipsize unit
-                                names and truncate unit descriptions
+                                names, cgroup members and truncate unit descriptions
                                 in the output of
                                 <command>list-units</command> and
                                 <command>list-jobs</command>.</para></listitem>
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index 9003a12..1b9f3cd 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -75,11 +75,12 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi
         /* And sort */
         qsort(pids, n_pids, sizeof(pid_t), compare);
 
-        if (n_columns > 8)
-                n_columns -= 8;
-        else
-                n_columns = 20;
-
+        if (n_columns != UINT_MAX) {
+                if (n_columns > 8)
+                        n_columns -= 8;
+                else
+                        n_columns = 20;
+        }
         for (i = 0; i < n_pids; i++) {
                 char *t = NULL;
 
@@ -217,7 +218,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
                                 }
                         }
 
-                        show_cgroup_by_path(last, p1, n_columns-2, kernel_threads, all);
+                        show_cgroup_by_path(last, p1, n_columns == UINT_MAX ? n_columns : n_columns-2, kernel_threads, all);
                         free(last);
                 }
 
diff --git a/src/shared/util.c b/src/shared/util.c
index 02ee637..570da7c 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -972,10 +972,8 @@ int get_process_comm(pid_t pid, char **name) {
 }
 
 int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char **line) {
-        char *r, *k;
+        char *r = NULL, *k;
         int c;
-        bool space = false;
-        size_t left;
         FILE *f;
 
         assert(max_length > 0);
@@ -994,47 +992,66 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
 
         if (!f)
                 return -errno;
+        if (max_length != UINT_MAX) {
+                bool space = false;
+                size_t left;
+                r = new(char, max_length);
+                if (!r) {
+                        fclose(f);
+                        return -ENOMEM;
+                }
 
-        r = new(char, max_length);
-        if (!r) {
-                fclose(f);
-                return -ENOMEM;
-        }
+                k = r;
+                left = max_length;
+                while ((c = getc(f)) != EOF) {
+
+                        if (isprint(c)) {
+                                if (space) {
+                                        if (left <= 4)
+                                                break;
 
-        k = r;
-        left = max_length;
-        while ((c = getc(f)) != EOF) {
+                                        *(k++) = ' ';
+                                        left--;
+                                        space = false;
+                                }
 
-                if (isprint(c)) {
-                        if (space) {
                                 if (left <= 4)
                                         break;
 
-                                *(k++) = ' ';
+                                *(k++) = (char) c;
                                 left--;
-                                space = false;
-                        }
-
-                        if (left <= 4)
-                                break;
+                        }  else
+                                space = true;
+                }
 
-                        *(k++) = (char) c;
-                        left--;
-                }  else
-                        space = true;
+                if (left <= 4) {
+                        size_t n = MIN(left-1, 3U);
+                        memcpy(k, "...", n);
+                        k[n] = 0;
+                } else
+                        *k = 0;
+        } else {
+                size_t len = 0, alloc = 0;
+                while ((c = getc(f)) != EOF) {
+                        if(alloc <= len+1) {
+                                alloc += 20;
+                                k = realloc(r, alloc);
+                                if (k == NULL) {
+                                        free(r);
+                                        fclose(f);
+                                        return log_oom();
+                                }
+                                r = k;
+                        }
+                        r[len] = isprint(c) ? c : ' ';
+                        r[++len] = 0;
+                }
         }
 
-        if (left <= 4) {
-                size_t n = MIN(left-1, 3U);
-                memcpy(k, "...", n);
-                k[n] = 0;
-        } else
-                *k = 0;
-
         fclose(f);
 
         /* Kernel threads have no argv[] */
-        if (r[0] == 0) {
+        if (r == NULL || r[0] == 0) {
                 char *t;
                 int h;
 
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index cc9c775..dbe4e13 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2255,12 +2255,15 @@ static void print_status_info(UnitStatusInfo *i) {
                         unsigned k = 0;
                         pid_t extra[2];
 
-                        c = columns();
-                        if (c > 18)
-                                c -= 18;
-                        else
-                                c = 0;
-
+                        if(arg_full)
+                                c = UINT_MAX;
+                        else {
+                                c = columns();
+                                if (c > 18)
+                                        c -= 18;
+                                else
+                                        c = 0;
+                        }
                         if (i->main_pid > 0)
                                 extra[k++] = i->main_pid;
 
-- 
1.7.6.5

_______________________________________________
systemd-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/systemd-devel

Reply via email to