Browse Source

Switch reorder_kernel() from sending emails to logging via syslog

and to write the logfile inside the kernel compile dir.
- turn the whole reorder_kernel function into a subshell {} -> ()
- create kernel compile dir early on
- redirect all stdout/stderr to a logfile inside this dir
- setup ERR trap handler that
- disables the EXIT trap handler
- syslogs the error and hints to the logfile
- additionally sends this message to the console
- setup EXIT trap handler that syslogs success
- wipe only the content instead of the whole kernel compile dir
- reestablish stdout redirection to the log after the wipe
- remove -q option of sha256 to log check result
- run reorder_kernel() in the background
OK deraadt@ tb@
OPENBSD_6_2
rpe 7 years ago
parent
commit
1f01084ede
1 changed files with 17 additions and 15 deletions
  1. +17
    -15
      src/etc/rc

+ 17
- 15
src/etc/rc View File

@ -1,4 +1,4 @@
# $OpenBSD: rc,v 1.506 2017/06/30 17:06:03 rpe Exp $
# $OpenBSD: rc,v 1.507 2017/07/04 19:02:11 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
@ -221,32 +221,35 @@ reorder_libs() {
# Re-link the kernel, placing the objects in a random order. # Re-link the kernel, placing the objects in a random order.
# Replace current with relinked kernel and inform root about it. # Replace current with relinked kernel and inform root about it.
reorder_kernel() {
reorder_kernel() (
local _dkdev=$(df /usr/share | sed '1d;s/ .*//') local _dkdev=$(df /usr/share | sed '1d;s/ .*//')
# Skip if /usr/share is on a nfs mounted filesystem. # Skip if /usr/share is on a nfs mounted filesystem.
[[ $(mount | grep "^$_dkdev") == *" type nfs "* ]] && return [[ $(mount | grep "^$_dkdev") == *" type nfs "* ]] && return
(
set -e
trap 'trap - EXIT; mail -s "$(hostname) Kernel relink failed" root \
</var/log/kernel_relink.log' ERR
trap 'mail -s "$(hostname) Kernel relink info" root \
</var/log/kernel_relink.log' EXIT
_compile=/usr/share/compile _compile=/usr/share/compile
_kernel=$(sysctl -n kern.osversion) _kernel=$(sysctl -n kern.osversion)
_kernel=${_kernel%#*} _kernel=${_kernel%#*}
_log=$_compile/$_kernel/relink.log
_sha256=/var/db/kernel.SHA256 _sha256=/var/db/kernel.SHA256
mkdir -m 700 -p $_compile/$_kernel
exec 1>$_log
exec 2>&1
trap 'trap - EXIT; logger -st /etc/rc \
"kernel relinking failed; see $_log" >>/dev/console 2>&1' ERR
trap 'logger -t /etc/rc "kernel relinking done"' EXIT
set -e
if [[ -f $_compile.tgz ]]; then if [[ -f $_compile.tgz ]]; then
rm -rf $_compile
mkdir -m 700 -p $_compile
rm -rf $_compile/$_kernel/*
exec 1>$_log
tar -C $_compile -xzf $_compile.tgz $_kernel tar -C $_compile -xzf $_compile.tgz $_kernel
rm -f $_compile.tgz rm -f $_compile.tgz
fi fi
sha256 -q -C $_sha256 /bsd
sha256 -C $_sha256 /bsd
cd $_compile/$_kernel cd $_compile/$_kernel
make newbsd make newbsd
@ -254,8 +257,7 @@ reorder_kernel() {
echo "\nKernel has been relinked and is active on next reboot.\n" echo "\nKernel has been relinked and is active on next reboot.\n"
cat $_sha256 cat $_sha256
) >/var/log/kernel_relink.log 2>&1 &
}
)
# Run rc.* script and email output to root. # Run rc.* script and email output to root.
# Usage: run_upgrade_script firsttime|sysmerge # Usage: run_upgrade_script firsttime|sysmerge
@ -619,7 +621,7 @@ echo -n 'starting local daemons:'
start_daemon apmd sensorsd hotplugd watchdogd cron wsmoused xenodm start_daemon apmd sensorsd hotplugd watchdogd cron wsmoused xenodm
echo '.' echo '.'
reorder_kernel
reorder_kernel &
date date
exit 0 exit 0

Loading…
Cancel
Save