diff options
author | Klemens Nanni <kn@cvs.openbsd.org> | 2022-11-07 11:03:15 +0000 |
---|---|---|
committer | Klemens Nanni <kn@cvs.openbsd.org> | 2022-11-07 11:03:15 +0000 |
commit | 9241d98c94747d370684e06f4f822e56ce910c94 (patch) | |
tree | d713f7b0b9cead5665db5692b3c6e6f7e90c977c /libexec/reorder_kernel | |
parent | 53cf9ceacf11b287d16f727b215b437ddea6f205 (diff) |
Set up logger(1) traps earlier to catch logfile setup failures
If /usr is mounted read-only, kernel relinking fails silently without any
log trace:
# /usr/libexec/reorder_kernel
/usr/libexec/reorder_kernel[35]: cannot create /usr/share/relink/kernel/GENERIC.MP/relink.log: Read-only file system
This stderr line does not show up anywhere because init(8) redirects stdout
and stderr to /dev/null, executes rc(8) which inherits it and thus executes
reorder_kernel with both streams discarded.
So install the error handler first, then try to set up a log file.
Introduce ERRMSG to provide error messages to users, i.e. not say
"see .../relink.log" when creating this file is what failed:
# ksh ./reorder_kernel.sh
./reorder_kernel.sh[40]: cannot create /usr/share/relink/kernel/GENERIC.MP/relink.log: Read-only file system
# tail -n1 /var/log/message # or xconsole(1)
Nov 7 10:51:00 eru reorder_kernel.sh: failed
OK tb
Diffstat (limited to 'libexec/reorder_kernel')
-rw-r--r-- | libexec/reorder_kernel/reorder_kernel.sh | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/libexec/reorder_kernel/reorder_kernel.sh b/libexec/reorder_kernel/reorder_kernel.sh index 957c85b9102..4d89b40ead6 100644 --- a/libexec/reorder_kernel/reorder_kernel.sh +++ b/libexec/reorder_kernel/reorder_kernel.sh @@ -1,6 +1,6 @@ #!/bin/ksh # -# $OpenBSD: reorder_kernel.sh,v 1.11 2022/05/13 13:20:16 sthen Exp $ +# $OpenBSD: reorder_kernel.sh,v 1.12 2022/11/07 11:03:14 kn Exp $ # # Copyright (c) 2017 Robert Peichaer <rpe@openbsd.org> # @@ -30,15 +30,17 @@ LOGFILE=$KERNEL_DIR/$KERNEL/relink.log PROGNAME=${0##*/} SHA256=/var/db/kernel.SHA256 +# Install trap handlers to inform about success or failure via syslog. +ERRMSG='failed' +trap 'trap - EXIT; logger -st $PROGNAME "$ERRMSG" >/dev/console 2>&1' ERR +trap 'logger -t $PROGNAME "kernel relinking done"' EXIT + # Create kernel compile dir and redirect stdout/stderr to a logfile. mkdir -m 700 -p $KERNEL_DIR/$KERNEL exec 1>$LOGFILE exec 2>&1 -# Install trap handlers to inform about success or failure via syslog. -trap 'trap - EXIT; logger -st $PROGNAME \ - "failed -- see $LOGFILE" >>/dev/console 2>&1' ERR -trap 'logger -t $PROGNAME "kernel relinking done"' EXIT +ERRMSG="failed -- see $LOGFILE" if [[ -f $KERNEL_DIR.tgz ]]; then rm -rf $KERNEL_DIR/$KERNEL/* |