diff options
author | Paul Moore <pmoore@redhat.com> | 2013-05-29 13:57:53 -0400 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2013-05-29 14:46:07 -0400 |
commit | a90fc8e32cfa66db5602b0c9088dc68f1b88208c (patch) | |
tree | 1716a3144c69811fd1d35508dabf5fb2a5d4e406 | |
parent | c0d9fc5950fb28adae649b71938368915db31908 (diff) | |
download | libseccomp-a90fc8e32cfa66db5602b0c9088dc68f1b88208c.tar.gz |
tools: allow the syscall resolver to resolve both names and numbers
Often we need to resolve syscall numbers into syscall names, add this
functionality to our existing resolver.
Thanks to Eduardo Otubo who originally came up with the idea and
inspired this patch.
Reported-by: Eduardo Otubo <otubo@linux.vnet.ibm.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
-rw-r--r-- | tools/scmp_sys_resolver.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/tools/scmp_sys_resolver.c b/tools/scmp_sys_resolver.c index 5bc593e..7e627d4 100644 --- a/tools/scmp_sys_resolver.c +++ b/tools/scmp_sys_resolver.c @@ -22,6 +22,7 @@ #include <errno.h> #include <stdlib.h> #include <stdio.h> +#include <ctype.h> #include <string.h> #include <unistd.h> @@ -41,7 +42,7 @@ static void exit_usage(const char *program) { fprintf(stderr, - "usage: %s [-h] [-a <arch>] [-t] <syscall_name>\n", + "usage: %s [-h] [-a <arch>] [-t] <name>|<number>\n", program); exit(EINVAL); } @@ -55,6 +56,7 @@ int main(int argc, char *argv[]) int translate = 0; const struct arch_def *arch = arch_def_native; int sys_num; + const char *sys_name; /* parse the command line */ while ((opt = getopt(argc, argv, "a:ht"))> 0) { @@ -85,11 +87,18 @@ int main(int argc, char *argv[]) if (optind >= argc) exit_usage(argv[0]); - sys_num = arch_syscall_resolve_name(arch, argv[optind]); - if (translate != 0) - /* we ignore errors and just output the resolved number */ - arch_syscall_rewrite(arch, 0, &sys_num); - printf("%d\n", sys_num); + /* perform the syscall lookup */ + if (isdigit(argv[optind][0]) || argv[optind][0] == '-') { + sys_num = atoi(argv[optind]); + sys_name = arch_syscall_resolve_num(arch, sys_num); + printf("%s\n", sys_name); + } else { + sys_num = arch_syscall_resolve_name(arch, argv[optind]); + if (translate != 0) + /* ignore errors and just output the resolved number */ + arch_syscall_rewrite(arch, 0, &sys_num); + printf("%d\n", sys_num); + } return 0; } |