On 4/18/06, M. Warner Losh <[EMAIL PROTECTED]> wrote:
>
> In message: <[EMAIL PROTECTED]>
>             Eric Anderson <[EMAIL PROTECTED]> writes:
> : Gordon Bergling wrote:
> : > Hi,
> : >
> : > * Thus spake Eric Anderson ([EMAIL PROTECTED]):
> : >> I've made a patch to /etc/rc.subr that makes the startup/shutdown rc
> : >> scripting look similar to other OS's (many different linux distros,
> : >> HP-UX, etc), but without color.
> : >>
> : >> The patch shouldn't break anything, and is only enabled if you have
> this
> : >> in your /etc/rc.conf:
> : >>
> : >> rc_fancy="YES"
> : >>
> : >> Several of the /etc/rc.d/* scripts send output to stdout, so that
> could
> : >> be cleaned up a bit if needed, but for now I tried to keep the patch
> as
> : >> minimal as possible.
> : >>
> : >> This is still a first pass, so please give feedback.
> : >
> : > A short try on my notebook shows some errors.
> : > I don't want to let this email getting too big, so I put the "dmesg
> -a"
> : > output online. http://generic.0xfce3.net/dmesg-fancy.txt
> : >
> : > BTW, the patch applied cleanly.
> :
> :
> : Thanks for the feedback!  Looks like I made an erroneous assumption that
> : the wc, expr, and printf tools found in /usr/bin and /bin would be
> : available through boot, but that isn't the case on systems with those
> : file systems separate from /.  I'm not sure how to resolve some of these
> : issues, since I don't know of a way to do those functions in csh without
> : them.  I'm open to suggestions here from anyone.
>
> /bin and /sbin are available through the entire boot.  Only things in
> /usr are suspect because /usr gets mounted early in the boot process,
> but not as early as /.
>
> Warner


Nice work!

I too noticed the dependence upon wc, printf, expr. I went ahead and rewrote
these into equivalents in native sh. (attaching new diff).

This diff is against the latest 7-CURRENT rc.subr. I had to manually merge 3
hunks due to some differences.

--
coleman kane
--- rc.subr.orig	Tue Apr 18 13:58:14 2006
+++ rc.subr	Tue Apr 18 13:57:36 2006
@@ -313,12 +313,16 @@
 			break
 		fi
 		_list=$_nlist
-		echo -n ${_prefix:-"Waiting for PIDS: "}$_list
+		if ! checkyesno rc_fancy; then
+			echo -n ${_prefix:-"Waiting for PIDS: "}$_list
+		fi
 		_prefix=", "
 		sleep 2
 	done
 	if [ -n "$_prefix" ]; then
-		echo "."
+		if ! checkyesno rc_fancy; then
+			echo "."
+		fi
 	fi
 }
 
@@ -564,12 +568,14 @@
 					# if the precmd failed and force
 					# isn't set, exit
 					#
+			rcargsize=`echo $rc_arg`
+			rcargsize=${#rcargsize}
 			if [ -n "$_precmd" ]; then
 				debug "run_rc_command: evaluating ${_precmd}()."
 				eval $_precmd $rc_extra_args
 				_return=$?
 				[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
-				    return 1
+				    (echo_fancy "FAILED" `expr 10 + $rcargsize - 1`) && return 1
 			fi
 
 			if [ -n "$_cmd" ]; then
@@ -577,7 +583,7 @@
 				eval $_cmd $rc_extra_args
 				_return=$?
 				[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
-				    return 1
+				    (echo_fancy "FAILED" `expr 10 + $rcargsize - 1`) && return 1
 			fi
 
 			if [ -n "$_postcmd" ]; then
@@ -585,6 +591,7 @@
 				 eval $_postcmd $rc_extra_args
 				_return=$?
 			fi
+			echo_fancy "  OK  " 0
 			return $_return
 		fi
 
@@ -600,13 +607,16 @@
 			;;
 
 		start)
+ 			echo -n "Starting ${name}"
 			if [ -z "$rc_fast" -a -n "$rc_pid" ]; then
+ 				echo_fancy " SKIP " 9
 				echo 1>&2 "${name} already running? (pid=$rc_pid)."
 				return 1
 			fi
 
 			if [ ! -x ${_chroot}${command} ]; then
 				info "run_rc_command: cannot run ($command)."
+ 				echo_fancy "ERROR " 9
 				return 1
 			fi
 
@@ -617,6 +627,7 @@
 				if ! checkyesno $_f; then
 					warn "\$${_f} is not enabled."
 					if [ -z "$rc_force" ]; then
+						echo_fancy "ERROR " 9
 						return 1
 					fi
 				fi
@@ -625,6 +636,7 @@
 				if [ ! -d "${_f}/." ]; then
 					warn "${_f} is not a directory."
 					if [ -z "$rc_force" ]; then
+						echo_fancy "ERROR " 9
 						return 1
 					fi
 				fi
@@ -633,6 +645,7 @@
 				if [ ! -r "${_f}" ]; then
 					warn "${_f} is not readable."
 					if [ -z "$rc_force" ]; then
+						echo_fancy "ERROR " 9
 						return 1
 					fi
 				fi
@@ -646,12 +659,11 @@
 				eval $_precmd
 				_return=$?
 				[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
-				    return 1
+				    (echo_fancy "ERROR " 9) && return 1
 			fi
 
 					# setup the command to run, and run it
 					#
-			echo "Starting ${name}."
 			if [ -n "$_chroot" ]; then
 				_doit="\
 ${_nice:+nice -n $_nice }\
@@ -673,7 +685,7 @@
 			debug "run_rc_command: _doit: $_doit"
 			eval $_doit
 			_return=$?
-			[ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1
+			[ $_return -ne 0 ] && [ -z "$rc_force" ] && (echo_fancy "FAILED" 9) && return 1
 
 					# finally, run postcmd
 					#
@@ -681,15 +693,19 @@
 				debug "run_rc_command: evaluating ${_postcmd}()."
 				eval $_postcmd
 			fi
+ 			echo_fancy "  OK  " 9
 			;;
 
 		stop)
+ 			echo -n "Stopping ${name}"
 			if [ -z "$rc_pid" ]; then
 				[ -n "$rc_fast" ] && return 0
 				if [ -n "$pidfile" ]; then
+ 					echo_fancy " SKIP " 9
 					echo 1>&2 \
 				    "${name} not running? (check $pidfile)."
 				else
+ 					echo_fancy " SKIP " 9
 					echo 1>&2 "${name} not running?"
 				fi
 				return 1
@@ -702,12 +718,11 @@
 				eval $_precmd
 				_return=$?
 				[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
-				    return 1
+					(echo_fancy "ERROR " 9) && return 1
 			fi
 
 					# send the signal to stop
 					#
-			echo "Stopping ${name}."
 			_doit="kill -${sig_stop:-TERM} $rc_pid"
 			if [ -n "$_user" ]; then
 				_doit="su -m $_user -c 'sh -c \"$_doit\"'"
@@ -718,7 +733,7 @@
 					#
 			eval $_doit
 			_return=$?
-			[ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1
+			[ $_return -ne 0 ] && [ -z "$rc_force" ] && (echo_fancy "FAILED" 9) && return 1
 
 					# wait for the command to exit,
 					# and run postcmd.
@@ -727,24 +742,27 @@
 				eval $_postcmd
 				_return=$?
 			fi
+ 			echo_fancy "  OK  " 9
 			;;
 
 		reload)
+ 			echo -n "Reloading ${name} config files"
 			if [ -z "$rc_pid" ]; then
 				if [ -n "$pidfile" ]; then
+ 					echo_fancy "SKIPPED" 23
 					echo 1>&2 \
 				    "${name} not running? (check $pidfile)."
 				else
+ 					echo_fancy "SKIPPED" 23
 					echo 1>&2 "${name} not running?"
 				fi
 				return 1
 			fi
-			echo "Reloading ${name} config files."
 			if [ -n "$_precmd" ]; then
 				eval $_precmd
 				_return=$?
 				[ $_return -ne 0 ] && [ -z "$rc_force" ] &&
-				    return 1
+ 				    (echo_fancy "FAILED" 23) && return 1
 			fi
 			_doit="kill -${sig_reload:-HUP} $rc_pid"
 			if [ -n "$_user" ]; then
@@ -752,11 +770,12 @@
 			fi
 			eval $_doit
 			_return=$?
-			[ $_return -ne 0 ] && [ -z "$rc_force" ] && return 1
+			[ $_return -ne 0 ] && [ -z "$rc_force" ] && (echo_fancy "FAILED" 23) && return 1
 			if [ -n "$_postcmd" ]; then
 				eval $_postcmd
 				_return=$?
 			fi
+			echo_fancy "  OK  " 23
 			;;
 
 		restart)
@@ -1428,3 +1447,33 @@
 }
 
 fi
+
+echo_fancy () {
+	columns=80
+	label=$1
+	namesize=`echo -n $name`
+	namesize=${#namesize}
+	rc_argsize=`echo -n $rc_arg`
+	rc_argsize=${#rc_argsize}
+	padding=""
+	paddingsize=$(($columns - 15 - $2 - $namesize))
+	until [ 0 = ${paddingsize} ]; do
+		padding=" $padding"
+		paddingsize=$(($paddingsize - 1))
+	done
+	if checkyesno rc_fancy; then
+		if [ $2 = 0 ]; then
+	    	padding=""
+			paddingsize=$((60 - $namesize - $rc_argsize))
+			until [ 0 = ${paddingsize} ]; do
+		  		padding=" $padding"
+		  		paddingsize=$(($paddingsize - 1))
+			done
+			echo -e "\rRunning ${rc_arg} $name $padding [$label]"
+		else
+			echo " ... $padding [$label]"
+		fi
+	else
+		echo "."
+	fi
+}
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to