UTIMENSAT test fails hugely
Review
Quoted 8 lines · ----- "Garrett Cooper
Almost there :). Some comments:
(quoted diff) +1
-0+ trap 'trap EXIT; teardown' EXITShould be:
(quoted diff) +1
-0+ trap 'trap "" EXIT; teardown' EXIT
Thanks for the tip :-) If I understood correctly, the EXIT signal is triggered when the program terminates(like after an `exit' command). I find that resetting the signal to original disposition and ignoring the signal have the same effect since the program is always ready to terminate after finishing the handler execution. Thus I think using trap EXIT', trap - EXIT' and `trap "" EXIT' all work.
Cheers,
Caspar
Quoted 55 lines
The double quotes tell the shell to ignore all future signals trapped for the EXIT event (from bash(1)'s trap section, but the same also applies for ash(1), which is the predecessor to dash ):
...
If arg is absent (and there is a
single sigspec) or -, each specified signal is
reset to its
original disposition (the value it had upon entrance
to the
shell). If arg is the null string the signal specified
by each
sigspec is ignored by the shell and by the commands it
invokes....
The `set' sed could be like this:
pattern="[[:space:]]*Defaults[[:space:]]*requiretty.*" sed -E -i "" -e "s/^($pattern)/#\1/" /etc/sudoersThe restore sed could be like this:
sed -E -i "" -e "s/^#($pattern)/\1/" /etc/sudoers # with $pattern being set like before.Don't forget the ^ anchors and the quoting's important :).
Quoted 2 lines
Quoted 2 lines
You may want to execute the handler before the setup call is
invoked
Quoted 1 line
Quoted 1 line
to ensure that everything done is properly undone in the event of
a
Quoted 11 lines
Quoted 11 lines
failure during setup.
Also, watch out for cases where a user may have done:# requirettyinstead of:
requiretty
It probably would be wise to preserve all leading and trailing
characters for teardown to avoid inadvertently enabling requirettyin
Quoted 2 lines
Quoted 2 lines
sudo.
The EXIT trap handler isn't 100% foolproof, but it protectsagainst
Quoted 1 line
Quoted 1 line
all but SIGKILL or SIGSTOP from being executed as they're NMIs.
Cheers,
-Garrett
Signature · 15 lines
Kernel Associate Quality Engineer Red Hat Inc. (Beijing R&D Branch) Red Hat China R&D Branch Unit 907, North Tower C, Raycom Infotech Park, No.2 Kexueyuan Nanlu, Haidian District, Beijing 100190 TEL: +86-10-62608150 Web: http://www.redhat.com/ ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 9 lines · Caspar ZHANG
Quoted 7 lines · ----- "Garrett Cooper
Almost there :). Some comments:
(quoted diff) +1
-0+ trap 'trap EXIT; teardown' EXITShould be:
Quoted 9 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ trap 'trap "" EXIT; teardown' EXITThanks for the tip :-) If I understood correctly, the EXIT signal is triggered when the program terminates(like after an `exit' command). I find that resetting the signal to original disposition and ignoring the signal have the same effect since the program is always ready to terminate after finishing the handler execution. Thus I think using
trap EXIT',trap - EXIT' and `trap "" EXIT' all work.
The first item is different from the other two. The first one ignores the signal (SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.
Quoted 45 lines
Quoted 45 lines
The double quotes tell the shell to ignore all future signals trapped for the EXIT event (from bash(1)'s trap section, but the same also applies for ash(1), which is the predecessor to dash ):
...
If arg is absent (and there is a
single sigspec) or -, each specified signal is
reset to its
original disposition (the value it had upon entrance
to the
shell). If arg is the null string the signal specified
by each
sigspec is ignored by the shell and by the commands it
invokes....
The `set' sed could be like this:
pattern="[[:space:]]*Defaults[[:space:]]*requiretty.*" sed -E -i "" -e "s/^($pattern)/#\1/" /etc/sudoersThe restore sed could be like this:
sed -E -i "" -e "s/^#($pattern)/\1/" /etc/sudoers # with $pattern being set like before.Don't forget the ^ anchors and the quoting's important :).
Quoted 2 lines
Quoted 2 lines
You may want to execute the handler before the setup call is
invoked
Quoted 1 line
Quoted 1 line
to ensure that everything done is properly undone in the event of
a
Quoted 9 lines
Quoted 9 lines
failure during setup.
Also, watch out for cases where a user may have done:# requirettyinstead of:
requiretty
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
It probably would be wise to preserve all leading and trailing
characters for teardown to avoid inadvertently enabling requirettyin
Quoted 2 lines
Quoted 2 lines
sudo.
The EXIT trap handler isn't 100% foolproof, but it protectsagainst
Quoted 1 line
Quoted 1 line
all but SIGKILL or SIGSTOP from being executed as they're NMIs.
Thanks,
-Garrett
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 4 lines · Garrett Cooper
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.
I see. Thank you.
The final patch ;-)
Cheers,
-Caspar
Signature · 6 lines
Tags: Ant, Beijing, BUPT, Caspar, Kernel QA, Linux, Open Source, Photography, Programmer, Red Hat Inc., Zhejianger, etc. Current: Kernel Associate Quality Engineer @ Red Hat Inc. Home Page: http://www.CasparZhang.com/
Hi,
Most automated testing systems have no tty when running tests, so the utimensat01 test may fail with the following error msg:
sudo: sorry, you must have a tty to run sudo
to avoid this, commenting `Defaults requiretty' line in
/etc/sudoers can make this testcase work. After test finished, restore this line.
---
testcases/kernel/syscalls/utimensat/utimensat_tests.sh +17 -0
@@ -43,6 +43,23 @@ exit 1; fi +# Since some automated testing systems have no tty while testing, +# comment this line in /etc/sudoers to avoid the error message: +# `sudo: sorry, you must have a tty to run sudo' +# Use trap to restore this line after program terminates. +pattern="[[:space:]]*Defaults[[:space:]]*requiretty.*" +if grep -q "^${pattern}" /etc/sudoers; then + echo "${TEST_PROG} 0 INFO : Comment requiretty in /etc/sudoers for automated testing systems" + sed -E -i"" -e "s/^($pattern)/#\1/" /etc/sudoers + trap 'trap "" EXIT; teardown' EXIT +fi + +teardown() +{ + echo "${TEST_PROG} 0 INFO : Restore requiretty in /etc/sudoers" + sed -E -i"" -e "s/^#($pattern)/\1/" /etc/sudoers +} + # Summary counters of all test results test_num=0
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Henry Yei <[email protected]>
Quoted 19 lines · Caspar Zhang
Quoted 4 lines · Garrett Cooper
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
Cheers,
-Caspar--
Tags: Ant, Beijing, BUPT, Caspar, Kernel QA, Linux, Open Source, Photography, Programmer, Red Hat Inc., Zhejianger, etc.Current: Kernel Associate Quality Engineer @ Red Hat Inc.
Quoted 10 lines
Home Page: http://www.CasparZhang.com/
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 5 lines · Henry Yei
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Quoted 10 lines
Quoted 9 lines · Caspar Zhang
Quoted 4 lines · Garrett Cooper
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
If it:
1. Works in all cases, i.e. doesn't use version specific constructs for sudo (which I haven't seen thus far, but just to be safe).
2. Is properly reverted when the test is done (which includes the following scenarios):
a. File already exists. Backup the old file, revert it when the
test is completed (regardless of whether or not the test passed or the test failed properly [*]).
b. File doesn't exist. Nuke the file after the test is done.
... sure.
Thanks,
-Garrett
[*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
If a sudo file exists, the patch doesn't touch it. If it does not, a sudoers file will be created and then it will remove it afterwards. I wouldn't feel confortable having a script modify a sudoers file if it already exists. The sudoers content that it does put in place just enables the root user to use sudo, which would not give it any more access than it already has. This text is available in every sudoers file I've looked at.
While I was testing the patch with the ltp-dev branch, I noticed that the -n option was put in front of every sudo call in commit 2aa40f7e10518977881b933cc93b8f50847cf3cf in order to suppress the interactive password check.
However, neither sudo 1.6.8p12 from MontaVista Linux 6 or 1.6.9p17 from Ubuntu 9.04 supports the -n option. The patch also removes the -n option from sudo calls. This option was added in 3/2008.
Quoted 28 lines · Garrett Cooper
Quoted 5 lines · Henry Yei
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Quoted 10 lines
Quoted 9 lines · Caspar Zhang
Quoted 4 lines · Garrett Cooper
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
If it:
1. Works in all cases, i.e. doesn't use version specific constructs for sudo (which I haven't seen thus far, but just to be safe).
2. Is properly reverted when the test is done (which includes the following scenarios):
a. File already exists. Backup the old file, revert it when the test is completed (regardless of whether or not the test passed or the test failed properly [*]).
b. File doesn't exist. Nuke the file after the test is done.
Quoted 6 lines
... sure.
Thanks,
-Garrett[*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
testcases/kernel/syscalls/utimensat/utimensat_tests.sh +33 -17
@@ -64,41 +64,41 @@ setup_file() # Make sure any old version of file is deleted if test -e $FILE; then - sudo -n chattr -ai $FILE || return $? - sudo -n rm -f $FILE || return $? + sudo chattr -ai $FILE || return $? + sudo rm -f $FILE || return $? fi # Create file and make atime and mtime zero. - sudo -n -u $user_tester touch $FILE || return $? + sudo -u $user_tester touch $FILE || return $? if ! $TEST_PROG -q $FILE 0 0 0 0 > $RESULT_FILE; then echo "Failed to set up test file $FILE" 1>&2 - exit 1 + cleanup_test fi read res atime mtime < $RESULT_FILE if test "X$res" != "XSUCCESS" || test $atime -ne 0 || test $mtime != 0; then echo "Failed to set correct times on test file $FILE" 1>&2 - exit 1 + cleanup_test fi # Set owner, permissions, and EFAs for file. if test -n "$2"; then - sudo -n chown $2 $FILE || return $? + sudo chown $2 $FILE || return $? fi - sudo -n chmod $3 $FILE || return $? + sudo chmod $3 $FILE || return $? if test -n "$4"; then - sudo -n chattr $4 $FILE || return $? + sudo chattr $4 $FILE || return $? fi # Display file setup, for visual verification ls -l $FILE | awk '{ printf "Owner=%s; perms=%s; ", $3, $1}' - if ! sudo -n lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' + if ! sudo lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' then return $? fi
@@ -126,7 +126,7 @@ check_result() if test $STATUS -gt 1; then echo "FAILED (bad test setup)" - exit 1 + cleanup_test fi read res atime mtime < $RESULT_FILE
@@ -204,7 +204,7 @@ run_test() W) do_write_fd_test=0 ;; *) echo "run_test: bad usage" - exit 1 + cleanup_test ;; esac done
@@ -215,7 +215,7 @@ run_test() cp $LTPROOT/testcases/bin/$TEST_PROG ./ CMD="./$TEST_PROG -q $FILE $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo
@@ -224,7 +224,7 @@ run_test() setup_file $FILE "$1" "$2" "$3" CMD="./$TEST_PROG -q -d $FILE NULL $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo fi
@@ -237,18 +237,33 @@ run_test() setup_file $FILE "$1" "$2" "$3" CMD="./$TEST_PROG -q -w -d $FILE NULL $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo fi - sudo -n chattr -ai $FILE - sudo -n rm -f $FILE + sudo chattr -ai $FILE + sudo rm -f $FILE +} + +cleanup_test() +{ + if test $sudoers_clean + then + sudo rm -f $sudoers + fi } #===================================================================== user_tester=nobody -sudo -n -u $user_tester mkdir -p $TEST_DIR +sudoers=/etc/sudoers +if test ! -e $sudoers +then + echo "root ALL=(ALL) ALL" > $sudoers + sudoers_clean=1 + chmod 440 $sudoers +fi +sudo -u $user_tester mkdir -p $TEST_DIR cd $TEST_DIR chown root $LTPROOT/testcases/bin/$TEST_PROG chmod ugo+x,u+s $LTPROOT/testcases/bin/$TEST_PROG
@@ -437,6 +452,7 @@ echo "================================== echo +cleanup_test rm -rf "$TEST_DIR" uname -a date
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 10 lines · Henry Yei
If a sudo file exists, the patch doesn't touch it. If it does not, a sudoers file will be created and then it will remove it afterwards. I wouldn't feel confortable having a script modify a sudoers file if it already exists. The sudoers content that it does put in place just enables the root user to use sudo, which would not give it any more access than it already has. This text is available in every sudoers file I've looked at.
Quoted 8 lines
While I was testing the patch with the ltp-dev branch, I noticed that the -n option was put in front of every sudo call in commit
2aa40f7e10518977881b933cc93b8f50847cf3cfin order to suppress the interactive password check.However, neither sudo 1.6.8p12 from MontaVista Linux 6 or 1.6.9p17 from Ubuntu 9.04 supports the -n option. The patch also removes the -n option from sudo calls. This option was added in 3/2008.
Ugh. The sudo in gentoo did this though and that's the reason why I added it in some scripts -- otherwise the pieces of junk halt waiting for user input and I had manually kill the scripts >:(... I guess a test will need to be added to ensure that sudo _does_ have the -n option beforehand, if it does, add the -n option. Otherwise all people running older versions are kind of SoL.
sudo is still a non-standard tool and a pain in the butt to deal with in scripts as it changes from time to time.
FWIW your patch only deals with the case when the script `exits cleanly' as there aren't any traps installed for cleanup_test.
Quoted 29 lines · Garrett Cooper
Quoted 28 lines · Henry Yei
Quoted 5 lines
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Quoted 10 lines
Quoted 9 lines · Caspar Zhang
Quoted 4 lines · Garrett Cooper
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
If it:
1. Works in all cases, i.e. doesn't use version specific constructs for sudo (which I haven't seen thus far, but just to be safe).
2. Is properly reverted when the test is done (which includes the following scenarios):
a. File already exists. Backup the old file, revert it when the test is completed (regardless of whether or not the test passed or the test failed properly [*]).
b. File doesn't exist. Nuke the file after the test is done.
Quoted 5 lines
Quoted 5 lines
... sure.
Thanks,
-Garrett[*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
Thanks,
-Garrett
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Garrett,
This patch installs the trap for cleanup_test which removes the sudoers file only if it was installed by utimensat script, and also takes care of detecting whether sudo knows about the -n option.
The patch was generated from ltp-dev git tree.
I didn't realize Caspar's patch hadn't already been incorporated yet, so didn't account for it.
Henry Yei <[email protected]>
Quoted 62 lines · Garrett Cooper
Quoted 10 lines · Henry Yei
If a sudo file exists, the patch doesn't touch it. If it does not, a sudoers file will be created and then it will remove it afterwards. I wouldn't feel confortable having a script modify a sudoers file if it already exists. The sudoers content that it does put in place just enables the root user to use sudo, which would not give it any more access than it already has. This text is available in every sudoers file I've looked at.
Quoted 8 lines
While I was testing the patch with the ltp-dev branch, I noticed that the -n option was put in front of every sudo call in commit
2aa40f7e10518977881b933cc93b8f50847cf3cfin order to suppress the interactive password check.However, neither sudo 1.6.8p12 from MontaVista Linux 6 or 1.6.9p17 from Ubuntu 9.04 supports the -n option. The patch also removes the -n option from sudo calls. This option was added in 3/2008.
Ugh. The sudo in gentoo did this though and that's the reason why I added it in some scripts -- otherwise the pieces of junk halt waiting for user input and I had manually kill the scripts >:(... I guess a test will need to be added to ensure that sudo _does_ have the -n option beforehand, if it does, add the -n option. Otherwise all people running older versions are kind of SoL.
sudo is still a non-standard tool and a pain in the butt to deal with in scripts as it changes from time to time.
FWIW your patch only deals with the case when the script `exits cleanly' as there aren't any traps installed for
cleanup_test.Quoted 29 lines · Garrett Cooper
Quoted 28 lines · Henry Yei
Quoted 5 lines
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Quoted 10 lines
Quoted 9 lines · Caspar Zhang
Quoted 4 lines · Garrett Cooper
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
If it:
1. Works in all cases, i.e. doesn't use version specific constructs for sudo (which I haven't seen thus far, but just to be safe).
2. Is properly reverted when the test is done (which includes the following scenarios):
a. File already exists. Backup the old file, revert it when the test is completed (regardless of whether or not the test passed or the test failed properly [*]).
b. File doesn't exist. Nuke the file after the test is done.
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
... sure.
Thanks,
-Garrett[*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
Thanks,
-Garrett
testcases/kernel/syscalls/utimensat/utimensat_tests.sh +38 -13
@@ -64,13 +64,13 @@ setup_file() # Make sure any old version of file is deleted if test -e $FILE; then - sudo -n chattr -ai $FILE || return $? - sudo -n rm -f $FILE || return $? + sudo $s_arg chattr -ai $FILE || return $? + sudo $s_arg rm -f $FILE || return $? fi # Create file and make atime and mtime zero. - sudo -n -u $user_tester touch $FILE || return $? + sudo $s_arg -u $user_tester touch $FILE || return $? if ! $TEST_PROG -q $FILE 0 0 0 0 > $RESULT_FILE; then echo "Failed to set up test file $FILE" 1>&2 exit 1
@@ -86,19 +86,19 @@ setup_file() # Set owner, permissions, and EFAs for file. if test -n "$2"; then - sudo -n chown $2 $FILE || return $? + sudo $s_arg chown $2 $FILE || return $? fi - sudo -n chmod $3 $FILE || return $? + sudo $s_arg chmod $3 $FILE || return $? if test -n "$4"; then - sudo -n chattr $4 $FILE || return $? + sudo $s_arg chattr $4 $FILE || return $? fi # Display file setup, for visual verification ls -l $FILE | awk '{ printf "Owner=%s; perms=%s; ", $3, $1}' - if ! sudo -n lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' + if ! sudo $s_arg lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' then return $? fi
@@ -215,7 +215,7 @@ run_test() cp $LTPROOT/testcases/bin/$TEST_PROG ./ CMD="./$TEST_PROG -q $FILE $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo $s_arg -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo
@@ -224,7 +224,7 @@ run_test() setup_file $FILE "$1" "$2" "$3" CMD="./$TEST_PROG -q -d $FILE NULL $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo $s_arg -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo fi
@@ -237,18 +237,43 @@ run_test() setup_file $FILE "$1" "$2" "$3" CMD="./$TEST_PROG -q -w -d $FILE NULL $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo $s_arg -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo fi - sudo -n chattr -ai $FILE - sudo -n rm -f $FILE + sudo $s_arg chattr -ai $FILE + sudo $s_arg rm -f $FILE +} + +cleanup_test() +{ + if test $sudoers_clean; then + sudo rm -f $sudoers + fi } #===================================================================== user_tester=nobody -sudo -n -u $user_tester mkdir -p $TEST_DIR +echo "test sudo for -n option, non-interactive" +sudo -n true +if test $? -eq 0; then + s_arg="-n" + echo "sudo supports -n" +else + s_arg= + echo "sudo does not support -n" +fi +sudoers=/etc/sudoers +if test ! -e $sudoers +then + echo "root ALL=(ALL) ALL" > $sudoers + sudoers_clean=1 + chmod 440 $sudoers + trap 'trap "" EXIT; cleanup_test' EXIT +fi + +sudo $s_arg -u $user_tester mkdir -p $TEST_DIR cd $TEST_DIR chown root $LTPROOT/testcases/bin/$TEST_PROG chmod ugo+x,u+s $LTPROOT/testcases/bin/$TEST_PROG
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Hi,
I just wanted to see if there was still interest in the patch from this thread last month.
Henry Yei <[email protected]>
Quoted 11 lines · Henry Yei
Garrett,
This patch installs the trap for
cleanup_testwhich removes the sudoers file only if it was installed by utimensat script, and also takes care of detecting whether sudo knows about the -n option.Signed-off-by <[email protected]>The patch was generated from ltp-dev git tree.
Quoted 79 lines
I didn't realize Caspar's patch hadn't already been incorporated yet, so didn't account for it.
Henry Yei <[email protected]>
Quoted 72 lines · Garrett Cooper
Quoted 10 lines · Henry Yei
If a sudo file exists, the patch doesn't touch it. If it does not, a sudoers file will be created and then it will remove it afterwards. I wouldn't feel confortable having a script modify a sudoers file if it already exists. The sudoers content that it does put in place just enables the root user to use sudo, which would not give it any more access than it already has. This text is available in every sudoers file I've looked at.
Quoted 8 lines
While I was testing the patch with the ltp-dev branch, I noticed that the -n option was put in front of every sudo call in commit
2aa40f7e10518977881b933cc93b8f50847cf3cfin order to suppress the interactive password check.However, neither sudo 1.6.8p12 from MontaVista Linux 6 or 1.6.9p17 from Ubuntu 9.04 supports the -n option. The patch also removes the -n option from sudo calls. This option was added in 3/2008.
Ugh. The sudo in gentoo did this though and that's the reason why I added it in some scripts -- otherwise the pieces of junk halt waiting for user input and I had manually kill the scripts >:(... I guess a test will need to be added to ensure that sudo _does_ have the -n option beforehand, if it does, add the -n option. Otherwise all people running older versions are kind of SoL.
sudo is still a non-standard tool and a pain in the butt to deal with in scripts as it changes from time to time.
FWIW your patch only deals with the case when the script `exits cleanly' as there aren't any traps installed for
cleanup_test.Quoted 7 lines · Garrett Cooper
Quoted 6 lines · Henry Yei
Quoted 5 lines
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Quoted 1 line
Quoted 1 line
Thanks,
-GarrettQuoted 27 lines
Quoted 27 lines
Quoted 10 lines · Caspar Zhang
Quoted 9 lines · Garrett Cooper
Quoted 4 lines
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
If it:
1. Works in all cases, i.e. doesn't use version specific constructs for sudo (which I haven't seen thus far, but just to be safe).
2. Is properly reverted when the test is done (which includes the following scenarios):
a. File already exists. Backup the old file, revert it when the test is completed (regardless of whether or not the test passed or the test failed properly [*]).
b. File doesn't exist. Nuke the file after the test is done.... sure.
Thanks,
-Garrett[*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
testcases/kernel/syscalls/utimensat/utimensat_tests.sh +38 -13
@@ -64,13 +64,13 @@ setup_file() # Make sure any old version of file is deleted if test -e $FILE; then - sudo -n chattr -ai $FILE || return $? - sudo -n rm -f $FILE || return $? + sudo $s_arg chattr -ai $FILE || return $? + sudo $s_arg rm -f $FILE || return $? fi # Create file and make atime and mtime zero. - sudo -n -u $user_tester touch $FILE || return $? + sudo $s_arg -u $user_tester touch $FILE || return $? if ! $TEST_PROG -q $FILE 0 0 0 0 > $RESULT_FILE; then echo "Failed to set up test file $FILE" 1>&2 exit 1
@@ -86,19 +86,19 @@ setup_file() # Set owner, permissions, and EFAs for file. if test -n "$2"; then - sudo -n chown $2 $FILE || return $? + sudo $s_arg chown $2 $FILE || return $? fi - sudo -n chmod $3 $FILE || return $? + sudo $s_arg chmod $3 $FILE || return $? if test -n "$4"; then - sudo -n chattr $4 $FILE || return $? + sudo $s_arg chattr $4 $FILE || return $? fi # Display file setup, for visual verification ls -l $FILE | awk '{ printf "Owner=%s; perms=%s; ", $3, $1}' - if ! sudo -n lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' + if ! sudo $s_arg lsattr -l $FILE | sed 's/, /,/g' | awk '{print "EFAs=" $2}' then return $? fi
@@ -215,7 +215,7 @@ run_test() cp $LTPROOT/testcases/bin/$TEST_PROG ./ CMD="./$TEST_PROG -q $FILE $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo $s_arg -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo
@@ -224,7 +224,7 @@ run_test() setup_file $FILE "$1" "$2" "$3" CMD="./$TEST_PROG -q -d $FILE NULL $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo $s_arg -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo fi
@@ -237,18 +237,43 @@ run_test() setup_file $FILE "$1" "$2" "$3" CMD="./$TEST_PROG -q -w -d $FILE NULL $4" echo "$CMD" - sudo -n -u $user_tester $CMD > $RESULT_FILE + sudo $s_arg -u $user_tester $CMD > $RESULT_FILE check_result $? $5 $6 $7 echo fi - sudo -n chattr -ai $FILE - sudo -n rm -f $FILE + sudo $s_arg chattr -ai $FILE + sudo $s_arg rm -f $FILE +} + +cleanup_test() +{ + if test $sudoers_clean; then + sudo rm -f $sudoers + fi } #===================================================================== user_tester=nobody -sudo -n -u $user_tester mkdir -p $TEST_DIR +echo "test sudo for -n option, non-interactive" +sudo -n true +if test $? -eq 0; then + s_arg="-n" + echo "sudo supports -n" +else + s_arg= + echo "sudo does not support -n" +fi +sudoers=/etc/sudoers +if test ! -e $sudoers +then + echo "root ALL=(ALL) ALL" > $sudoers + sudoers_clean=1 + chmod 440 $sudoers + trap 'trap "" EXIT; cleanup_test' EXIT +fi + +sudo $s_arg -u $user_tester mkdir -p $TEST_DIR cd $TEST_DIR chown root $LTPROOT/testcases/bin/$TEST_PROG chmod ugo+x,u+s $LTPROOT/testcases/bin/$TEST_PROG
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 4 lines · Henry Yei
Hi,
I just wanted to see if there was still interest in the patch from this thread last month.
Thanks. I was not aware of this patch. Checked in now.
Regards--
Subrata
Quoted 94 lines
Henry Yei <[email protected]>
Quoted 89 lines · Henry Yei
Garrett,
This patch installs the trap for
cleanup_testwhich removes the sudoers file only if it was installed by utimensat script, and also takes care of detecting whether sudo knows about the -n option.Signed-off-by <[email protected]>The patch was generated from ltp-dev git tree.
I didn't realize Caspar's patch hadn't already been incorporated yet, so didn't account for it.
Henry Yei <[email protected]>
Quoted 71 lines · Garrett Cooper
Quoted 10 lines · Henry Yei
If a sudo file exists, the patch doesn't touch it. If it does not, a sudoers file will be created and then it will remove it afterwards. I wouldn't feel confortable having a script modify a sudoers file if it already exists. The sudoers content that it does put in place just enables the root user to use sudo, which would not give it any more access than it already has. This text is available in every sudoers file I've looked at.
Quoted 8 lines
While I was testing the patch with the ltp-dev branch, I noticed that the -n option was put in front of every sudo call in commit
2aa40f7e10518977881b933cc93b8f50847cf3cfin order to suppress the interactive password check.However, neither sudo 1.6.8p12 from MontaVista Linux 6 or 1.6.9p17 from Ubuntu 9.04 supports the -n option. The patch also removes the -n option from sudo calls. This option was added in 3/2008.
Ugh. The sudo in gentoo did this though and that's the reason why I added it in some scripts -- otherwise the pieces of junk halt waiting for user input and I had manually kill the scripts >:(... I guess a test will need to be added to ensure that sudo _does_ have the -n option beforehand, if it does, add the -n option. Otherwise all people running older versions are kind of SoL.
sudo is still a non-standard tool and a pain in the butt to deal with in scripts as it changes from time to time.
FWIW your patch only deals with the case when the script `exits cleanly' as there aren't any traps installed for
cleanup_test.Quoted 7 lines · Garrett Cooper
Quoted 6 lines · Henry Yei
Quoted 5 lines
Speaking of the utimesat test and prerequisites, our test systems don't have a sudoers file by default, so we have an internal patch to utimesat to create a default one if non exist and remove it after the test is done. Would that be of interest to LTP?
Quoted 1 line
Quoted 1 line
Thanks,
-GarrettQuoted 26 lines
Quoted 26 lines
Quoted 10 lines · Caspar Zhang
Quoted 9 lines · Garrett Cooper
Quoted 4 lines
The first item is different from the other two. The first one ignores the signal (
SIG_IGN), whereas the latter two cases reset the handler to the default one (SIG_DFL). I prefer the former format, because otherwise the signal handlers become reentrable on accident.I see. Thank you.
The final patch ;-)
If it:
1. Works in all cases, i.e. doesn't use version specific constructs for sudo (which I haven't seen thus far, but just to be safe).
2. Is properly reverted when the test is done (which includes the following scenarios):
a. File already exists. Backup the old file, revert it when the
test is completed (regardless of whether or not the test passed or the test failed properly [*]).
b. File doesn't exist. Nuke the file after the test is done.... sure.Thanks,
-Garrett
Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
[*] SIGKILL or SIGSTOP can't be avoided, so technically it's a best effort.
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
This patch seemed not included in latest release?
Thanks,
Caspar
Quoted 24 lines · ----- "Caspar Zhang
Quoted 1 line · Garrett Cooper
The first item is different from the other two. The first one
ignores the
Quoted 1 line
signal (
SIG_IGN), whereas the latter two cases reset the handler tothe
Quoted 1 line
default one (
SIG_DFL). I prefer the former format, because otherwisethe
Quoted 1 line
signal handlers become reentrable on accident.
I see. Thank you.
The final patch ;-)
Cheers,
-CasparSignature · 6 lines
Tags: Ant, Beijing, BUPT, Caspar, Kernel QA, Linux, Open Source, Photography, Programmer, Red Hat Inc., Zhejianger, etc. Current: Kernel Associate Quality Engineer @ Red Hat Inc. Home Page: http://www.CasparZhang.com/
Signature · 8 lines
/---------------------------------------\ | Name: Caspar Zhang | | Team: Kernel-QE | | Timezone: GMT+0800 (Asia/Shanghai) | | IRC: caspar @ #kernel-qe, #eng-china | | Phone: +86-10-6260-8150 | | Cellphone: +86-1381-073-0090 | \---------------------------------------/
Hi,
Most automated testing systems have no tty when running tests, so the utimensat01 test may fail with the following error msg:
sudo: sorry, you must have a tty to run sudo
to avoid this, commenting `Defaults requiretty' line in
/etc/sudoers can make this testcase work. After test finished, restore this line.
---
testcases/kernel/syscalls/utimensat/utimensat_tests.sh +17 -0
@@ -43,6 +43,23 @@ exit 1; fi +# Since some automated testing systems have no tty while testing, +# comment this line in /etc/sudoers to avoid the error message: +# `sudo: sorry, you must have a tty to run sudo' +# Use trap to restore this line after program terminates. +pattern="[[:space:]]*Defaults[[:space:]]*requiretty.*" +if grep -q "^${pattern}" /etc/sudoers; then + echo "${TEST_PROG} 0 INFO : Comment requiretty in /etc/sudoers for automated testing systems" + sed -E -i"" -e "s/^($pattern)/#\1/" /etc/sudoers + trap 'trap "" EXIT; teardown' EXIT +fi + +teardown() +{ + echo "${TEST_PROG} 0 INFO : Restore requiretty in /etc/sudoers" + sed -E -i"" -e "s/^#($pattern)/\1/" /etc/sudoers +} + # Summary counters of all test results test_num=0
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list
Quoted 1 line · Caspar Zhang
This patch seemed not included in latest release?
Thanks for pointing that out. Pushed to git so that i do not forget again ;-)
Regards--
Subrata
Quoted 31 lines
Thanks,
CasparQuoted 8 lines · ----- "Caspar Zhang
Quoted 1 line · Garrett Cooper
The first item is different from the other two. The first one
ignores the
Quoted 1 line
signal (
SIG_IGN), whereas the latter two cases reset the handler tothe
Quoted 1 line
default one (
SIG_DFL). I prefer the former format, because otherwisethe
Quoted 16 lines
Quoted 1 line
signal handlers become reentrable on accident.
I see. Thank you.
The final patch ;-)
Cheers,
-CasparSignature · 6 lines
Tags: Ant, Beijing, BUPT, Caspar, Kernel QA, Linux, Open Source, Photography, Programmer, Red Hat Inc., Zhejianger, etc. Current: Kernel Associate Quality Engineer @ Red Hat Inc. Home Page: http://www.CasparZhang.com/
Quoted 7 lines
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list