Bug 14931

Summary: rc logging facility
Product: Base System Reporter: Cyrille Lefevre <root>
Component: confAssignee: freebsd-bugs (Nobody) <bugs>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.3-STABLE   
Hardware: Any   
OS: Any   

Description Cyrille Lefevre 1999-11-17 01:00:00 UTC
	Modifications to the /etc/rc startup file to provide
	a logging facility. so it is easy to see if something
	is wrong within /etc/rc.* startup files.

Fix: 

split the /etc/rc into two scripts, /etc/rc and /etc/rc.boot.
	the first one provides the required things as well as the
	logging facilities, and the second one the rest as usual
	(optional things !).

	I'm sorry to not provide you a diff output, but the output
	is really !@#$%^&*, humm, not good at all to understand
	the philosophy of the logging facility.

	instead, I provide you a shell script which act as a patch.

#!/bin/sh

# ========== rc ==========

sed -n 1,/adjkerntz/p /etc/rc | grep -v adjkerntz > /tmp/rc
cat << 'EOF' >> /tmp/rc
# rc logging facility.
#

if [ -f /etc/rc.boot ]; then
	rc_boot=/etc/rc.boot
else
	rc_boot=
fi

# We need script(1) to do logging.
# Maybe a static-ly linked version exists ?
# Much better in case of /usr is not mounted.
#

if [ -x /bin/script ]; then
	rc_script=/bin/script
if [ -x /usr/bin/script ]; then
	rc_script=/usr/bin/script
else
	rc_script=
fi

# Do not use /var/run, it is cleaned by rc.* startup files.
#

if [ -d /var/log -a -w /var/log ]; then
	rc_log=/var/log/rc.log
elif [ -w /etc ]; then
	rc_log=/etc/rc.log
else
	rc_log=
fi

if [ "X$rc_boot" != "X" ]; then
	if [ "X$rc_script" != "X" -a "X$rc_log" != "X" ]; then
		chmod 664 $rc_log
		chmod 755 $rc_boot
		SHELL=$rc_boot $rc_script $rc_log
		rc_status=$?
		chmod 644 $rc_boot
		exit $rc_status
	else
		chmod 644 $rc_boot
		. $rc_boot
	fi
else
	echo "rc.boot file not found, startup aborted"
	exit 1
fi
EOF

# ========== rc.boot ==========

cat << 'EOF' >> /tmp/rc.boot
#!/bin/sh

# Set shell to ignore SIGINT (2), but not children;
# shell catches SIGQUIT (3) and returns to single user after fsck.
trap : 2
trap : 3	# shouldn't be needed

SHELL=/bin/sh
export SHELL

# If there is a global system configuration file, suck it in.
#
if [ -f /etc/defaults/rc.conf ]; then
	. /etc/defaults/rc.conf
elif [ -f /etc/rc.conf ]; then
	. /etc/rc.conf
fi

set -T
trap "echo 'Reboot interrupted'; exit 1" 3
EOF
sed -n /adjkerntz/,\$p /etc/rc >> /tmp/rc.boot

# ===== copy disabled =====

# cp /tmp/rc /etc/rc
# cp /tmp/rc.boot /etc/rc.boot

# eof
How-To-Repeat: 
	reboot ;-)
Comment 1 Sheldon Hearn 1999-11-17 10:49:30 UTC
On Wed, 17 Nov 1999 01:50:41 +0100, Cyrille Lefevre wrote:

> 	Modifications to the /etc/rc startup file to provide
> 	a logging facility. so it is easy to see if something
> 	is wrong within /etc/rc.* startup files.

I don't think this is worth the effort, given that you can get all the
detail you need out of the shell's xtrace option.  Just edit the first
line of all the rc scripts so that it reads:

#!/bin/sh -x

Ciao,
Sheldon.
Comment 2 Sheldon Hearn 1999-11-17 13:25:45 UTC
On Wed, 17 Nov 1999 14:18:15 +0100, Cyrille Lefevre wrote:

> no, you don't understand what I would say.
>
> while the system is starting up, there is lots of messages on the
> system console which scroll very fast. so if there is an error message
> and that error message is not on the last 25 lines, you are unable to
> know what is reporting the error message.

Right, I did misunderstand what you were after.  I wonder if there isn't
something that we could do with init(8) to do something clever with the
outpur of the rc scripts instead of this.  I'm just keen on exploring
alternatives to what looks like a bit of a messy work-around.

Ciao,
Sheldon.
Comment 3 Cyrille Lefevre 2000-11-26 02:47:55 UTC
updated version of the original PR. I'm using it for month w/o any problems.
that's permit to me to know what's happen at boot time even if I'm not front
to the console. maybe this one could be commited until something much better
exists ?

PS : this script relies on script which lives on the /usr filesystem.
if /usr/bin doesn't exists, nothing is logged. a possible solution is
to have a static linked script living in /bin.

Index: defaults/rc.conf
===================================================================
RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
retrieving revision 1.53.2.13
diff -u -r1.53.2.13 rc.conf
--- defaults/rc.conf	2000/11/11 20:33:40	1.53.2.13
+++ defaults/rc.conf	2000/11/26 02:38:33
@@ -19,6 +19,8 @@
 ###  Important initial Boot-time options  ####################
 ##############################################################
 
