syscalls/vhangup: convert to new lib, use direct syscall
PATCH 1/1 syscalls/vhangup: convert to new lib, use direct syscall
Use direct syscall to expand test compatibility to Android.
Signed-off-by Steve Muckle <[email protected]>
--- testcases/kernel/syscalls/vhangup/vhangup01.c | 89 +++++-------- testcases/kernel/syscalls/vhangup/vhangup02.c | 123 ++++-------------- 2 files changed, 53 insertions(+), 159 deletions(-)
testcases/kernel/syscalls/vhangup/vhangup01.c +29 -60
@@ -1,23 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 * 07/2001 John George * Copyright (C) 2015 Cyril Hrubis <[email protected]> * -* 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 -*/ -/* * Check the return value, and errno of vhangup(2) when a non-root user calls * vhangup(). */
@@ -26,64 +12,47 @@#include <pwd.h> #include <sys/wait.h> -#include "test.h" -#include "safe_macros.h" - -static void setup (void ); - -char *TCID ="vhangup01" ; -int TST_TOTAL =1 ; +#include "tst_test.h" +#include "lapi/syscalls.h" static uid_t nobody_uid; -int main (int argc,char **argv) +static void run (void ) { -int lc; -pid_t pid;int retval; -tst_parse_opts (argc, argv,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -if ((pid =FORK_OR_VFORK ()) <0 ) { -tst_brkm (TFAIL ,NULL ,"fork failed" ); - }else if (pid >0 ) { -tst_record_childstatus (NULL , pid); - }else { - retval =setreuid (nobody_uid, nobody_uid); -if (retval <0 ) { -perror ("setreuid" ); -tst_brkm (TFAIL ,NULL ,"setreuid failed" ); - } -TEST (vhangup ()); -if (TEST_RETURN !=-1 ) { -tst_brkm (TFAIL ,NULL ,"vhangup() failed to " -"fail" ); - }else if (TEST_ERRNO ==EPERM ) { -tst_resm (TPASS ,"Got EPERM as expected." ); - }else { -tst_resm (TFAIL ,"expected EPERM got %d" , -TEST_ERRNO ); - } - } +if ((pid =SAFE_FORK ()) <0 ) { +tst_brk (TBROK |TTERRNO ,"fork failed" ); + }else if (pid >0 ) { +/* parent */ +waitpid (pid,NULL ,0 ); + }else { +/* child */ + retval =setreuid (nobody_uid, nobody_uid); +if (retval <0 ) +tst_brk (TBROK |TTERRNO ,"setreuid failed" ); +TEST (tst_syscall (__NR_vhangup)); +if (TST_RET !=-1 ) +tst_brk (TFAIL ,"vhangup() failed to fail" ); +else if (TST_ERR ==EPERM ) +tst_res (TPASS ,"Got EPERM as expected." ); +else +tst_res (TFAIL ,"expected EPERM got %d" ,TST_ERR ); } - -tst_exit (); }static void setup (void ) {struct passwd *pw; -tst_require_root (); - - pw =SAFE_GETPWNAM (NULL ,"nobody" ); + pw =SAFE_GETPWNAM ("nobody" ); nobody_uid = pw->pw_uid; - -TEST_PAUSE ; } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root =1 , + .forks_child =1 , +};
testcases/kernel/syscalls/vhangup/vhangup02.c +24 -99
142 lines not on this page · raw message
Signature · 1 line
2.20.1.495.gaa96b0ce6b-goog
PATCH 1/1 syscalls/vhangup: convert to new lib, use direct syscall
Hi!
testcases/kernel/syscalls/vhangup/vhangup01.c line 26
Quoted 2 lines
testcases/kernel/syscalls/vhangup/vhangup01.c +2
-0+if ((pid =SAFE_FORK ()) <0 ) { +tst_brk (TBROK |TTERRNO ,"fork failed" );
I've removed this pid < 0 check, since the whole point of SAFE_* macros is that the call will either succeed or exit the test.
testcases/kernel/syscalls/vhangup/vhangup01.c line 31
Quoted 5 lines
testcases/kernel/syscalls/vhangup/vhangup01.c +5
-0+ }else if (pid >0 ) { +/* parent */ +waitpid (pid,NULL ,0 ); + }else { +/* child */
And also these useless /* parent */ and /* child */ comments.
And pushed, thanks!
Signature · 2 lines
Cyril Hrubis [email protected]