diff options
author | Lukas Nykryn <lnykryn@redhat.com> | 2013-01-14 18:16:50 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-16 12:11:47 -0500 |
commit | 9bdbc2e2ec523dbefe1c1c7e164b5544aff0b185 (patch) | |
tree | 5a24260ea36f9984b1f03162fa4d418429d9f268 /src/shared/util.c | |
parent | 2e72983463fc0b95f5aac3528334848e8d1d0744 (diff) |
systemctl,loginctl,cgls: do not ellipsize cgroup members when --full is specified
New file output.h with output flags and modes.
--full parameter also for cgls and loginctl.
Include 'all' parameter in flags (show_cgroup_by_path, show_cgroup,
show_cgroup_and_extra, show_cgroup_and_extra_by_spec).
get_process_cmdline with max_length == 0 will not ellipsize output.
Replace LINE_MAX with 0 in some calls of get_process_cmdline.
[zj: Default to --full when under pager for clgs.
Drop '-f' since it wasn't documented and didn't actually work.
Reindent a bit.
]
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index a87828d451..0161f3e957 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -905,13 +905,10 @@ 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); assert(line); if (pid == 0) @@ -927,47 +924,64 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char * if (!f) return -errno; + if (max_length == 0) { + size_t len = 1; + while ((c = getc(f)) != EOF) { + k = realloc(r, len+1); + if (k == NULL) { + free(r); + fclose(f); + return -ENOMEM; + } + r = k; + r[len-1] = isprint(c) ? c : ' '; + r[len] = 0; + len++; + } + } else { + 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; } - 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; |