From: kn Date: Mon, 7 Nov 2022 11:03:14 +0000 (+0000) Subject: Set up logger(1) traps earlier to catch logfile setup failures X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=44e1f38769613700cf6d7ee3779e7f8af5df97e8;p=openbsd 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 --- 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 # @@ -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/*