diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-03-03 00:43:38 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2002-03-03 00:43:38 +0000 |
commit | 52fea3aae5e7d849b3126f3dfc4c70e59b9629f5 (patch) | |
tree | 39bc4c08b639b8aab6ca7d1dcdacfcd2a0ac9d48 /distrib | |
parent | b74f14a248dcd82476ee017f07051f9b2b871a77 (diff) |
Cleanup/Improve trap handling.
a) Add /var/run to the filesystem created when the installation media
boots. This allows the creation and use of the dhclient.pid file.
Synchronize all mtree.conf files in architectures using miniroot.
b) Rework the traps used in upgrade.sh and install.sh so that HUP,
INT, QUIT, TERM and EXIT all invoke a cleanup function that kills an
active dhclient, unmounts all filesystems and fsck's -p all devices
in /etc/fstab, or just /mnt if /etc/fstab is not present.
c) Make sure the actions of the cleanup function are visible, thus
eliminating the long delay with no feedback at the end of the
upgrade/install script, after the congratulatory message.
d) Reduce manual parsing of fstab files by using umount -a to
unmount all mounted filesystems.
e) Since the new cleanup function tries to unmount all filesystems,
use the presence of /etc/fstab, rather than a difference between
`df /` and `df /mnt`, to determine if an install is being restarted
in a state where disk initialization can be skipped.
f) Change munge_fs, check_fs, mount_fs, remount_fs so that they
all 'know' about /etc/fstab rather than passing the same
parameter in all the time.
g) Use input redirection on munge_fs to read correct file, rather
than passing a file name as a parameter.
h) Indent code for various smaller functions.
i) Eliminate some subshell usage to simplify code further.
j) Display pretty messages during fsck -p to clearly indicate success
or failure of fsck, rather than just dumping fsck output.
k) Always run mount_fs in install.sh, even if disk initialization is
being skipped, because the trap should have unmounted all filesystems
when the last run terminated.
ok weingart@ millert@
Diffstat (limited to 'distrib')
-rw-r--r-- | distrib/hp300/ramdisk/mtree.conf | 46 | ||||
-rw-r--r-- | distrib/i386/floppies/common/mtree.conf | 8 | ||||
-rw-r--r-- | distrib/macppc/ramdisk/mtree.conf | 16 | ||||
-rw-r--r-- | distrib/miniroot/install.sh | 27 | ||||
-rw-r--r-- | distrib/miniroot/install.sub | 218 | ||||
-rw-r--r-- | distrib/miniroot/upgrade.sh | 32 | ||||
-rw-r--r-- | distrib/sparc64/common/mtree.conf | 16 | ||||
-rw-r--r-- | distrib/sparc64/ramdisk/mtree.conf | 16 | ||||
-rw-r--r-- | distrib/sparc64/ramdiskB/mtree.conf | 16 |
9 files changed, 231 insertions, 164 deletions
diff --git a/distrib/hp300/ramdisk/mtree.conf b/distrib/hp300/ramdisk/mtree.conf index fafc74ee56c..419ded2f682 100644 --- a/distrib/hp300/ramdisk/mtree.conf +++ b/distrib/hp300/ramdisk/mtree.conf @@ -1,5 +1,5 @@ # -# $OpenBSD: mtree.conf,v 1.3 2001/06/23 19:44:40 deraadt Exp $ +# $OpenBSD: mtree.conf,v 1.4 2002/03/03 00:43:37 krw Exp $ # $NetBSD: mtree.conf,v 1.1 1995/07/18 04:13:24 briggs Exp $ # @@ -19,6 +19,12 @@ dev # ./etc etc + +# ./etc/ppp +ppp +# ./etc/ppp +.. + # ./etc .. @@ -38,22 +44,10 @@ sbin .. # ./tmp -tmp +tmp mode=01777 # ./tmp .. -# ./var -var - -# ./var/tmp -tmp - -# ./var -.. - -# ./ -.. - # ./usr usr @@ -85,3 +79,27 @@ misc # ./usr .. + +# ./var +var + +# ./var/tmp +tmp mode=01777 + +# ./var/tmp +.. + +# ./var/db +db + +# ./var/db +.. + +# ./var/run +run + +# ./var/run +.. + +# ./var +.. diff --git a/distrib/i386/floppies/common/mtree.conf b/distrib/i386/floppies/common/mtree.conf index 9a87ca621a9..f1288eb2928 100644 --- a/distrib/i386/floppies/common/mtree.conf +++ b/distrib/i386/floppies/common/mtree.conf @@ -1,4 +1,4 @@ -# $OpenBSD: mtree.conf,v 1.5 2001/06/23 19:44:42 deraadt Exp $ +# $OpenBSD: mtree.conf,v 1.6 2002/03/03 00:43:37 krw Exp $ /set type=dir uname=root gname=wheel mode=0755 # . @@ -92,5 +92,11 @@ db # ./var/db .. +# ./var/run +run + +# ./var/run +.. + # ./var .. diff --git a/distrib/macppc/ramdisk/mtree.conf b/distrib/macppc/ramdisk/mtree.conf index 443802bfb29..82608136920 100644 --- a/distrib/macppc/ramdisk/mtree.conf +++ b/distrib/macppc/ramdisk/mtree.conf @@ -1,4 +1,4 @@ -# $OpenBSD: mtree.conf,v 1.1 2001/09/01 16:47:03 drahn Exp $ +# $OpenBSD: mtree.conf,v 1.2 2002/03/03 00:43:37 krw Exp $ /set type=dir uname=root gname=wheel mode=0755 # . @@ -17,6 +17,11 @@ dev # ./etc etc +# ./etc/ppp +ppp +# ./etc/ppp +.. + # ./etc .. @@ -76,15 +81,22 @@ misc var # ./var/tmp -tmp mode=0177 +tmp mode=01777 # ./var/tmp .. # ./var/db db + # ./var/db .. +# ./var/run +run + +# ./var/run +.. + # ./var .. diff --git a/distrib/miniroot/install.sh b/distrib/miniroot/install.sh index 275394eb799..208daff37fe 100644 --- a/distrib/miniroot/install.sh +++ b/distrib/miniroot/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: install.sh,v 1.82 2001/12/23 16:54:04 krw Exp $ +# $OpenBSD: install.sh,v 1.83 2002/03/03 00:43:37 krw Exp $ # $NetBSD: install.sh,v 1.5.2.8 1996/08/27 18:15:05 gwr Exp $ # # Copyright (c) 1997-2001 Todd Miller, Theo de Raadt, Ken Westerback @@ -77,8 +77,6 @@ FILESYSTEMS="/tmp/filesystems" # The Fully Qualified Domain Name FQDN= -trap "umount /tmp > /dev/null 2>&1" 0 - MODE="install" # include machine-dependent functions @@ -100,10 +98,14 @@ MODE="install" # include common subroutines . install.sub +# Cleanup when the script exits. +trap 'cleanup_on_exit' EXIT +trap 'exit 2' HUP INT QUIT TERM + # which sets? THESETS="$ALLSETS $MDSETS" -if [ "`df /`" = "`df /mnt`" ]; then +if [ ! -f /etc/fstab ]; then # Good {morning,afternoon,evening,night}. echo ================================================== md_welcome_banner @@ -137,7 +139,7 @@ md_set_term # Get timezone info get_timezone -if [ "`df /`" = "`df /mnt`" ]; then +if [ ! -f /etc/fstab ]; then # Install the shadowed disktab file; lets us write to it for temporary # purposes without mounting the miniroot read-write. if [ -f /etc/disktab.shadow ]; then @@ -307,7 +309,7 @@ case "$resp" in ;; esac -if [ "`df /`" = "`df /mnt`" ]; then +if [ ! -f /etc/fstab ]; then # Now that the network has been configured, it is safe to configure the # fstab. ( @@ -320,10 +322,11 @@ if [ "`df /`" = "`df /mnt`" ]; then done ) < ${FILESYSTEMS} > /tmp/fstab - munge_fstab /tmp/fstab /tmp/fstab.shadow - mount_fs /tmp/fstab.shadow "-o async" + munge_fstab < /tmp/fstab fi +mount_fs "-o async" + mount | while read line; do set -- $line if [ "$2" = "/" -a "$3" = "nfs" ]; then @@ -411,7 +414,7 @@ sh MAKEDEV all echo "... done." cd / -remount_fs /tmp/fstab.shadow +remount_fs md_installboot ${ROOTDISK} _encr=`/mnt/usr/bin/encrypt -b 7 "${_password}"` @@ -425,7 +428,11 @@ chmod 600 /mnt/var/db/host.random >/dev/null 2>&1 populateusrlocal test -x /mnt/install.site && /mnt/usr/sbin/chroot /mnt /install.site -unmount_fs /tmp/fstab.shadow +# Unmount filesystems, etc. and disable trap that would do same on exit. +# Do this manually rather than through the trap so md_congrats is +# the last message printed. +trap - HUP INT QUIT TERM EXIT +cleanup_on_exit # Pat on the back. md_congrats diff --git a/distrib/miniroot/install.sub b/distrib/miniroot/install.sub index b1393a90cb1..2bba425795b 100644 --- a/distrib/miniroot/install.sub +++ b/distrib/miniroot/install.sub @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: install.sub,v 1.183 2002/01/24 23:01:18 millert Exp $ +# $OpenBSD: install.sub,v 1.184 2002/03/03 00:43:37 krw Exp $ # $NetBSD: install.sub,v 1.5.2.8 1996/09/02 23:25:02 pk Exp $ # # Copyright (c) 1997,1998 Todd Miller, Theo de Raadt @@ -2094,148 +2094,120 @@ done } munge_fstab() { -local _fstab _fstab_shadow _dev _mp _fstype _dev _options - -# Create a 'shadow' fstab to use for mounting and unmounting all -# of the target filesystems relative to /mnt. -_fstab=$1 -_fstab_shadow=$2 -( while read _dev _mp _fstype _options _rest; do - # Skip comment lines, non-ffs filesystems and - # 'noauto' filesystems. - case "$_dev" in - \#*) continue;; - *) ;; - esac - case "$_fstype" in - ffs) ;; - *) continue;; - esac - case "$_options" in - *noauto*) continue;; - *) ;; - esac - # Don't use soft updates - _options="$(echo ${_options} | sed 's/,softdep,/,/; s/,softdep//; s/softdep,//')" - if [ "$_mp" = "/" ]; then - _mp="" - fi - echo $_dev /mnt$_mp $_fstype $_options $_rest - done ) < $_fstab > $_fstab_shadow + # Create a fstab to use for fsck'ing, mounting and unmounting all + # of the target filesystems relative to /mnt. + + local _dev _mp _fstype _opt _rest + + while read _dev _mp _fstype _opt _rest; do + # Skip comment lines, non-ffs filesystems and + # 'noauto' filesystems. + case "$_dev" in + \#*) continue;; + *) ;; + esac + case "$_fstype" in + ffs) ;; + *) continue;; + esac + case "$_opt" in + *noauto*) continue;; + *) ;; + esac + + # Don't use soft updates + _opt="$(echo ${_opt} | sed 's/,softdep,/,/; s/,softdep//; s/softdep,//')" + + if [ "$_mp" = "/" ]; then + _mp="" + fi + + echo $_dev /mnt$_mp $_fstype $_opt $_rest + done > /etc/fstab } mount_fs() { -# Must mount filesystems manually, one at a time, so we can make -# sure the mount points exist. -# $1 is a file in fstab format -local _fstab=$1 -local _async=$2 - -( while read line; do - set -- $line - _dev=$1 - _mp=$2 - _fstype=$3 - _opt=$4 - - # If not the root filesystem, make sure the mount - # point is present. - if [ "X{$_mp}" != X"/mnt" ]; then - mkdir -p $_mp - fi + # Must mount filesystems manually, one at a time, so we can make + # sure the mount points exist. + local _async=$1 _dev _mp _fstype _opt _rest + + while read _dev _mp _fstype _opt _rest; do + # If not the root filesystem, make sure the mount + # point is present. + if [ "X{$_mp}" != X"/mnt" ]; then + mkdir -p $_mp + fi - # Mount the filesystem. If the mount fails, exit - # with an error condition to tell the outer - # later to bail. - if ! mount -v -t $_fstype $_async -o $_opt $_dev $_mp ; then - # error message displayed by mount - exit 1 - fi -done ) < $_fstab + # Mount the filesystem. If the mount fails, exit. + if ! mount -v -t $_fstype $_async -o $_opt $_dev $_mp ; then + # In addition to the error message displayed by mount ... + cat << __EOT -if [ "X${?}" != X"0" ]; then - cat << __EOT +FATAL ERROR: Cannot mount filesystems. Double-check your configuration + and restart the ${MODE}. -FATAL ERROR: Cannot mount filesystems. Double-check your configuration -and restart the installation process. __EOT - exit -fi + exit + fi + done < /etc/fstab } -unmount_fs() { - # Unmount all filesystems and check their integrity. - # Usage: [-check] <fstab file> - local _check _fstab _pid _devs= _mps= +cleanup_on_exit() { + # Script is exiting. Clean up as much as possible. + local _bad_devs - if [ "$1" = "-check" ]; then - _check=1 - _fstab=$2 - else - _check=0 - _fstab=$1 - fi + echo "\nCleaning up..." - if [ ! \( -f $_fstab -a -s $_fstab \) ]; then - echo "fstab empty" > /dev/tty - return - fi + # Kill any running dhclient, so a restart will not + # find /dev/bpf0 busy. Do this first so a user who + # interrupts out of any fsck'ing will not be stuck + # with an active dhclient. - # maintain reverse order - while read line; do - set -- $line - _devs="$1 ${_devs}" - _mps="$2 ${_mps}" - done < $_fstab - - echo -n "Unmounting filesystems... " - for _mp in ${_mps}; do - echo -n "${_mp} " - umount ${_mp} - done - echo "... Done." + if [ -f /var/run/dhclient.pid ]; then + echo "Stopping dhclient" + kill -HUP `sed -ne "1p" /var/run/dhclient.pid` > /dev/null 2>&1 + rm -f /var/run/dhclient.pid + fi - if [ $_check = 1 ]; then - echo "Checking filesystem integrity..." - for _dev in ${_devs}; do - echo "${_dev}" - fsck -f ${_dev} - done - echo "... Done." + if [ -f /etc/fstab ]; then + umount -av + check_fs + elif [ ! "`df /`" = "`df /mnt`" ]; then + umount -v /mnt fi + + echo "Done." } remount_fs() { -( while read line; do - set -- $line - _dev=$1 - _mp=$2 - _fstype=$3 - _opt=$4 - - if ! mount -u -o $_opt $_dev $_mp ; then - # error message displayed by mount - exit 1 - fi -done ) < $1 + # Remount all filesystems in /etc/fstab with the options from + # /etc/fstab, i.e. without any options such as async which + # may have been used in the first mount. + local _dev _mp _fstype _opt _rest + + while read _dev _mp _fstype _opt _rest; do + if ! mount -u -o $_opt $_dev $_mp ; then + # error message displayed by mount + exit 1 + fi + done < /etc/fstab } check_fs() { - # Check filesystem integrity. - # $1 is a file in fstab format - local _fstab=$1 _devs= _dev - - while read line; do - set -- $line - _devs="$1 ${_devs}" - done < $_fstab - - echo "Checking filesystem integrity..." - for _dev in ${_devs}; do - echo "${_dev}" - fsck -f ${_dev} - done - echo "Done." + # Preen all filesystems in /etc/fstab, showing individual results. + local _dev _rest _badfsck=0 + + while read _dev _rest; do + echo -n "fsck -p ${_dev}..." + if ! fsck -fp ${_dev} > /dev/null 2>&1; then + echo "FAILED. You must fsck this device manually." + _badfsck=1 + else + echo "OK." + fi + done < /etc/fstab + + return $_badfsck } get_fqdn() { diff --git a/distrib/miniroot/upgrade.sh b/distrib/miniroot/upgrade.sh index cda63ef0bc7..d4da20d9568 100644 --- a/distrib/miniroot/upgrade.sh +++ b/distrib/miniroot/upgrade.sh @@ -1,5 +1,5 @@ #!/bin/sh -# $OpenBSD: upgrade.sh,v 1.20 2001/11/25 21:43:08 krw Exp $ +# $OpenBSD: upgrade.sh,v 1.21 2002/03/03 00:43:37 krw Exp $ # $NetBSD: upgrade.sh,v 1.2.4.5 1996/08/27 18:15:08 gwr Exp $ # # Copyright (c) 1997-2001 Todd Miller, Theo de Raadt, Ken Westerback @@ -44,8 +44,6 @@ # In a perfect world, this would be a nice C program, with a reasonable # user interface. -trap "unmount_fs -check /tmp/fstab.shadow > /dev/null 2>&1; rm -f /tmp/fstab.shadow" 0 - MODE="upgrade" # include machine-dependent functions @@ -65,6 +63,10 @@ MODE="upgrade" # include common subroutines . install.sub +# Make sure to cleanup when the script terminates: +trap 'cleanup_on_exit' EXIT +trap 'exit 2' HUP INT QUIT TERM + # which sets? THESETS="$UPGRSETS $MDSETS" @@ -202,7 +204,7 @@ esac echo "" # Create a fstab containing only ffs filesystems w/o 'noauto'. -munge_fstab /tmp/fstab /tmp/fstab.shadow +munge_fstab < /tmp/fstab if ! umount /mnt; then echo "ERROR: can't unmount previously mounted root!" @@ -210,10 +212,20 @@ if ! umount /mnt; then fi # Check filesystems. -check_fs /tmp/fstab.shadow +echo "Checking filesystem integrity..." +if ! check_fs; then + # Prevent check_fs() invocation in cleanup_on_exit from fsck'ing. + # Remember /etc/fstab is a link, /tmp/fstab.shadow is the file! + rm /tmp/fstab.shadow +fi +echo "...Done." -# Mount filesystems. -mount_fs /tmp/fstab.shadow +if [ ! -f /etc/fstab ]; then + exit 2 +else + # Mount filesystems. + mount_fs +fi # If Xfree86 v3 directories that would prevent upgrading to XFree86 v4 # are found, move them and replace them with links that the upgrade @@ -274,7 +286,11 @@ __rc_edit populateusrlocal test -x /mnt/upgrade.site && /mnt/usr/sbin/chroot /mnt /upgrade.site -unmount_fs /tmp/fstab.shadow +# Unmount filesystems, etc. and disable trap to do same on exit. +# Do this manually rather than through the trap so md_congrats is +# the last message printed. +trap - HUP INT QUIT TERM EXIT +cleanup_on_exit # Pat on the back. md_congrats diff --git a/distrib/sparc64/common/mtree.conf b/distrib/sparc64/common/mtree.conf index c619ef1e898..82608136920 100644 --- a/distrib/sparc64/common/mtree.conf +++ b/distrib/sparc64/common/mtree.conf @@ -1,4 +1,4 @@ -# $OpenBSD: mtree.conf,v 1.1 2001/10/10 04:21:02 deraadt Exp $ +# $OpenBSD: mtree.conf,v 1.2 2002/03/03 00:43:37 krw Exp $ /set type=dir uname=root gname=wheel mode=0755 # . @@ -17,6 +17,11 @@ dev # ./etc etc +# ./etc/ppp +ppp +# ./etc/ppp +.. + # ./etc .. @@ -76,15 +81,22 @@ misc var # ./var/tmp -tmp mode=0177 +tmp mode=01777 # ./var/tmp .. # ./var/db db + # ./var/db .. +# ./var/run +run + +# ./var/run +.. + # ./var .. diff --git a/distrib/sparc64/ramdisk/mtree.conf b/distrib/sparc64/ramdisk/mtree.conf index a56bed09a51..82608136920 100644 --- a/distrib/sparc64/ramdisk/mtree.conf +++ b/distrib/sparc64/ramdisk/mtree.conf @@ -1,4 +1,4 @@ -# $OpenBSD: mtree.conf,v 1.1 2001/09/18 14:27:32 jason Exp $ +# $OpenBSD: mtree.conf,v 1.2 2002/03/03 00:43:37 krw Exp $ /set type=dir uname=root gname=wheel mode=0755 # . @@ -17,6 +17,11 @@ dev # ./etc etc +# ./etc/ppp +ppp +# ./etc/ppp +.. + # ./etc .. @@ -76,15 +81,22 @@ misc var # ./var/tmp -tmp mode=0177 +tmp mode=01777 # ./var/tmp .. # ./var/db db + # ./var/db .. +# ./var/run +run + +# ./var/run +.. + # ./var .. diff --git a/distrib/sparc64/ramdiskB/mtree.conf b/distrib/sparc64/ramdiskB/mtree.conf index c619ef1e898..82608136920 100644 --- a/distrib/sparc64/ramdiskB/mtree.conf +++ b/distrib/sparc64/ramdiskB/mtree.conf @@ -1,4 +1,4 @@ -# $OpenBSD: mtree.conf,v 1.1 2001/10/10 04:21:02 deraadt Exp $ +# $OpenBSD: mtree.conf,v 1.2 2002/03/03 00:43:37 krw Exp $ /set type=dir uname=root gname=wheel mode=0755 # . @@ -17,6 +17,11 @@ dev # ./etc etc +# ./etc/ppp +ppp +# ./etc/ppp +.. + # ./etc .. @@ -76,15 +81,22 @@ misc var # ./var/tmp -tmp mode=0177 +tmp mode=01777 # ./var/tmp .. # ./var/db db + # ./var/db .. +# ./var/run +run + +# ./var/run +.. + # ./var .. |