Deleted Added
full compact
rc.subr (256256) rc.subr (264243)
1# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
1# $NetBSD: rc.subr,v 1.67 2006/10/07 11:25:15 elad Exp $
2# $FreeBSD: head/etc/rc.subr 256256 2013-10-10 09:32:27Z hrs $
2# $FreeBSD: head/etc/rc.subr 264243 2014-04-07 22:40:29Z dteske $
3#
4# Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Luke Mewburn.
9#
10# Redistribution and use in source and binary forms, with or without

--- 38 unchanged lines hidden (view full) ---

49IDCMD="if [ -x $ID ]; then $ID -un; fi"
50PS="/bin/ps -ww"
51JID=`$PS -p $$ -o jid=`
52
53#
54# functions
55# ---------
56
3#
4# Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
5# All rights reserved.
6#
7# This code is derived from software contributed to The NetBSD Foundation
8# by Luke Mewburn.
9#
10# Redistribution and use in source and binary forms, with or without

--- 38 unchanged lines hidden (view full) ---

49IDCMD="if [ -x $ID ]; then $ID -un; fi"
50PS="/bin/ps -ww"
51JID=`$PS -p $$ -o jid=`
52
53#
54# functions
55# ---------
56
57# list_vars pattern
58# List vars matching pattern.
59#
60list_vars()
61{
62 set | { while read LINE; do
63 var="${LINE%%=*}"
64 case "$var" in
65 "$LINE"|*[!a-zA-Z0-9_]*) continue ;;
66 $1) echo $var
67 esac
68 done; }
69}
70
57# set_rcvar_obsolete oldvar [newvar] [msg]
58# Define obsolete variable.
59# Global variable $rcvars_obsolete is used.
60#
61set_rcvar_obsolete()
62{
63 local _var
64 _var=$1

--- 244 unchanged lines hidden (view full) ---

309 ;;
310 esac
311 done'
312
313# debug "in _find_processes: proccheck is ($_proccheck)."
314 eval $_proccheck
315}
316
71# set_rcvar_obsolete oldvar [newvar] [msg]
72# Define obsolete variable.
73# Global variable $rcvars_obsolete is used.
74#
75set_rcvar_obsolete()
76{
77 local _var
78 _var=$1

--- 244 unchanged lines hidden (view full) ---

323 ;;
324 esac
325 done'
326
327# debug "in _find_processes: proccheck is ($_proccheck)."
328 eval $_proccheck
329}
330
331# sort_lite [-b] [-n] [-k POS] [-t SEP]
332# A lite version of sort(1) (supporting a few options) that can be used
333# before the real sort(1) is available (e.g., in scripts that run prior
334# to mountcritremote). Requires only shell built-in functionality.
317#
335#
336sort_lite()
337{
338 local funcname=sort_lite
339 local sort_sep="$IFS" sort_ignore_leading_space=
340 local sort_field=0 sort_strict_fields= sort_numeric=
341 local nitems=0 skip_leading=0 trim=
342
343 local OPTIND flag
344 while getopts bnk:t: flag; do
345 case "$flag" in
346 b) sort_ignore_leading_space=1 ;;
347 n) sort_numeric=1 sort_ignore_leading_space=1 ;;
348 k) sort_field="${OPTARG%%,*}" ;; # only up to first comma
349 # NB: Unlike sort(1) only one POS allowed
350 t) sort_sep="$OPTARG"
351 if [ ${#sort_sep} -gt 1 ]; then
352 echo "$funcname: multi-character tab \`$sort_sep'" >&2
353 return 1
354 fi
355 sort_strict_fields=1
356 ;;
357 \?) return 1 ;;
358 esac
359 done
360 shift $(( $OPTIND - 1 ))
361
362 # Create transformation pattern to trim leading text if desired
363 case "$sort_field" in
364 ""|[!0-9]*|*[!0-9.]*)
365 echo "$funcname: invalid sort field \`$sort_field'" >&2
366 return 1
367 ;;
368 *.*)
369 skip_leading=${sort_field#*.} sort_field=${sort_field%%.*}
370 while [ ${skip_leading:-0} -gt 1 ] 2> /dev/null; do
371 trim="$trim?" skip_leading=$(( $skip_leading - 1 ))
372 done
373 esac
374
375 # Copy input to series of local numbered variables
376 # NB: IFS of NULL preserves leading whitespace
377 local LINE
378 while IFS= read -r LINE || [ "$LINE" ]; do
379 nitems=$(( $nitems + 1 ))
380 local src_$nitems="$LINE"
381 done
382
383 #
384 # Sort numbered locals using insertion sort
385 #
386 local curitem curitem_orig curitem_mod curitem_haskey
387 local dest dest_orig dest_mod dest_haskey
388 local d gt n
389 local i=1
390 while [ $i -le $nitems ]; do
391 curitem_haskey=1 # Assume sort field (-k POS) exists
392 eval curitem=\"\$src_$i\"
393 curitem_mod="$curitem" # for modified comparison
394 curitem_orig="$curitem" # for original comparison
395
396 # Trim leading whitespace if desired
397 if [ "$sort_ignore_leading_space" ]; then
398 while case "$curitem_orig" in
399 [$IFS]*) : ;; *) false; esac
400 do
401 curitem_orig="${curitem_orig#?}"
402 done
403 curitem_mod="$curitem_orig"
404 fi
405
406 # Shift modified comparison value if sort field (-k POS) is > 1
407 n=$sort_field
408 while [ $n -gt 1 ]; do
409 case "$curitem_mod" in
410 *[$sort_sep]*)
411 # Cut text up-to (and incl.) first separator
412 curitem_mod="${curitem_mod#*[$sort_sep]}"
413
414 # Skip NULLs unless strict field splitting
415 [ "$sort_strict_fields" ] ||
416 [ "${curitem_mod%%[$sort_sep]*}" ] ||
417 [ $n -eq 2 ] ||
418 continue
419 ;;
420 *)
421 # Asked for a field that doesn't exist
422 curitem_haskey= break
423 esac
424 n=$(( $n - 1 ))
425 done
426
427 # Trim trailing words if sort field >= 1
428 [ $sort_field -ge 1 -a "$sort_numeric" ] &&
429 curitem_mod="${curitem_mod%%[$sort_sep]*}"
430
431 # Apply optional trim (-k POS.TRIM) to cut leading characters
432 curitem_mod="${curitem_mod#$trim}"
433
434 # Determine the type of modified comparison to use initially
435 # NB: Prefer numerical if requested but fallback to standard
436 case "$curitem_mod" in
437 ""|[!0-9]*) # NULL or begins with non-number
438 gt=">"
439 [ "$sort_numeric" ] && curitem_mod=0
440 ;;
441 *)
442 if [ "$sort_numeric" ]; then
443 gt="-gt"
444 curitem_mod="${curitem_mod%%[!0-9]*}"
445 # NB: trailing non-digits removed
446 # otherwise numeric comparison fails
447 else
448 gt=">"
449 fi
450 esac
451
452 # If first time through, short-circuit below position-search
453 if [ $i -le 1 ]; then
454 d=0
455 else
456 d=1
457 fi
458
459 #
460 # Find appropriate element position
461 #
462 while [ $d -gt 0 ]
463 do
464 dest_haskey=$curitem_haskey
465 eval dest=\"\$dest_$d\"
466 dest_mod="$dest" # for modified comparison
467 dest_orig="$dest" # for original comparison
468
469 # Trim leading whitespace if desired
470 if [ "$sort_ignore_leading_space" ]; then
471 while case "$dest_orig" in
472 [$IFS]*) : ;; *) false; esac
473 do
474 dest_orig="${dest_orig#?}"
475 done
476 dest_mod="$dest_orig"
477 fi
478
479 # Shift modified value if sort field (-k POS) is > 1
480 n=$sort_field
481 while [ $n -gt 1 ]; do
482 case "$dest_mod" in
483 *[$sort_sep]*)
484 # Cut text up-to (and incl.) 1st sep
485 dest_mod="${dest_mod#*[$sort_sep]}"
486
487 # Skip NULLs unless strict fields
488 [ "$sort_strict_fields" ] ||
489 [ "${dest_mod%%[$sort_sep]*}" ] ||
490 [ $n -eq 2 ] ||
491 continue
492 ;;
493 *)
494 # Asked for a field that doesn't exist
495 dest_haskey= break
496 esac
497 n=$(( $n - 1 ))
498 done
499
500 # Trim trailing words if sort field >= 1
501 [ $sort_field -ge 1 -a "$sort_numeric" ] &&
502 dest_mod="${dest_mod%%[$sort_sep]*}"
503
504 # Apply optional trim (-k POS.TRIM), cut leading chars
505 dest_mod="${dest_mod#$trim}"
506
507 # Determine type of modified comparison to use
508 # NB: Prefer numerical if requested, fallback to std
509 case "$dest_mod" in
510 ""|[!0-9]*) # NULL or begins with non-number
511 gt=">"
512 [ "$sort_numeric" ] && dest_mod=0
513 ;;
514 *)
515 if [ "$sort_numeric" ]; then
516 gt="-gt"
517 dest_mod="${dest_mod%%[!0-9]*}"
518 # NB: kill trailing non-digits
519 # for numeric comparison safety
520 else
521 gt=">"
522 fi
523 esac
524
525 # Break if we've found the proper element position
526 if [ "$curitem_haskey" -a "$dest_haskey" ]; then
527 if [ "$dest_mod" = "$curitem_mod" ]; then
528 [ "$dest_orig" ">" "$curitem_orig" ] &&
529 break
530 elif [ "$dest_mod" $gt "$curitem_mod" ] \
531 2> /dev/null
532 then
533 break
534 fi
535 else
536 [ "$dest_orig" ">" "$curitem_orig" ] && break
537 fi
538
539 # Break if we've hit the end
540 [ $d -ge $i ] && break
541
542 d=$(( $d + 1 ))
543 done
544
545 # Shift remaining positions forward, making room for new item
546 n=$i
547 while [ $n -ge $d ]; do
548 # Shift destination item forward one placement
549 eval dest_$(( $n + 1 ))=\"\$dest_$n\"
550 n=$(( $n - 1 ))
551 done
552
553 # Place the element
554 if [ $i -eq 1 ]; then
555 local dest_1="$curitem"
556 else
557 local dest_$d="$curitem"
558 fi
559
560 i=$(( $i + 1 ))
561 done
562
563 # Print sorted results
564 d=1
565 while [ $d -le $nitems ]; do
566 eval echo \"\$dest_$d\"
567 d=$(( $d + 1 ))
568 done
569}
570
571#
318# wait_for_pids pid [pid ...]
319# spins until none of the pids exist
320#
321wait_for_pids()
322{
323 local _list _prefix _nlist _j
324
325 _list="$@"

--- 1193 unchanged lines hidden (view full) ---

1519 info "$1 kernel module loaded."
1520 fi
1521 else
1522 debug "load_kld: $1 kernel module already loaded."
1523 fi
1524 return 0
1525}
1526
572# wait_for_pids pid [pid ...]
573# spins until none of the pids exist
574#
575wait_for_pids()
576{
577 local _list _prefix _nlist _j
578
579 _list="$@"

--- 1193 unchanged lines hidden (view full) ---

1773 info "$1 kernel module loaded."
1774 fi
1775 else
1776 debug "load_kld: $1 kernel module already loaded."
1777 fi
1778 return 0
1779}
1780
1527# ltr str src dst
1781# ltr str src dst [var]
1528# Change every $src in $str to $dst.
1529# Useful when /usr is not yet mounted and we cannot use tr(1), sed(1) nor
1782# Change every $src in $str to $dst.
1783# Useful when /usr is not yet mounted and we cannot use tr(1), sed(1) nor
1530# awk(1).
1784# awk(1). If var is non-NULL, set it to the result.
1531ltr()
1532{
1785ltr()
1786{
1533 local _str _src _dst _out _com
1534 _str=$1
1535 _src=$2
1536 _dst=$3
1787 local _str _src _dst _out _com _var
1788 _str="$1"
1789 _src="$2"
1790 _dst="$3"
1791 _var="$4"
1537 _out=""
1538
1792 _out=""
1793
1539 IFS=${_src}
1794 local IFS="${_src}"
1540 for _com in ${_str}; do
1541 if [ -z "${_out}" ]; then
1542 _out="${_com}"
1543 else
1544 _out="${_out}${_dst}${_com}"
1545 fi
1546 done
1795 for _com in ${_str}; do
1796 if [ -z "${_out}" ]; then
1797 _out="${_com}"
1798 else
1799 _out="${_out}${_dst}${_com}"
1800 fi
1801 done
1547 echo "${_out}"
1802 if [ -n "${_var}" ]; then
1803 setvar "${_var}" "${_out}"
1804 else
1805 echo "${_out}"
1806 fi
1548}
1549
1550# Creates a list of providers for GELI encryption.
1551geli_make_list()
1552{
1553 local devices devices2
1554 local provider mountpoint type options rest
1555

--- 204 unchanged lines hidden ---
1807}
1808
1809# Creates a list of providers for GELI encryption.
1810geli_make_list()
1811{
1812 local devices devices2
1813 local provider mountpoint type options rest
1814

--- 204 unchanged lines hidden ---