summaryrefslogtreecommitdiff
path: root/usr/src/cmd/initpkg
diff options
context:
space:
mode:
authorDan McDonald <danmcd@omniti.com>2017-04-05 12:38:20 -0400
committerDan McDonald <danmcd@omniti.com>2017-04-07 11:35:17 -0400
commit3bf13137914e56c8fbc66be397fadb819121166c (patch)
treeb3b0fa2915102f2eb9e8cb82345b7a403e3c97da /usr/src/cmd/initpkg
parent703ced3896c5138ab30a9a5e0be538cbbd524767 (diff)
downloadillumos-joyent-3bf13137914e56c8fbc66be397fadb819121166c.tar.gz
8034 shutdown(1M) needs modernizing
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Peter Tribble <peter.tribble@gmail.com> Approved by: Joshua M. Clulow <josh@sysmgr.org>
Diffstat (limited to 'usr/src/cmd/initpkg')
-rw-r--r--usr/src/cmd/initpkg/shutdown.sh51
1 files changed, 26 insertions, 25 deletions
diff --git a/usr/src/cmd/initpkg/shutdown.sh b/usr/src/cmd/initpkg/shutdown.sh
index e65224c632..a90213cd81 100644
--- a/usr/src/cmd/initpkg/shutdown.sh
+++ b/usr/src/cmd/initpkg/shutdown.sh
@@ -25,7 +25,9 @@
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
# All Rights Reserved
-
+#
+# Copyright 2017, OmniTI Computer Consulting, Inc. All rights reserved.
+#
# Sequence performed to change the init state of a machine. Only allows
# transitions to states 0,1,5,6,s,S (i.e.: down or administrative states).
@@ -44,16 +46,9 @@ notify() {
/usr/sbin/wall -a <<-!
$*
!
- if [ -x /usr/sbin/showmount -a -x /usr/sbin/rwall ]
- then
- remotes=`/usr/sbin/showmount`
- if [ "X${remotes}" != "X" ]
- then
- /usr/sbin/rwall -q ${remotes} <<-!
- $*
- !
- fi
- fi
+ # We used to do rwall here if showmounts had any output, but
+ # rwall is a potential security hole, and it could block this, so
+ # we don't bother with it anymore.
}
nologin=/etc/nologin
@@ -128,7 +123,7 @@ do
;;
esac
done
-shift `expr $OPTIND - 1`
+shift $(($OPTIND - 1))
echo '\nShutdown started. \c'
/usr/bin/date
@@ -145,9 +140,9 @@ trap "rm $nologin >/dev/null 2>&1 ;exit 1" 1 2 15
for i in 7200 3600 1800 1200 600 300 120 60 30 10; do
if [ ${grace} -gt $i ]
then
- hours=`/usr/bin/expr ${grace} / 3600`
- minutes=`/usr/bin/expr ${grace} % 3600 / 60`
- seconds=`/usr/bin/expr ${grace} % 60`
+ hours=$((${grace} / 3600))
+ minutes=$((${grace} % 3600 / 60))
+ seconds=$((${grace} % 60))
time=""
if [ ${hours} -gt 1 ]
then
@@ -175,9 +170,7 @@ for i in 7200 3600 1800 1200 600 300 120 60 30 10; do
(notify \
"The system ${NODENAME} will be shut down in ${time}
-$*") &
-
-pid1=$!
+$*")
rm $nologin >/dev/null 2>&1
cat > $nologin <<-!
@@ -187,7 +180,7 @@ pid1=$!
!
- /usr/bin/sleep `/usr/bin/expr ${grace} - $i`
+ /usr/bin/sleep $((${grace} - $i))
grace=$i
fi
done
@@ -212,9 +205,7 @@ fi
(notify \
"THE SYSTEM ${NODENAME} IS BEING SHUT DOWN NOW ! ! !
Log off now or risk your files being damaged
-$*") &
-
-pid2=$!
+$*")
if [ ${grace} -gt 0 ]
then
@@ -226,9 +217,19 @@ fi
echo "Changing to init state $initstate - please wait"
-if [ "$pid1" ] || [ "$pid2" ]
-then
- /usr/bin/kill $pid1 $pid2 > /dev/null 2>&1
+# We might be racing with a system that's still booting.
+# Before starting init, check to see if smf(5) is running. The easiest way
+# to do this is to check for the existence of the repository service door.
+
+i=0
+# Try three times, sleeping one second each time...
+while [ ! -e /etc/svc/volatile/repository_door -a $i -lt 3 ]; do
+ sleep 1
+ i=$(($i + 1))
+done
+
+if [ ! -e /etc/svc/volatile/repository_door ]; then
+ notify "Could not find repository door, init-state change may fail!"
fi
/sbin/init ${initstate}