From b138da4a4b9d57b850ca4d0061969f5e3299861d Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Sat, 3 Nov 2012 20:31:18 -0700 Subject: Imported Upstream version 2.22 --- progs/getpcaps.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 progs/getpcaps.c (limited to 'progs/getpcaps.c') diff --git a/progs/getpcaps.c b/progs/getpcaps.c new file mode 100644 index 0000000..e405a92 --- /dev/null +++ b/progs/getpcaps.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1997,2008 Andrew G. Morgan + * + * This displays the capabilities of given target process(es). + */ + +#include +#include +#include +#include +#include +#include + +static void usage(void) +{ + fprintf(stderr, +"usage: getcaps [ ...]\n\n" +" This program displays the capabilities on the queried process(es).\n" +" The capabilities are displayed in the cap_from_text(3) format.\n\n" +"[Copyright (c) 1997-8,2007 Andrew G. Morgan ]\n" + ); + exit(1); +} + +int main(int argc, char **argv) +{ + int retval = 0; + + if (argc < 2) { + usage(); + } + + for ( ++argv; --argc > 0; ++argv ) { + ssize_t length; + int pid; + cap_t cap_d; + + pid = atoi(argv[0]); + + cap_d = cap_get_pid(pid); + if (cap_d == NULL) { + fprintf(stderr, "Failed to get cap's for proccess %d:" + " (%s)\n", pid, strerror(errno)); + retval = 1; + continue; + } else { + char *result = cap_to_text(cap_d, &length); + fprintf(stderr, "Capabilities for `%s': %s\n", *argv, result); + cap_free(result); + result = NULL; + cap_free(cap_d); + } + } + + return retval; +} -- cgit v1.2.3