+rc_log_enable="YES"	# enable rc logging facility
+rc_debug_enable="NO"	# enable rc debug (trace) facility
 swapfile="NO"		# Set to name of swapfile if aux swapfile desired.
 apm_enable="NO"		# Set to YES to enable APM BIOS functions (or NO).
 apmd_enable="NO"	# Run apmd to handle APM event from userland.
Index: rc
===================================================================
RCS file: /home/ncvs/src/etc/rc,v
retrieving revision 1.212.2.8
diff -u -r1.212.2.8 rc
--- rc	2000/10/30 10:40:10	1.212.2.8
+++ rc	2000/10/31 03:46:45
@@ -158,6 +158,13 @@
 		sh ${diskless_mount}
 fi
 
+# log rc.* messages.
+#
+if [ -r /etc/rc.bootlog ]; then
+	. /etc/rc.bootlog
+fi
+# DO NOT DELETE THIS LINE -- rc.boot uses it
+
 adjkerntz -i
  
 purgedir() {
----------=========--------- /etc/rc.bootlog ----------=========---------
# Copyright (c) 2000 Cyrille Lefevre
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

#
# log rc.* messages.
#

case ${rc_log_enable:-YES} in
[Yy][Ee][Ss])

	if [ -f $0 ]; then
		rc_file=$0
	else
		rc_file=
	fi

	if [ -d /usr/bin ]; then
		rc_usrbindir=/usr/bin
	else
		rc_usrbindir=
	fi

	if [ -d /var/tmp -a -w /var/tmp ]; then
		rc_tmpfile=/var/tmp/rc.tmp
	elif [ -w /etc ]; then
		rc_tmpfile=/etc/rc.tmp
	else
		rc_tmpfile=
	fi

	# Do not use /var/run, it is cleaned by rc.bootlog.
	#

	if [ -d /var/log -a -w /var/log ]; then
		rc_logfile=/var/log/rc.log
		rc_symlink=/etc/rc.log
	elif [ -w /etc ]; then
		rc_logfile=/etc/rc.log
		rc_symlink=
	else
		rc_logfile=
		rc_symlink=
	fi

	case ${rc_debug_enable:-NO} in
	[Yy][Ee][Ss])
		rc_debug='s/$/ -x/'
		;;
	*)
		rc_debug=
		;;
	esac

	rc_tag="# DO NOT DELETE THIS LINE -- rc.bootlog uses it"

	if [ "X${rc_file}" != X -a "X${rc_usrbindir}" != X -a \
	     "X${rc_tmpfile}" != X -a "X${rc_logfile}" != X ] &&
	   grep -q "${rc_tag}" "${rc_file}" &&
	   sed -n "1${rc_debug}p
		   /^[^#]*rc.conf/p
		   /${rc_tag}/,\${
			   s/${rc_tag}/fi/
			   p
		   }" "${rc_file}" > "${rc_tmpfile}" &&
	   [ -s "${rc_tmpfile}" ]; then
		if [ -f "${rc_logfile}" ]; then
			mv ${rc_logfile} ${rc_logfile}.old
		fi
		if [ "X${rc_symlink}" != X ]; then
			if [ -f "${rc_symlink}" ]; then
				mv ${rc_symlink} ${rc_symlink}.old
			fi
			if [ ! -L "${rc_symlink}" ]; then
				ln -s ${rc_logfile} ${rc_symlink}
			fi
		fi
		touch ${rc_logfile}
		chmod 664 ${rc_logfile}
		chmod 755 ${rc_tmpfile}
		SHELL=${rc_tmpfile} script ${rc_logfile}
		rc_status=$?
		rm ${rc_tmpfile}
		exit ${rc_status}
	fi
	;;
esac
----------=========--------- /etc/rc.bootlog ----------=========---------

Cyrille.
--
home: mailto:clefevre@citeweb.net work: mailto:Cyrille.Lefevre@edf.fr
Comment 4 Cyrille Lefevre 2000-11-26 02:52:22 UTC
oops, typo error in my previous posting, sorry.

on the line :
# DO NOT DELETE THIS LINE -- rc.boot uses it
read rc.bootlog and not rc.boot.

Index: rc
===================================================================
RCS file: /home/ncvs/src/etc/rc,v
retrieving revision 1.212.2.8
diff -u -r1.212.2.8 rc
--- rc	2000/10/30 10:40:10	1.212.2.8
+++ rc	2000/10/31 03:46:45
@@ -158,6 +158,13 @@
 		sh ${diskless_mount}
 fi
 
+# log rc.* messages
+#
+if [ -r /etc/rc.boot ]; then
+	. /etc/rc.boot
+fi
+# DO NOT DELETE THIS LINE -- rc.bootlog uses it
+
 adjkerntz -i
  
 purgedir() {
===================================================================

Cyrille.
--
home: mailto:clefevre@citeweb.net work: mailto:Cyrille.Lefevre@edf.fr
Comment 5 Doug Barton freebsd_committer freebsd_triage 2001-02-04 05:49:43 UTC
State Changed
From-To: open->closed


While we appreciate your contribution, phk has committed a new console 
facility to both -current and RELENG_4 which neatly handles not only 
rc related items, but everything else that's written to the console 
as well. I hope this doesn't discourage you from further contributions.