From 3fa808f5886d08c45866217cfe6e6e9def7de04e Mon Sep 17 00:00:00 2001 From: "Andrew G. Morgan" Date: Sun, 29 Jun 2008 22:21:13 -0700 Subject: Make text representation more readable. When the most compact representation of a set of capabilities involves displaying unnamed capabilities (with numbers), folk find the output unreadable. With this change, we make an attempt to avoid ever printing numeric capabilities in the common cases for capability sets. Reported-by: Serge E. Hallyn Signed-off-by: Andrew G. Morgan --- libcap/cap_text.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'libcap/cap_text.c') diff --git a/libcap/cap_text.c b/libcap/cap_text.c index 1eaa7ae..e013714 100644 --- a/libcap/cap_text.c +++ b/libcap/cap_text.c @@ -406,13 +406,21 @@ char *cap_to_text(cap_t caps, ssize_t *length_p) memset(histo, 0, sizeof(histo)); - for (n = cap_maxbits; n--; ) + /* default prevailing state to the upper - unnamed bits */ + for (n = cap_maxbits-1; n > __CAP_BITS; n--) histo[getstateflags(caps, n)]++; + /* find which combination of capability sets shares the most bits */ for (m=t=7; t--; ) if (histo[t] > histo[m]) m = t; + /* capture remaining bits - selecting m from only the unnamed bits, + we maximize the likelihood that we won't see numeric capability + values in the text output. */ + while (n--) + histo[getstateflags(caps, n)]++; + /* blank is not a valid capability set */ p = sprintf(buf, "=%s%s%s", (m & LIBCAP_EFF) ? "e" : "", -- cgit v1.2.3