lapi/syscalls: Add syscall numbers for _sysctl
PATCH 1/4 lapi/syscalls: Add syscall numbers for _sysctl
--- include/lapi/syscalls/aarch64.in | 1 + include/lapi/syscalls/arm.in | 1 + include/lapi/syscalls/hppa.in | 1 + include/lapi/syscalls/i386.in | 1 + include/lapi/syscalls/ia64.in | 1 + include/lapi/syscalls/powerpc.in | 1 + include/lapi/syscalls/powerpc64.in | 1 + include/lapi/syscalls/s390.in | 1 + include/lapi/syscalls/s390x.in | 1 + include/lapi/syscalls/sh.in | 1 + include/lapi/syscalls/sparc.in | 1 + include/lapi/syscalls/sparc64.in | 1 + include/lapi/syscalls/x86_64.in | 1 + 13 files changed, 13 insertions(+)
include/lapi/syscalls/aarch64.in +1 -0
@@ -257,3 +257,4 @@ kcmp 272 getrandom 278 memfd_create 279 copy_file_range 285 +_sysctl 1078
include/lapi/syscalls/arm.in +1 -0
@@ -120,6 +120,7 @@ readv (__NR_SYSCALL_BASE+145) writev (__NR_SYSCALL_BASE+146) getsid (__NR_SYSCALL_BASE+147) fdatasync (__NR_SYSCALL_BASE+148) +_sysctl (__NR_SYSCALL_BASE+149) mlock (__NR_SYSCALL_BASE+150) munlock (__NR_SYSCALL_BASE+151) mlockall (__NR_SYSCALL_BASE+152)
include/lapi/syscalls/hppa.in +1 -0
@@ -1,3 +1,4 @@ +_sysctl 149 openat 275 mkdirat (__NR_openat + 1) mknodat (__NR_openat + 2)
include/lapi/syscalls/i386.in +1 -0
@@ -145,6 +145,7 @@ readv 145 writev 146 getsid 147 fdatasync 148 +_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/ia64.in +1 -0
@@ -118,6 +118,7 @@ readv 1146 writev 1147 pread64 1148 pwrite64 1149 +_sysctl 1150 mmap 1151 munmap 1152 mlock 1153
include/lapi/syscalls/powerpc.in +1 -0
@@ -145,6 +145,7 @@ readv 145 writev 146 getsid 147 fdatasync 148 +_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/powerpc64.in +1 -0
@@ -145,6 +145,7 @@ readv 145 writev 146 getsid 147 fdatasync 148 +_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/s390.in +1 -0
@@ -107,6 +107,7 @@ readv 145 writev 146 getsid 147 fdatasync 148 +_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/s390x.in +1 -0
@@ -107,6 +107,7 @@ readv 145 writev 146 getsid 147 fdatasync 148 +_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/sh.in +1 -0
@@ -145,6 +145,7 @@ readv 145 writev 146 getsid 147 fdatasync 148 +_sysctl 149 mlock 150 munlock 151 mlockall 152
include/lapi/syscalls/sparc.in +1 -0
@@ -252,6 +252,7 @@ sched_get_priority_min 247 sched_rr_get_interval 248 nanosleep 249 mremap 250 +_sysctl 251 getsid 252 fdatasync 253 nfsservctl 254
include/lapi/syscalls/sparc64.in +1 -0
@@ -228,6 +228,7 @@ sched_get_priority_min 247 sched_rr_get_interval 248 nanosleep 249 mremap 250 +_sysctl 251 getsid 252 fdatasync 253 nfsservctl 254
include/lapi/syscalls/x86_64.in +1 -0
@@ -154,6 +154,7 @@ munlockall 152 vhangup 153 modify_ldt 154 pivot_root 155 +_sysctl 156 prctl 157 arch_prctl 158 adjtimex 159
Signature · 1 line
1.8.3.1
PATCH 2/4 syscalls/sysctl01: Enable && Cleanup
1) Undefined __NR_sysctl always skips the test even though CONFIG_SYSCTL_SYSCALL is built, so enable it by correct __NR__sysctl.
2) Convert to new API.
3) Fix compiler warnings.
--- testcases/kernel/syscalls/sysctl/sysctl01.c | 224 +++++++--------------------- 1 file changed, 57 insertions(+), 167 deletions(-)
testcases/kernel/syscalls/sysctl/sysctl01.c +57 -167
@@ -1,196 +1,86 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2018 Xiao Yang <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. */ /* -* NAME -* sysctl01.c -* -* DESCRIPTION -* Testcase for testing the basic functionality of sysctl(2) system call. -* This testcase attempts to read the kernel parameters using -* sysctl({CTL_KERN, KERN_* }, ...) and compares it with the known -* values. -* -* USAGE: <for command-line> -* sysctl01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -f : Turn off functionality Testing. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* -* RESTRICTIONS -* None +* DESCRIPTION: +* Testcase for testing the basic functionality of sysctl(2) system call. +* This testcase attempts to read the kernel parameters by using +* sysctl({CTL_KERN, KERN_* }, ...) and compares it with the known values. */ -#include "test.h" -#include <stdio.h> +#include <errno.h> -#include <unistd.h> +#include <stdio.h> +#include <string.h> #include <linux/version.h> #include <sys/utsname.h> #include <linux/unistd.h> #include <linux/sysctl.h> -char *TCID ="sysctl01" ; - -/* This is an older/deprecated syscall that newer arches are omitting */ -#ifdef __NR_sysctl - -int TST_TOTAL =3 ; +#include "tst_test.h" +#include "lapi/syscalls.h" -static int sysctl (int *name,int nlen,void *oldval,size_t * oldlenp, -void *newval,size_t newlen) -{ -struct __sysctl_args args = - { name, nlen, oldval, oldlenp, newval, newlen }; -return syscall (__NR__sysctl, &args); -} - -struct utsname buf; -char osname[BUFSIZ ]; -size_t osnamelth; +static struct utsname buf; -void setup (void ); -void cleanup (void ); - -struct test_case_t { +static struct test_case_t {char *desc;int name[2 ]; -int size; -char *oldval; -size_t *oldlen; -void *newval; -int newlen; -int (*cleanup) (); -int exp_retval; +char *cmp_str; }TC [] = { - { -"Test for KERN_OSTYPE" , { -CTL_KERN ,KERN_OSTYPE },2 , osname, &osnamelth,NULL ,0 ,NULL ,0 }, { -"Test for KERN_OSRELEASE" , { -CTL_KERN ,KERN_OSRELEASE },2 , - osname, &osnamelth,NULL ,0 ,NULL ,0 }, { -"Test for KERN_VERSION" , { -CTL_KERN ,KERN_VERSION },2 , osname, &osnamelth,NULL ,0 ,NULL ,0 } + {"KERN_OSTYPE" , {CTL_KERN ,KERN_OSTYPE }, buf.sysname}, + {"KERN_OSRELEASE" , {CTL_KERN ,KERN_OSRELEASE }, buf.release}, + {"KERN_VERSION" , {CTL_KERN ,KERN_VERSION }, buf.version}, }; -int main (int ac,char **av) +static void verify_sysctl (unsigned int n) { -int lc; -int i; -char *comp_string; - - comp_string =NULL ; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -/* reset tst_count in case we are looping */ - tst_count =0 ; - -for (i =0 ; i <TST_TOTAL ; ++i) { - - osnamelth =sizeof (osname); - -switch (i) { -case 0 : - comp_string = buf.sysname; -break ; -case 1 : - comp_string = buf.release; -break ; -case 2 : - comp_string = buf.version; -break ; - } - -TEST (sysctl (TC [i].name,TC [i].size,TC [i].oldval, -TC [i].oldlen,TC [i].newval,TC [i].newlen)); - -if (TEST_RETURN !=0 ) { -if (TEST_ERRNO ==ENOSYS ) { -tst_resm (TCONF , -"You may need to make CONFIG_SYSCTL_SYSCALL=y" -" to your kernel config." ); - }else { -tst_resm (TFAIL , -"sysctl(2) failed unexpectedly " -"errno:%d" ,TEST_ERRNO ); - } -continue ; - } - -if (strcmp (TC [i].oldval, comp_string) !=0 ) { -tst_resm (TFAIL ,"strings don't match - %s : %s" , -TC [i].oldval, comp_string); - }else { -tst_resm (TPASS ,"%s is correct" ,TC [i].desc); - } -if (TC [i].cleanup) { - (void )TC [i].cleanup (); - } - } +char osname[BUFSIZ ]; +size_t length =BUFSIZ ; +struct test_case_t *tc = &TC [n]; + +memset (osname,0 ,BUFSIZ ); + +struct __sysctl_args args = { + .name = tc->name, + .nlen =ARRAY_SIZE (tc->name), + .oldval = osname, + .oldlenp = &length, + }; + +TEST (tst_syscall (__NR__sysctl, &args)); +if (TEST_RETURN !=0 ) { +tst_res (TFAIL |TTERRNO ,"sysctl() failed unexpectedly" ); +return ; } -cleanup (); -tst_exit (); -} - -/* -* setup() - performs all ONE TIME setup for this test. -*/ -void setup (void ) -{ - -tst_sig (NOFORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; - -/* get kernel name and information */ -if (uname (&buf) ==-1 ) { -tst_brkm (TBROK , cleanup,"uname() failed" ); +if (strcmp (osname, tc->cmp_str)) { +tst_res (TFAIL ,"Strings don't match %s : %s" , + osname, tc->cmp_str); + }else { +tst_res (TPASS ,"Test for %s is correct" , tc->desc); } } -/* -* cleanup() - performs all ONE TIME cleanup for this test at -* completion or premature exit. -*/ -void cleanup (void ) +static void setup (void ) { - +/* get kernel name and information */ +if (uname (&buf) ==-1 ) +tst_brk (TBROK |TERRNO ,"uname() failed" ); } -#else -int TST_TOTAL =0 ; - -int main (void ) -{ - -tst_brkm (TCONF ,NULL , -"This test needs a kernel that has sysctl syscall." ); -} -#endif +static struct tst_test test = { + .setup = setup, + .tcnt =ARRAY_SIZE (TC ), + .test = verify_sysctl, +};
Signature · 1 line
1.8.3.1
PATCH 3/4 syscalls/sysctl03: Enable && Cleanup
In reply to Xiao Yang1) Undefined __NR_sysctl always skips the test even though CONFIG_SYSCTL_SYSCALL is built, so enable it by correct __NR__sysctl.
2) Convert to new API.
3) Fix compiler warnings and errors.
--- testcases/kernel/syscalls/sysctl/sysctl03.c | 236 ++++++++-------------------- 1 file changed, 67 insertions(+), 169 deletions(-)
testcases/kernel/syscalls/sysctl/sysctl03.c +67 -169
@@ -1,67 +1,41 @@/* +* Copyright (c) International Business Machines Corp., 2001 +* Copyright (c) 2018 Xiao Yang <[email protected]> * -* Copyright (c) International Business Machines Corp., 2001 +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. * -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +* the GNU General Public License for more details. */ /* -* NAME -* sysctl03.c -* * DESCRIPTION -* Testcase to check that sysctl(2) sets errno to EPERM correctly. +* 1) Call sysctl(2) as a root user, and attempt to write data +* to the kernel_table[]. Since the table does not have write +* permissions even for the root, it should fail EPERM. +* 2) Call sysctl(2) as a non-root user, and attempt to write data +* to the kernel_table[]. Since the table does not have write +* permission for the regular user, it should fail with EPERM. * -* ALGORITHM -* a. Call sysctl(2) as a root user, and attempt to write data -* to the kernel_table[]. Since the table does not have write -* permissions even for the root, it should fail EPERM. -* b. Call sysctl(2) as a non-root user, and attempt to write data -* to the kernel_table[]. Since the table does not have write -* permission for the regular user, it should fail with EPERM. -* -* NOTE: There is a documentation bug in 2.6.33-rc1 where unfortunately the -* behavior of sysctl(2) isn't properly documented, as discussed in detail in -* the following thread: +* NOTE: There is a documentation bug in 2.6.33-rc1 where unfortunately +* the behavior of sysctl(2) isn't properly documented, as discussed +* in detail in the following thread: * http://sourceforge.net/mailarchive/message.php?msg_name=4B7BA24F.2010705%40linux.vnet.ibm.com. * * The documentation bug is filed as: -* https://bugzilla.kernel.org/show_bug.cgi?id=15446 . If you want the message -* removed, please ask your fellow kernel maintainer to fix their documentation. +* https://bugzilla.kernel.org/show_bug.cgi?id=15446 . If you want the +* message removed, please ask your fellow kernel maintainer to fix their +* documentation. * * Thanks! * -Ngie -* -* USAGE: <for command-line> -* sysctl03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] -* where, -c n : Run n copies concurrently. -* -e : Turn on errno logging. -* -i n : Execute test n times. -* -I x : Execute test for x seconds. -* -P x : Pause for x seconds between iterations. -* -t : Turn on syscall timing. -* -* HISTORY -* 07/2001 Ported by Wayne Boyer -* 02/2010 Updated by [email protected] -* -* RESTRICTIONS -* Test must be run as root. */ -#include "test.h" -#include "safe_macros.h" +#include <sys/types.h> #include <sys/wait.h> #include <stdio.h>
@@ -71,141 +45,65 @@#include <linux/sysctl.h> #include <pwd.h> -char *TCID ="sysctl03" ; - -/* This is an older/deprecated syscall that newer arches are omitting */ -#ifdef __NR_sysctl +#include "tst_test.h" +#include "lapi/syscalls.h" -int TST_TOTAL =2 ; +static int exp_eno; -int sysctl (int *name,int nlen,void *oldval,size_t * oldlenp, -void *newval,size_t newlen) +static void verify_sysctl (void ) { -struct __sysctl_args args = - { name, nlen, oldval, oldlenp, newval, newlen }; -return syscall (__NR__sysctl, &args); -} - -#define OSNAMESZ 100 +char *osname ="Linux" ; +int name[] = {CTL_KERN ,KERN_OSTYPE }; +struct __sysctl_args args = { + .name = name, + .nlen =ARRAY_SIZE (name), + .newval = osname, + .newlen =sizeof (osname), + }; + +TEST (tst_syscall (__NR__sysctl, &args)); +if (TEST_RETURN !=-1 ) { +tst_res (TFAIL ,"sysctl(2) succeeded unexpectedly" ); +return ; + } -void setup (void ); -void cleanup (void ); +if (TEST_ERRNO == exp_eno) +tst_res (TPASS |TTERRNO ,"Got expected error" ); +else +tst_res (TFAIL |TTERRNO ,"Got unexpected error" ); +} -int main (int ac,char **av) +static void setup (void ) { -int exp_eno; -int lc; - -char osname[OSNAMESZ ]; -int osnamelth, status; -int name[] = {CTL_KERN ,KERN_OSTYPE }; -pid_t pid; -struct passwd *ltpuser; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); -if ((tst_kvercmp (2 ,6 ,32 )) <=0 ) { exp_eno =EPERM ; }else { -/* ^^ Look above this warning. ^^ */ -tst_resm (TINFO , +/* Look above this warning. */ +tst_res (TINFO ,"this test's results are based on potentially undocumented behavior in the kernel. read the NOTE in the source file for more details" ); exp_eno =EACCES ; - exp_enos[0 ] =EACCES ; } - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - -/* reset tst_count in case we are looping */ - tst_count =0 ; - -strcpy (osname,"Linux" ); - osnamelth =sizeof (osname); - -TEST (sysctl (name,ARRAY_SIZE (name),0 ,0 , osname, osnamelth)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"sysctl(2) succeeded unexpectedly" ); - }else { -if (TEST_ERRNO == exp_eno) { -tst_resm (TPASS |TTERRNO ,"Got expected error" ); - }else if (errno ==ENOSYS ) { -tst_resm (TCONF , -"You may need to make CONFIG_SYSCTL_SYSCALL=y" -" to your kernel config." ); - }else { -tst_resm (TFAIL |TTERRNO , -"Got unexpected error" ); - } - } - - osnamelth =sizeof (osname); -if ((ltpuser =getpwnam ("nobody" )) ==NULL ) { -tst_brkm (TBROK , cleanup,"getpwnam() failed" ); - } - -/* set process ID to "ltpuser1" */ -SAFE_SETEUID (cleanup, ltpuser->pw_uid); - -if ((pid =FORK_OR_VFORK ()) ==-1 ) { -tst_brkm (TBROK , cleanup,"fork() failed" ); - } - -if (pid ==0 ) { -TEST (sysctl (name,ARRAY_SIZE (name),0 ,0 , osname, osnamelth)); - -if (TEST_RETURN !=-1 ) { -tst_resm (TFAIL ,"call succeeded unexpectedly" ); - }else { -if (TEST_ERRNO == exp_eno) { -tst_resm (TPASS |TTERRNO , -"Got expected error" ); - }else if (TEST_ERRNO ==ENOSYS ) { -tst_resm (TCONF , -"You may need to make CONFIG_SYSCTL_SYSCALL=y" -" to your kernel config." ); - }else { -tst_resm (TFAIL |TTERRNO , -"Got unexpected error" ); - } - } - -cleanup (); - - }else { -/* wait for the child to finish */ -wait (&status); - } - -/* set process ID back to root */ -SAFE_SETEUID (cleanup,0 ); - } -cleanup (); -tst_exit (); } -void setup (void ) +static void do_test (void ) { -tst_require_root (); - -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} +pid_t pid; +struct passwd *ltpuser; -void cleanup (void ) -{ + pid =SAFE_FORK (); +if (!pid) { + ltpuser =SAFE_GETPWNAM ("nobody" ); +SAFE_SETUID (ltpuser->pw_uid); +verify_sysctl (); + }else { +SAFE_WAIT (NULL ); +verify_sysctl (); + } } -#else -int TST_TOTAL =0 ; - -int main (void ) -{ - -tst_brkm (TCONF ,NULL , -"This test needs a kernel that has sysctl syscall." ); -} -#endif +static struct tst_test test = { + .needs_root =1 , + .forks_child =1 , + .setup = setup, + .test_all = do_test, +};
Signature · 1 line
1.8.3.1
PATCH 4/4 syscalls/sysctl04,05: Enable && Cleanup
In reply to Xiao Yang1) Undefined __NR_sysctl always skips the test even though CONFIG_SYSCTL_SYSCALL is built, so enable it by correct __NR__sysctl.
2) Convert to new API.
3) Merge sysctl05 into sysctl04.
--- runtest/ltplite | 1 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/sysctl/sysctl04.c | 192 ++++++++------------------- testcases/kernel/syscalls/sysctl/sysctl05.c | 193 ---------------------------- 6 files changed, 51 insertions(+), 338 deletions(-) delete mode 100644 testcases/kernel/syscalls/sysctl/sysctl05.c
runtest/ltplite +0 -1
@@ -915,7 +915,6 @@ sysconf01 sysconf01 sysctl01 sysctl01 sysctl03 sysctl03 sysctl04 sysctl04 -sysctl05 sysctl05 sysfs01 sysfs01 sysfs02 sysfs02
runtest/stress.part3 +0 -1
@@ -804,7 +804,6 @@ sysconf01 sysconf01 sysctl01 sysctl01 sysctl03 sysctl03 sysctl04 sysctl04 -sysctl05 sysctl05 sysfs01 sysfs01 sysfs02 sysfs02
runtest/syscalls +0 -1
@@ -1316,7 +1316,6 @@ sysconf01 sysconf01 sysctl01 sysctl01 sysctl03 sysctl03 sysctl04 sysctl04 -sysctl05 sysctl05 sysfs01 sysfs01 sysfs02 sysfs02
testcases/kernel/syscalls/.gitignore +0 -1
@@ -1037,7 +1037,6 @@ /sysctl/sysctl01 /sysctl/sysctl03 /sysctl/sysctl04 -/sysctl/sysctl05 /sysfs/sysfs01 /sysfs/sysfs02 /sysfs/sysfs03
testcases/kernel/syscalls/sysctl/sysctl04.c +51 -141
217 lines not on this page · raw message
testcases/kernel/syscalls/sysctl/sysctl05.c deleted +0 -193
193 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 1/4 lapi/syscalls: Add syscall numbers for _sysctl
In reply to Xiao YangHi!
Patchset pushed with cosmetic changes (such as printing expected errno on test failure), thanks.
Signature · 2 lines
Cyril Hrubis [email protected]