diff options
author | Andrew G. Morgan <morgan@kernel.org> | 2021-11-20 16:55:58 -0800 |
---|---|---|
committer | Andrew G. Morgan <morgan@kernel.org> | 2021-11-20 16:55:58 -0800 |
commit | 4c7dde9f519095f74d19982fb3c1d05fb1ff46be (patch) | |
tree | 12311e594c56293eee7f7629822ca849a10e6a76 | |
parent | f7deb5ad451458eeec20f9e7546d731e932bec2c (diff) | |
download | libcap-4c7dde9f519095f74d19982fb3c1d05fb1ff46be.tar.gz |
Add some more info to the libcap.so as an executable.
Mostly cause we can, but this gives a little more diagnostic
value to the libcap.so executable mode of operation.
usage: libcap.so [--help|--usage|--summary]
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
-rw-r--r-- | libcap/Makefile | 3 | ||||
-rw-r--r-- | libcap/execable.c | 46 |
2 files changed, 49 insertions, 0 deletions
diff --git a/libcap/Makefile b/libcap/Makefile index 967820e..05fa90d 100644 --- a/libcap/Makefile +++ b/libcap/Makefile @@ -135,6 +135,9 @@ cap_test: cap_test.c $(INCLS) $(CAPOBJS) libcapsotest: $(CAPLIBNAME) ./$(CAPLIBNAME) + ./$(CAPLIBNAME) --usage + ./$(CAPLIBNAME) --help + ./$(CAPLIBNAME) --summary libpsxsotest: $(PSXLIBNAME) ./$(PSXLIBNAME) diff --git a/libcap/execable.c b/libcap/execable.c index 5e7a88f..9d3ae7f 100644 --- a/libcap/execable.c +++ b/libcap/execable.c @@ -1,9 +1,44 @@ #include <stdio.h> +#include <stdlib.h> +#include <sys/capability.h> + #include "execable.h" +static void usage(int status) +{ + printf("\nusage: libcap.so [--help|--usage|--summary]\n"); + exit(status); +} + +static void summary(void) +{ + cap_value_t bits = cap_max_bits(), c; + cap_mode_t mode = cap_get_mode(); + + printf("\nCurrent mode: %s\n", cap_mode_name(mode)); + printf("Number of cap values known to: this libcap=%d, running kernel=%d\n", + CAP_LAST_CAP+1, bits); + if (bits > CAP_LAST_CAP+1) { + printf("=> Consider upgrading libcap to name:"); + for (c = CAP_LAST_CAP+1; c < bits; c++) { + printf(" %d", c); + } + } else if (bits < CAP_LAST_CAP+1) { + printf("=> Newer kernels also provide support for:"); + for (c = bits; c <= CAP_LAST_CAP; c++) { + char *name = cap_to_name(c); + printf(" %s", name); + cap_free(name); + } + } + printf("\n"); +} + SO_MAIN(int argc, char **argv) { + int i; const char *cmd = "This library"; + if (argv != NULL && argv[0] != NULL) { cmd = argv[0]; } @@ -12,4 +47,15 @@ SO_MAIN(int argc, char **argv) "More information on this library is available from:\n" "\n" " https://sites.google.com/site/fullycapable/\n", cmd); + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "--usage") || !strcmp(argv[i], "--help")) { + usage(0); + } + if (!strcmp(argv[i], "--summary")) { + summary(); + continue; + } + usage(1); + } } |