From 4278aa278cf05158c874cf9f28f45a1f60413ee6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mantas=20Mikul=C4=97nas?= Date: Fri, 19 Oct 2012 20:15:25 +0300 Subject: [PATCH] cgls: correctly ellipsize command lines for PIDs >= 1000000 --- src/shared/cgroup-show.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 9003a1228e1..2ffed8b739a 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -52,7 +52,7 @@ static unsigned ilog10(unsigned long ul) { } static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsigned n_columns, bool extra, bool more, bool kernel_threads) { - unsigned i, m; + unsigned i, m, pid_width; pid_t biggest = 0; /* Filter duplicates */ @@ -71,12 +71,13 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi pids[m++] = pids[i]; } n_pids = m; + pid_width = ilog10(biggest); /* And sort */ qsort(pids, n_pids, sizeof(pid_t), compare); - if (n_columns > 8) - n_columns -= 8; + if (n_columns > pid_width+2) + n_columns -= pid_width+2; else n_columns = 20; @@ -88,7 +89,7 @@ static void show_pid_array(int pids[], unsigned n_pids, const char *prefix, unsi printf("%s%s %*lu %s\n", prefix, extra ? "\342\200\243" : ((more || i < n_pids-1) ? "\342\224\234" : "\342\224\224"), - (int) ilog10(biggest), + pid_width, (unsigned long) pids[i], strna(t)); -- 2.39.2