From root@d074.paris-222.cybercable.fr Tue Nov 16 16:50:46 1999
Return-Path: <root@d074.paris-222.cybercable.fr>
Received: from lafontaine.cybercable.fr (lafontaine.cybercable.fr [212.198.0.202])
	by hub.freebsd.org (Postfix) with SMTP id 4EB2714FA1
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 16 Nov 1999 16:50:44 -0800 (PST)
	(envelope-from root@d074.paris-222.cybercable.fr)
Received: (qmail 746716 invoked from network); 17 Nov 1999 00:50:41 -0000
Received: from d074.paris-222.cybercable.fr ([212.198.222.74]) (envelope-sender <root@d074.paris-222.cybercable.fr>)
          by lafontaine.cybercable.fr (qmail-ldap-1.03) with SMTP
          for <FreeBSD-gnats-submit@freebsd.org>; 17 Nov 1999 00:50:41 -0000
Received: (from root@localhost)
	by d074.paris-222.cybercable.fr (8.9.3/8.9.3) id BAA01005;
	Wed, 17 Nov 1999 01:50:41 +0100 (CET)
	(envelope-from root)
Message-Id: <199911170050.BAA01005@d074.paris-222.cybercable.fr>
Date: Wed, 17 Nov 1999 01:50:41 +0100 (CET)
From: Cyrille Lefevre <root@d074.paris-222.cybercable.fr>
Reply-To: clefevre@citeweb.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: rc logging facility
X-Send-Pr-Version: 3.2

>Number:         14931
>Category:       conf
>Synopsis:       rc logging facility
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 16 17:00:00 PST 1999
>Closed-Date:    Sat Feb 3 21:49:43 PST 2001
>Last-Modified:  Sat Feb 03 21:51:35 PST 2001
>Originator:     Cyrille Lefevre
>Release:        FreeBSD 3.3-STABLE i386
>Organization:
ACME
>Environment:

FreeBSD gits 3.3-STABLE FreeBSD 3.3-STABLE #5: Sun Nov 14 04:01:58 CET 1999     root@gits:/disk3/3.3-STABLE/src/sys/compile/CUSTOM  i386

>Description:

	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.

>How-To-Repeat:

	reboot ;-)

>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

>Release-Note:
>Audit-Trail:

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: clefevre@citeweb.net
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: conf/14931: rc logging facility 
Date: Wed, 17 Nov 1999 12:49:30 +0200

 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.
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: clefevre@citeweb.net
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: conf/14931: rc logging facility 
Date: Wed, 17 Nov 1999 15:25:45 +0200

 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.
 

From: Cyrille Lefevre <root@gits.dyndns.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: conf/14931: rc logging facility
Date: Sun, 26 Nov 2000 03:47:55 +0100 (CET)

 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
 

From: Cyrille Lefevre <root@gits.dyndns.org>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: conf/14931: rc logging facility
Date: Sun, 26 Nov 2000 03:52:22 +0100 (CET)

 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
 
State-Changed-From-To: open->closed 
State-Changed-By: dougb 
State-Changed-When: Sat Feb 3 21:49:43 PST 2001 
State-Changed-Why:  

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. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=14931 
>Unformatted:
