Browse Source

Improve error handling in reorder_libs()

- run commands in subshell only if mktemp is successful
- on error just leave the for-loop but set _error=true
- cleanup tmpdirs afterwards
- set _error=true if the ro remount fails
- print appropriate final message depending on $_error
positive feedback from deraadt
OK krw
OPENBSD_6_0
rpe 8 years ago
parent
commit
44084ed262
1 changed files with 12 additions and 8 deletions
  1. +12
    -8
      src/etc/rc

+ 12
- 8
src/etc/rc View File

@ -1,4 +1,4 @@
# $OpenBSD: rc,v 1.484 2016/05/27 17:03:45 rpe Exp $
# $OpenBSD: rc,v 1.485 2016/05/29 15:36:06 rpe Exp $
# System startup script run by init on autoboot or after single-user. # System startup script run by init on autoboot or after single-user.
# Output and error are redirected to console by init, and the console is the # Output and error are redirected to console by init, and the console is the
@ -160,7 +160,7 @@ make_keys() {
# Re-link libraries, placing the objects in a random order. # Re-link libraries, placing the objects in a random order.
reorder_libs() { reorder_libs() {
local _l _liba _libas _tmpdir _remount=false
local _l _liba _libas _tmpdir _remount=false _error=false
local _dkdev=/dev/$(stat -L -f '%Sd' /usr/lib) local _dkdev=/dev/$(stat -L -f '%Sd' /usr/lib)
local _mp=$(mount | grep "^$_dkdev") local _mp=$(mount | grep "^$_dkdev")
@ -189,8 +189,7 @@ reorder_libs() {
fi fi
for _liba in $_libas; do for _liba in $_libas; do
_tmpdir=$(mktemp -dq /tmp/_librebuild.XXXXXXXXXXXX) || return
(
_tmpdir=$(mktemp -dq /tmp/_librebuild.XXXXXXXXXXXX) && (
set -o errexit set -o errexit
_lib=${_liba#/usr/lib/} _lib=${_liba#/usr/lib/}
_lib=${_lib%.a} _lib=${_lib%.a}
@ -200,16 +199,21 @@ reorder_libs() {
[[ -s $_lib ]] && file $_lib | fgrep -q 'shared object' [[ -s $_lib ]] && file $_lib | fgrep -q 'shared object'
LD_BIND_NOW=1 LD_LIBRARY_PATH=$_tmpdir awk 'BEGIN {exit 0}' LD_BIND_NOW=1 LD_LIBRARY_PATH=$_tmpdir awk 'BEGIN {exit 0}'
install -F -S -o root -g bin -m 0444 $_lib /usr/lib/$_lib install -F -S -o root -g bin -m 0444 $_lib /usr/lib/$_lib
)
rm -rf /tmp/_librebuild.${_tmpdir#*.}
) || { _error=true; break; }
done done
rm -rf /tmp/_librebuild.*
# Restore previous mount state if it was changed. # Restore previous mount state if it was changed.
if $_remount; then if $_remount; then
mount -u -r $_dkdev
mount -u -r $_dkdev || _error=true
fi fi
echo ' done.'
if $_error; then
echo ' failed.'
else
echo ' done.'
fi
} }
# Run rc.* script and email output to root. # Run rc.* script and email output to root.


Loading…
Cancel
Save