Wed Apr 9 12:38:09 2014 UTC ()
Add comments about the intended use of each type of metadata message.


(apb)
diff -r1.166 -r1.167 src/etc/rc

cvs diff -r1.166 -r1.167 src/etc/rc (expand / switch to unified diff)

--- src/etc/rc 2011/08/11 22:52:47 1.166
+++ src/etc/rc 2014/04/09 12:38:09 1.167
@@ -1,16 +1,16 @@ @@ -1,16 +1,16 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# $NetBSD: rc,v 1.166 2011/08/11 22:52:47 apb Exp $ 3# $NetBSD: rc,v 1.167 2014/04/09 12:38:09 apb Exp $
4# 4#
5# rc -- 5# rc --
6# Run the scripts in /etc/rc.d with rcorder, and log output 6# Run the scripts in /etc/rc.d with rcorder, and log output
7# to /var/run/rc.log. 7# to /var/run/rc.log.
8 8
9# System startup script run by init(8) on autoboot or after single-user. 9# System startup script run by init(8) on autoboot or after single-user.
10# Output and error are redirected to console by init, and the console 10# Output and error are redirected to console by init, and the console
11# is the controlling terminal. 11# is the controlling terminal.
12 12
13export HOME=/ 13export HOME=/
14export PATH=/sbin:/bin:/usr/sbin:/usr/bin 14export PATH=/sbin:/bin:/usr/sbin:/usr/bin
15umask 022 15umask 022
16 16
@@ -267,84 +267,100 @@ rc_postprocess_metadata() @@ -267,84 +267,100 @@ rc_postprocess_metadata()
267 local msg 267 local msg
268 local IFS=':' 268 local IFS=':'
269 269
270 # given metadata="bleep:foo bar:baz", 270 # given metadata="bleep:foo bar:baz",
271 # set keyword="bleep", args="foo bar:baz", 271 # set keyword="bleep", args="foo bar:baz",
272 # $1="foo bar", $2="baz" 272 # $1="foo bar", $2="baz"
273 # 273 #
274 keyword="${metadata%%:*}" 274 keyword="${metadata%%:*}"
275 args="${metadata#*:}" 275 args="${metadata#*:}"
276 set -- $args 276 set -- $args
277 277
278 case "$keyword" in 278 case "$keyword" in
279 start) 279 start)
280 # $args contains a date/time 280 # Marks the start of the entire /etc/rc script.
 281 # $args contains a date/time.
281 rc_log_message "[$0 starting at $args]" 282 rc_log_message "[$0 starting at $args]"
282 if ! $rc_silent; then 283 if ! $rc_silent; then
283 printf "%s\n" "$args" 284 printf "%s\n" "$args"
284 fi 285 fi
285 ;; 286 ;;
286 cmd-name) 287 cmd-name)
 288 # Marks the start of a child script (usually one of
 289 # the /etc/rc.d/* scripts).
287 rc_log_message "[running $1]" 290 rc_log_message "[running $1]"
288 ;; 291 ;;
289 cmd-status) 292 cmd-status)
 293 # Marks the end of a child script.
290 # $1 is a command name, $2 is the command's exit status. 294 # $1 is a command name, $2 is the command's exit status.
291 # If the command failed, report it, and add it to a list. 295 # If the command failed, report it, and add it to a list.
292 if [ "$2" != 0 ]; then 296 if [ "$2" != 0 ]; then
293 rc_failures="${rc_failures}${rc_failures:+ }$1" 297 rc_failures="${rc_failures}${rc_failures:+ }$1"
294 msg="$1 $(human_exit_code $2)" 298 msg="$1 $(human_exit_code $2)"
295 rc_log_message "$msg" 299 rc_log_message "$msg"
296 if ! $rc_silent; then 300 if ! $rc_silent; then
297 printf "%s\n" "$msg" 301 printf "%s\n" "$msg"
298 fi 302 fi
299 fi 303 fi
300 # After the mountcritlocal script has finished, it's 304 # After the mountcritlocal script has finished, it's
301 # OK to flush the log to disk 305 # OK to flush the log to disk
302 case "$1" in 306 case "$1" in
303 */mountcritlocal) 307 */mountcritlocal)
304 rc_log_flush OK 308 rc_log_flush OK
305 ;; 309 ;;
306 esac 310 esac
307 ;; 311 ;;
308 nop) 312 nop)
309 # Do nothing. 313 # Do nothing.
 314 # This has the side effect of flushing partial lines,
 315 # and the echo() and printf() functions in rc.subr take
 316 # advantage of this.
310 ;; 317 ;;
311 note) 318 note)
 319 # Unlike most metadata messages, which should be used
 320 # only by /etc/rc and rc.subr, the "note" message may be
 321 # used directly by /etc.rc.d/* and similar scripts.
 322 # It adds a note to the log file, without displaying
 323 # it to stdout.
312 rc_log_message "[NOTE: $args]" 324 rc_log_message "[NOTE: $args]"
313 ;; 325 ;;
314 end) 326 end)
315 # 327 # Marks the end of processing, after the last child script.
316 # If any scripts (or other commands) failed, report them. 328 # If any child scripts (or other commands) failed, report them.
317 # 329 #
318 if [ -n "$rc_failures" ]; then 330 if [ -n "$rc_failures" ]; then
319 rc_log_message "[failures]" 331 rc_log_message "[failures]"
320 msg="The following components reported failures:" 332 msg="The following components reported failures:"
321 msg="${msg}${nl}$( echo " ${rc_failures}" | fmt )" 333 msg="${msg}${nl}$( echo " ${rc_failures}" | fmt )"
322 msg="${msg}${nl}See ${RC_LOG_FILE} for more information." 334 msg="${msg}${nl}See ${RC_LOG_FILE} for more information."
323 rc_log_message "${msg}" 335 rc_log_message "${msg}"
324 printf "%s\n" "${msg}" 336 printf "%s\n" "${msg}"
325 fi 337 fi
326 # 338 #
327 # Report the end date/time, even in silent mode 339 # Report the end date/time, even in silent mode
328 # 340 #
329 rc_log_message "[$0 finished at $args]" 341 rc_log_message "[$0 finished at $args]"
330 printf "%s\n" "$args" 342 printf "%s\n" "$args"
331 ;; 343 ;;
332 exit) 344 exit)
 345 # Marks an exit from the rc_real_work() function.
 346 # This may be a normal or abnormal exit.
 347 #
333 rc_log_message "[$0 exiting with status $1]" 348 rc_log_message "[$0 exiting with status $1]"
334 exit $1 349 exit $1
335 ;; 350 ;;
336 interrupted) 351 interrupted)
337 # $args is a human-readable message 352 # Marks an interrupt trapped by the rc_real_work() function.
 353 # $args is a human-readable message.
338 rc_log_message "$args" 354 rc_log_message "$args"
339 printf "%s\n" "$args" 355 printf "%s\n" "$args"
340 ;; 356 ;;
341 *) 357 *)
342 # an unrecognised line of metadata 358 # an unrecognised line of metadata
343 rc_log_message "[metadata:${metadata}]" 359 rc_log_message "[metadata:${metadata}]"
344 ;; 360 ;;
345 esac 361 esac
346} 362}
347 363
348# 364#
349# rc_log_message string [...] 365# rc_log_message string [...]
350# Write a message to the log file, or buffer it for later. 366# Write a message to the log file, or buffer it for later.