summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew G. Morgan <morgan@kernel.org>2008-10-16 17:54:25 -0700
committerAndrew G. Morgan <morgan@kernel.org>2008-10-16 17:54:25 -0700
commitafb17b8c007a49d93b0d30936b2d65af1bfdb039 (patch)
tree33fd54797fbbed38e41971cbdc4a128031aa55a9
parent4f288dd21d4ac2b86821ad6e010b0444f8285fa9 (diff)
downloadlibcap2-afb17b8c007a49d93b0d30936b2d65af1bfdb039.tar.gz
Another corner case not gracefully handled by cap_to_text.
This shows up when you try to run getpcaps on a system still running with 32-bit capabilities. The output is very verbose for a process with no capabilities. Now it yields '='. Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r--libcap/cap_text.c7
-rw-r--r--libcap/libcap.h4
2 files changed, 7 insertions, 4 deletions
diff --git a/libcap/cap_text.c b/libcap/cap_text.c
index 2b81b1f..42fb685 100644
--- a/libcap/cap_text.c
+++ b/libcap/cap_text.c
@@ -365,9 +365,12 @@ char *cap_to_text(cap_t caps, ssize_t *length_p)
for (n = cap_maxbits-1; n > __CAP_BITS; n--)
histo[getstateflags(caps, n)]++;
- /* find which combination of capability sets shares the most bits */
+ /* find which combination of capability sets shares the most bits
+ we bias to preferring non-set (m=0) with the >= 0 test. Failing
+ to do this causes strange things to happen with older systems
+ that don't know about bits 32+. */
for (m=t=7; t--; )
- if (histo[t] > histo[m])
+ if (histo[t] >= histo[m])
m = t;
/* capture remaining bits - selecting m from only the unnamed bits,
diff --git a/libcap/libcap.h b/libcap/libcap.h
index 0c652ec..1e66f98 100644
--- a/libcap/libcap.h
+++ b/libcap/libcap.h
@@ -155,14 +155,14 @@ struct _cap_struct {
#include <stdio.h>
# define _cap_debug(f, x...) do { \
- fprintf(stderr, __FUNCTION__ "(" __FILE__ ":%d): ", __LINE__); \
+ fprintf(stderr, "%s(%s:%d): ", __FUNCTION__, __FILE__, __LINE__); \
fprintf(stderr, f, ## x); \
fprintf(stderr, "\n"); \
} while (0)
# define _cap_debugcap(s, c, set) do { \
unsigned _cap_index; \
- fprintf(stderr, __FUNCTION__ "(" __FILE__ ":%d): " s, __LINE__); \
+ fprintf(stderr, "%s(%s:%d): %s", __FUNCTION__, __FILE__, __LINE__, s); \
for (_cap_index=_LIBCAP_CAPABILITY_U32S; _cap_index-- > 0; ) { \
fprintf(stderr, "%08x", (c).u[_cap_index].flat[set]); \
} \