summaryrefslogtreecommitdiffstats
path: root/src/shared/cgroup-show.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-05-15 11:20:26 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2019-05-22 10:08:17 +0200
commitbc28751ed2372065fd6f6f7ba6137edf21dee88b (patch)
tree22b55bbd88ec30c99aafc0fbb671ce965f621632 /src/shared/cgroup-show.c
parentutil-lib: add truncation based on printable width to utf8_escape_non_printable() (diff)
downloadsystemd-bc28751ed2372065fd6f6f7ba6137edf21dee88b.tar.xz
systemd-bc28751ed2372065fd6f6f7ba6137edf21dee88b.zip
Rework cmdline printing to use unicode
The functions to retrieve and print process cmdlines were based on the assumption that they contain printable ASCII, and everything else should be filtered out. That assumption doesn't hold in today's world, where people are free to use unicode everywhere. This replaces the custom cmdline reading code with a more generic approach using utf8_escape_non_printable_full(). For kernel threads, truncation is done on the parenthesized name, so we'll get "[worker]", "[worker…]", …, "[w…]", "[…", "…" as we reduce the number of available columns. This implementation is most likely slower for very long cmdlines, but I don't think this is very important. The common case is to have short commandlines, and should print those properly. Absurdly long cmdlines are the exception, which needs to be handled correctly and safely, but speed is not too important. Fixes #12532. v2: - use size_t for the number of columns. This change propagates into various other functions that call get_process_cmdline(), increasing the size of the patch, but the changes are rather trivial.
Diffstat (limited to 'src/shared/cgroup-show.c')
-rw-r--r--src/shared/cgroup-show.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index cac7922ec0..2bd0e09cae 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -29,7 +29,7 @@ static void show_pid_array(
pid_t pids[],
unsigned n_pids,
const char *prefix,
- unsigned n_columns,
+ size_t n_columns,
bool extra,
bool more,
OutputFlags flags) {
@@ -51,7 +51,7 @@ static void show_pid_array(
pid_width = DECIMAL_STR_WIDTH(pids[j]);
if (flags & OUTPUT_FULL_WIDTH)
- n_columns = 0;
+ n_columns = SIZE_MAX;
else {
if (n_columns > pid_width + 3) /* something like "├─1114784 " */
n_columns -= pid_width + 3;
@@ -75,7 +75,7 @@ static void show_pid_array(
static int show_cgroup_one_by_path(
const char *path,
const char *prefix,
- unsigned n_columns,
+ size_t n_columns,
bool more,
OutputFlags flags) {
@@ -119,7 +119,7 @@ static int show_cgroup_one_by_path(
int show_cgroup_by_path(
const char *path,
const char *prefix,
- unsigned n_columns,
+ size_t n_columns,
OutputFlags flags) {
_cleanup_free_ char *fn = NULL, *p1 = NULL, *last = NULL, *p2 = NULL;
@@ -199,7 +199,7 @@ int show_cgroup_by_path(
int show_cgroup(const char *controller,
const char *path,
const char *prefix,
- unsigned n_columns,
+ size_t n_columns,
OutputFlags flags) {
_cleanup_free_ char *p = NULL;
int r;
@@ -217,7 +217,7 @@ static int show_extra_pids(
const char *controller,
const char *path,
const char *prefix,
- unsigned n_columns,
+ size_t n_columns,
const pid_t pids[],
unsigned n_pids,
OutputFlags flags) {
@@ -262,7 +262,7 @@ int show_cgroup_and_extra(
const char *controller,
const char *path,
const char *prefix,
- unsigned n_columns,
+ size_t n_columns,
const pid_t extra_pids[],
unsigned n_extra_pids,
OutputFlags flags) {