From: Dmitry V. Levin Date: Tue, 15 Nov 2016 22:57:33 +0000 (+0000) Subject: Split qual_syscall into separate functions X-Git-Tag: v4.15~129 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0323fa3217ef81afd6bfe4e8385daa7c7108435c;p=strace Split qual_syscall into separate functions Split qual_syscall into qualify_scno, qualify_syscall_class, and qualify_syscall_name. This might be needed later to implement syscall fault injection. * syscall.c (qualify_scno, qualify_syscall_class, qualify_syscall_name): New functions. (qual_syscall): Use them. --- diff --git a/syscall.c b/syscall.c index 40504e68..ba566b11 100644 --- a/syscall.c +++ b/syscall.c @@ -427,6 +427,19 @@ qualify_one(const unsigned int n, unsigned int bitflag, const int not, const int } } +static bool +qualify_scno(const char *const s, const unsigned int bitflag, + const int not) +{ + unsigned int i; + + if (*s < '0' || *s > '9' || (i = string_to_uint(s)) >= MAX_NSYSCALLS) + return false; + + qualify_one(i, bitflag, not, -1); + return true; +} + static int lookup_class(const char *s) { @@ -447,45 +460,62 @@ lookup_class(const char *s) return -1; } -static int -qual_syscall(const char *s, const unsigned int bitflag, const int not) +static bool +qualify_syscall_class(const char *const s, const unsigned int bitflag, + const int not) { unsigned int p; - unsigned int i; - int n; - int rc = -1; - - if ((n = lookup_class(s)) >= 0) { - for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) { - for (i = 0; i < nsyscall_vec[p]; ++i) { - if ((sysent_vec[p][i].sys_flags & n) == n) { - qualify_one(i, bitflag, not, p); - } + const int n = lookup_class(s); + + if (n < 0) + return false; + + for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) { + unsigned int i; + + for (i = 0; i < nsyscall_vec[p]; ++i) { + if (sysent_vec[p][i].sys_name + && (sysent_vec[p][i].sys_flags & n) == n) { + qualify_one(i, bitflag, not, p); } } - return 0; } - if (*s >= '0' && *s <= '9') { - i = string_to_uint(s); - if (i >= MAX_NSYSCALLS) - return -1; - qualify_one(i, bitflag, not, -1); - return 0; - } + return true; +} - for (p = 0; p < SUPPORTED_PERSONALITIES; p++) { - for (i = 0; i < nsyscall_vec[p]; i++) { +static bool +qualify_syscall_name(const char *const s, const unsigned int bitflag, + const int not) +{ + bool found = false; + unsigned int p; + + for (p = 0; p < SUPPORTED_PERSONALITIES; ++p) { + unsigned int i; + + for (i = 0; i < nsyscall_vec[p]; ++i) { if (sysent_vec[p][i].sys_name - && strcmp(s, sysent_vec[p][i].sys_name) == 0 - ) { + && strcmp(s, sysent_vec[p][i].sys_name) == 0) { qualify_one(i, bitflag, not, p); - rc = 0; + found = true; } } } - return rc; + return found; +} + +static int +qual_syscall(const char *s, const unsigned int bitflag, const int not) +{ + if (qualify_scno(s, bitflag, not) + || qualify_syscall_class(s, bitflag, not) + || qualify_syscall_name(s, bitflag, not)) { + return 0; + } + + return -1; } static int