Print this page
11838 secflag tests are racy

@@ -11,21 +11,28 @@
 # http://www.illumos.org/license/CDDL.
 #
 
 #
 # Copyright 2015, Richard Lowe.
+# Copyright 2019 Joyent, Inc.
 #
 
+# check secflags, waiting a little bit for the change to happen
+secflags() {
+    sleep 1
+    /usr/bin/psecflags $*
+}
+
 mkdir /tmp/$$-secflags-test
 cd /tmp/$$-secflags-test
 
 /usr/bin/psecflags -s none $$   # Clear ourselves out
 cat > expected <<EOF
         I:      none
 EOF
 
-/usr/bin/psecflags $$ | grep I: > output
+secflags $$ | grep I: > output
 diff -u expected output || exit 1 # Make sure the setting of 'none' worked
 
 cleanup() {
     cd /
     rm -fr /tmp/$$-secflags-test

@@ -40,11 +47,11 @@
 
     cat > expected <<EOF
         I:      aslr
 EOF
 
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
 self_add() {
     echo "Add (self)"

@@ -51,11 +58,11 @@
     /usr/bin/psecflags -s current,noexecstack $$
     cat > expected <<EOF
         I:      aslr,noexecstack
 EOF
 
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
 self_remove() {
     echo "Remove (self)"

@@ -62,28 +69,28 @@
     /usr/bin/psecflags -s current,-aslr $$
     cat > expected <<EOF
         I:      noexecstack
 EOF
 
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
 self_all() {
     echo "All (self)"
     /usr/bin/psecflags -s all $$
-    /usr/bin/psecflags $$ | grep -q 'I:.*,.*,' || exit 1 # This is lame, but functional
+    secflags $$ | grep -q 'I:.*,.*,' || exit 1 # This is lame, but functional
 }
 
 self_none() {
     echo "None (self)"
     /usr/bin/psecflags -s all $$
     /usr/bin/psecflags -s none $$
     cat > expected <<EOF
         I:      none
 EOF
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
 child_set() {
     echo "Set (child)"

@@ -94,11 +101,11 @@
     pid=$!
     cat > expected <<EOF
         E:      aslr
         I:      aslr
 EOF
-    /usr/bin/psecflags $pid | grep '[IE]:' > output
+    secflags $pid | grep '[IE]:' > output
     kill $pid
     diff -u expected output || exit 1
 }
 
 child_add() {

@@ -111,11 +118,11 @@
     pid=$!
     cat > expected <<EOF
         E:      aslr,noexecstack
         I:      aslr,noexecstack
 EOF
-    /usr/bin/psecflags $pid | grep '[IE]:' > output
+    secflags $pid | grep '[IE]:' > output
     kill $pid
     /usr/bin/psecflags -s none $$
     diff -u expected output || exit 1
 }
 

@@ -129,11 +136,11 @@
     pid=$!
     cat > expected <<EOF
         E:      none
         I:      none
 EOF
-    /usr/bin/psecflags $pid | grep '[IE]:' > output
+    secflags $pid | grep '[IE]:' > output
     kill $pid
     /usr/bin/psecflags -s none $$
     diff -u expected output || exit 1
 }
 

@@ -142,11 +149,11 @@
 
     typeset pid ret
 
     /usr/bin/psecflags -s all -e sleep 10000 &
     pid=$!
-    /usr/bin/psecflags $pid | grep -q 'E:.*,.*,' # This is lame, but functional
+    secflags $pid | grep -q 'E:.*,.*,' # This is lame, but functional
     ret=$?
     kill $pid
     (( $ret != 0 )) && exit $ret
 }
 

@@ -161,11 +168,11 @@
     pid=$!
     cat > expected <<EOF
         E:      none
         I:      none
 EOF
-    /usr/bin/psecflags $pid | grep '[IE]:' > output
+    secflags $pid | grep '[IE]:' > output
     kill $pid
     diff -u expected output || exit 1
 }
 
 list() {