--- old/usr/src/test/os-tests/tests/secflags/secflags_core.sh	Mon Oct 21 21:31:32 2019
+++ new/usr/src/test/os-tests/tests/secflags/secflags_core.sh	Mon Oct 21 21:31:32 2019
@@ -13,6 +13,7 @@
 
 #
 # Copyright 2015, Richard Lowe.
+# Copyright 2019 Joyent, Inc.
 #
 
 mkdir /tmp/secflags-test.$$
@@ -20,16 +21,26 @@
 
 /usr/bin/psecflags -s aslr -e sleep 100000 &
 pid=$!
-coreadm -p core $pid # We need to be able to reliably find the core
+# Make sure we generate a kernel core we can find
+coreadm -p core $pid
+enabled=$(/usr/bin/svcprop -p config_params/process_enabled coreadm)
+coreadm_restore=""
+if [[ "$enabled" = "false" ]]; then
+    coreadm_restore="/usr/bin/coreadm -d process"
+    coreadm -e process
+fi
 
 cleanup() {
     kill $pid >/dev/null 2>&1
     cd /
     rm -fr /tmp/secflags-test.$$
+
+    $coreadm_restore
 }
 
 trap cleanup EXIT
 
+sleep 1
 ## gcore-produced core
 gcore $pid >/dev/null
 
@@ -42,6 +53,7 @@
 /usr/bin/psecflags core.${pid} | grep -v '[LU]:' > gcore-output.$$
 
 if ! diff -u gcore-expected.$$ gcore-output.$$; then
+    $coreadm_restore
     exit 1;
 fi
 
@@ -48,6 +60,7 @@
 ## kernel-produced core
 kill -SEGV $pid
 wait $pid >/dev/null 2>&1
+$coreadm_restore
 
 cat > core-expected.$$ <<EOF
 core 'core' of $pid:	sleep 100000
--- old/usr/src/test/os-tests/tests/secflags/secflags_dts.sh	Mon Oct 21 21:31:32 2019
+++ new/usr/src/test/os-tests/tests/secflags/secflags_dts.sh	Mon Oct 21 21:31:32 2019
@@ -12,6 +12,7 @@
 #
 
 # Copyright 2015, Richard Lowe.
+# Copyright 2019 Joyent, Inc.
 
 tmpdir=/tmp/test.$$
 mkdir $tmpdir
@@ -51,6 +52,7 @@
 
     $bin &
     pid=$!
+    sleep 1
     psecflags $pid | grep -q "${set}:.*aslr"
     (( $? != $state )) && ret=1
     kill -9 $pid
--- old/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh	Mon Oct 21 21:31:33 2019
+++ new/usr/src/test/os-tests/tests/secflags/secflags_elfdump.sh	Mon Oct 21 21:31:33 2019
@@ -13,6 +13,7 @@
 
 #
 # Copyright 2015, Richard Lowe.
+# Copyright 2019 Joyent, Inc.
 #
 
 mkdir /tmp/secflags-test.$$
@@ -30,6 +31,9 @@
 
 trap cleanup EXIT
 
+# We need to wait for sleep to get exec()ed
+sleep 1
+
 ## gcore-produced core
 gcore $pid >/dev/null
 
--- old/usr/src/test/os-tests/tests/secflags/secflags_proc.sh	Mon Oct 21 21:31:34 2019
+++ new/usr/src/test/os-tests/tests/secflags/secflags_proc.sh	Mon Oct 21 21:31:34 2019
@@ -13,6 +13,7 @@
 
 #
 # Copyright 2015, Richard Lowe.
+# Copyright 2019 Joyent, Inc.
 #
 
 /usr/bin/psecflags -s aslr -e sleep 100000 &
@@ -32,6 +33,9 @@
 	I:	aslr
 EOF
 
+# We need to wait for sleep to get exec()ed
+sleep 1
+
 /usr/bin/psecflags $pid | grep -v '[LU]:' > /tmp/output.$$
 
 if ! diff -u /tmp/expected.$$ /tmp/output.$$; then
--- old/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh	Mon Oct 21 21:31:34 2019
+++ new/usr/src/test/os-tests/tests/secflags/secflags_psecflags.sh	Mon Oct 21 21:31:34 2019
@@ -13,8 +13,15 @@
 
 #
 # 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
 
@@ -23,7 +30,7 @@
 	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() {
@@ -42,7 +49,7 @@
 	I:	aslr
 EOF
 
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
@@ -53,7 +60,7 @@
 	I:	aslr,noexecstack
 EOF
 
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
@@ -64,7 +71,7 @@
 	I:	noexecstack
 EOF
 
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
@@ -71,7 +78,7 @@
 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() {
@@ -81,7 +88,7 @@
     cat > expected <<EOF
 	I:	none
 EOF
-    /usr/bin/psecflags $$ | grep I: > output
+    secflags $$ | grep I: > output
     diff -u expected output || exit 1
 }
 
@@ -88,7 +95,7 @@
 child_set() {
     echo "Set (child)"
 
-    typeset pid; 
+    typeset pid;
 
     /usr/bin/psecflags -s aslr -e sleep 10000 &
     pid=$!
@@ -96,7 +103,7 @@
 	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
 }
@@ -104,7 +111,7 @@
 child_add() {
     echo "Add (child)"
 
-    typeset pid; 
+    typeset pid;
 
     /usr/bin/psecflags -s aslr $$
     /usr/bin/psecflags -s current,noexecstack -e sleep 10000 &
@@ -113,7 +120,7 @@
 	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
@@ -122,7 +129,7 @@
 child_remove() {
     echo "Remove (child)"
 
-    typeset pid; 
+    typeset pid;
 
     /usr/bin/psecflags -s aslr $$
     /usr/bin/psecflags -s current,-aslr -e sleep 10000 &
@@ -131,7 +138,7 @@
 	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
@@ -144,7 +151,7 @@
 
     /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
@@ -154,7 +161,7 @@
     echo "None (child)"
 
     typeset pid
-    
+
     /usr/bin/psecflags -s all $$
 
     /usr/bin/psecflags -s none -e sleep 10000 &
@@ -163,7 +170,7 @@
 	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
 }
