From a90fc8e32cfa66db5602b0c9088dc68f1b88208c Mon Sep 17 00:00:00 2001 From: Paul Moore Date: Wed, 29 May 2013 13:57:53 -0400 Subject: 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 Signed-off-by: Paul Moore --- tools/scmp_sys_resolver.c | 21 +++++++++++++++------ 1 file 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 #include #include +#include #include #include @@ -41,7 +42,7 @@ static void exit_usage(const char *program) { fprintf(stderr, - "usage: %s [-h] [-a ] [-t] \n", + "usage: %s [-h] [-a ] [-t] |\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; } -- cgit v1.2.1