aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2008-06-29 22:21:13 -0700
committerAndrew G. Morgan <morgan@kernel.org>2008-06-29 22:21:13 -0700
commit3fa808f5886d08c45866217cfe6e6e9def7de04e (patch)
tree7e2ec95a15c55c8491c4f428a7d58f71e296d154
parent6d809ebd1d7bea3c0564b6ee3c13abee408738ea (diff)
downloadlibcap-3fa808f5886d08c45866217cfe6e6e9def7de04e.tar.gz
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 <serue@us.ibm.com> Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--libcap/cap_text.c10
1 files changed, 9 insertions, 1 deletions
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" : "",