rc.subr (139949) | rc.subr (146490) |
---|---|
1# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $ | 1# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $ |
2# $FreeBSD: head/etc/rc.subr 139949 2005-01-09 23:46:37Z keramida $ | 2# $FreeBSD: head/etc/rc.subr 146490 2005-05-22 16:22:23Z schweikh $ |
3# 4# Copyright (c) 1997-2002 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 --- 94 unchanged lines hidden (view full) --- 105# has check to make sure this call is necessary 106# $1 - filename of script, in /etc/rc.d, to run 107# 108force_depend() 109{ 110 _depend="$1" 111 112 info "${name} depends on ${_depend}, which will be forced to start." | 3# 4# Copyright (c) 1997-2002 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 --- 94 unchanged lines hidden (view full) --- 105# has check to make sure this call is necessary 106# $1 - filename of script, in /etc/rc.d, to run 107# 108force_depend() 109{ 110 _depend="$1" 111 112 info "${name} depends on ${_depend}, which will be forced to start." |
113 if ! /etc/rc.d/${_depend} forcestart ; then | 113 if ! /etc/rc.d/${_depend} forcestart; then |
114 warn "Unable to force ${_depend}. It may already be running." 115 return 1 116 fi 117 return 0 118} 119 120# 121# checkyesno var --- 147 unchanged lines hidden (view full) --- 269 _fp_match='case "$_arg0" in 270 $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})")' 271 fi 272 273 _proccheck=' 274 ps 2>/dev/null -o "pid,command" '"$_psargs"' | 275 while read _npid '"$_fp_args"'; do 276 case "$_npid" in | 114 warn "Unable to force ${_depend}. It may already be running." 115 return 1 116 fi 117 return 0 118} 119 120# 121# checkyesno var --- 147 unchanged lines hidden (view full) --- 269 _fp_match='case "$_arg0" in 270 $_procname|$_procnamebn|${_procnamebn}:|"(${_procnamebn})")' 271 fi 272 273 _proccheck=' 274 ps 2>/dev/null -o "pid,command" '"$_psargs"' | 275 while read _npid '"$_fp_args"'; do 276 case "$_npid" in |
277 PID) 278 continue ;; 279 esac ; '"$_fp_match"' 280 echo -n "$_pref$_npid" ; | 277 PID) 278 continue;; 279 esac; '"$_fp_match"' 280 echo -n "$_pref$_npid"; |
281 _pref=" " 282 ;; 283 esac 284 done' 285 286# debug "in _find_processes: proccheck is ($_proccheck)." 287 eval $_proccheck 288} --- 538 unchanged lines hidden (view full) --- 827 828 unset name command command_args command_interpreter \ 829 extra_commands pidfile procname \ 830 rcvar required_dirs required_files required_vars 831 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd 832 833 case "$_file" in 834 *.sh) # run in current shell | 281 _pref=" " 282 ;; 283 esac 284 done' 285 286# debug "in _find_processes: proccheck is ($_proccheck)." 287 eval $_proccheck 288} --- 538 unchanged lines hidden (view full) --- 827 828 unset name command command_args command_interpreter \ 829 extra_commands pidfile procname \ 830 rcvar required_dirs required_files required_vars 831 eval unset ${_arg}_cmd ${_arg}_precmd ${_arg}_postcmd 832 833 case "$_file" in 834 *.sh) # run in current shell |
835 set $_arg ; . $_file | 835 set $_arg; . $_file |
836 ;; 837 *[~#]|*.OLD|*.orig|*,v) # scratch file; skip 838 warn "Ignoring scratch file $_file" 839 ;; 840 *) # run in subshell 841 if [ -x $_file ]; then 842 if [ -n "$rc_fast_and_loose" ]; then | 836 ;; 837 *[~#]|*.OLD|*.orig|*,v) # scratch file; skip 838 warn "Ignoring scratch file $_file" 839 ;; 840 *) # run in subshell 841 if [ -x $_file ]; then 842 if [ -n "$rc_fast_and_loose" ]; then |
843 set $_arg ; . $_file | 843 set $_arg; . $_file |
844 else 845 ( trap "echo Script $_file interrupted; kill -QUIT $$" 3 846 trap "echo Script $_file interrupted; exit 1" 2 | 844 else 845 ( trap "echo Script $_file interrupted; kill -QUIT $$" 3 846 trap "echo Script $_file interrupted; exit 1" 2 |
847 set $_arg ; . $_file ) | 847 set $_arg; . $_file ) |
848 fi 849 fi 850 ;; 851 esac 852} 853 854# 855# load_rc_config --- 23 unchanged lines hidden (view full) --- 879 debug "Sourcing /etc/rc.conf.d/${_command}" 880 . /etc/rc.conf.d/"$_command" 881 fi 882 883 # XXX - Deprecated variable name support 884 # 885 case ${OSTYPE} in 886 FreeBSD) | 848 fi 849 fi 850 ;; 851 esac 852} 853 854# 855# load_rc_config --- 23 unchanged lines hidden (view full) --- 879 debug "Sourcing /etc/rc.conf.d/${_command}" 880 . /etc/rc.conf.d/"$_command" 881 fi 882 883 # XXX - Deprecated variable name support 884 # 885 case ${OSTYPE} in 886 FreeBSD) |
887 [ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable" 888 [ -n "$portmap_program" ] && rpcbind_program="$portmap_program" 889 [ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags" 890 [ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable" 891 [ -n "$xntpd_enable" ] && ntpd_enable="$xntpd_enable" 892 [ -n "$xntpd_program" ] && ntpd_program="$xntpd_program" 893 [ -n "$xntpd_flags" ] && ntpd_flags="$xntpd_flags" | 887 [ -n "$portmap_enable" ] && rpcbind_enable="$portmap_enable" 888 [ -n "$portmap_program" ] && rpcbind_program="$portmap_program" 889 [ -n "$portmap_flags" ] && rpcbind_flags="$portmap_flags" 890 [ -n "$single_mountd_enable" ] && mountd_enable="$single_mountd_enable" 891 [ -n "$xntpd_enable" ] && ntpd_enable="$xntpd_enable" 892 [ -n "$xntpd_program" ] && ntpd_program="$xntpd_program" 893 [ -n "$xntpd_flags" ] && ntpd_flags="$xntpd_flags" |
894 [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program" 895 [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags" | 894 [ -n "$dhcp_program" ] && dhclient_program="$dhcp_program" 895 [ -n "$dhcp_flags" ] && dhclient_flags="$dhcp_flags" |
896 ;; | 896 ;; |
897 esac | 897 esac |
898 | |
899} 900 901# 902# rc_usage commands 903# Print a usage string for $0, with `commands' being a list of 904# valid commands. 905# 906rc_usage() --- 61 unchanged lines hidden (view full) --- 968# 969debug() 970{ 971 case ${rc_debug} in 972 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 973 if [ -x /usr/bin/logger ]; then 974 logger "$0: INFO: $*" 975 fi | 898} 899 900# 901# rc_usage commands 902# Print a usage string for $0, with `commands' being a list of 903# valid commands. 904# 905rc_usage() --- 61 unchanged lines hidden (view full) --- 967# 968debug() 969{ 970 case ${rc_debug} in 971 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 972 if [ -x /usr/bin/logger ]; then 973 logger "$0: INFO: $*" 974 fi |
976 echo 1>&2 "$0: DEBUG: $*" | 975 echo 1>&2 "$0: DEBUG: $*" |
977 ;; 978 esac 979} 980 981# 982# backup_file action file cur backup 983# Make a backup copy of `file' into `cur', and save the previous 984# version of `cur' as `backup' or use rcs for archiving. --- 96 unchanged lines hidden (view full) --- 1081 if [ -z "$src" -o -z "$link" ]; then 1082 warn "$_me: requires two arguments." 1083 return 1 1084 fi 1085 if [ ! -d "$linkdir" ]; then 1086 warn "$_me: the directory $linkdir does not exist" 1087 return 1 1088 fi | 976 ;; 977 esac 978} 979 980# 981# backup_file action file cur backup 982# Make a backup copy of `file' into `cur', and save the previous 983# version of `cur' as `backup' or use rcs for archiving. --- 96 unchanged lines hidden (view full) --- 1080 if [ -z "$src" -o -z "$link" ]; then 1081 warn "$_me: requires two arguments." 1082 return 1 1083 fi 1084 if [ ! -d "$linkdir" ]; then 1085 warn "$_me: the directory $linkdir does not exist" 1086 return 1 1087 fi |
1089 if ! ln -sf $src $link ; then | 1088 if ! ln -sf $src $link; then |
1090 warn "$_me: unable to make a symbolic link from $link to $src" 1091 return 1 1092 fi 1093 return 0 1094} 1095 1096# devfs_rulesets_from_file file 1097# Reads a set of devfs commands from file, and creates --- 32 unchanged lines hidden (view full) --- 1130 rulename=`expr "$line" : "\[\(.*\)=[0-9]*\]"` 1131 if [ -z "$rulename" ]; then 1132 warn "$_me: cannot extract rule name ($line)" 1133 _err=1 1134 break; 1135 fi 1136 eval $rulename=\$rulenum 1137 debug "found ruleset: $rulename=$rulenum" | 1089 warn "$_me: unable to make a symbolic link from $link to $src" 1090 return 1 1091 fi 1092 return 0 1093} 1094 1095# devfs_rulesets_from_file file 1096# Reads a set of devfs commands from file, and creates --- 32 unchanged lines hidden (view full) --- 1129 rulename=`expr "$line" : "\[\(.*\)=[0-9]*\]"` 1130 if [ -z "$rulename" ]; then 1131 warn "$_me: cannot extract rule name ($line)" 1132 _err=1 1133 break; 1134 fi 1135 eval $rulename=\$rulenum 1136 debug "found ruleset: $rulename=$rulenum" |
1138 if ! /sbin/devfs rule -s $rulenum delset ; then | 1137 if ! /sbin/devfs rule -s $rulenum delset; then |
1139 _err=1 1140 break 1141 fi 1142 ;; 1143 *) 1144 rulecmd="${line%%"\#*"}" 1145 # evaluate the command incase it includes 1146 # other rules --- 24 unchanged lines hidden (view full) --- 1171 local file _me 1172 _me="devfs_init_rulesets" 1173 1174 # Go through this only once 1175 if [ -n "$devfs_rulesets_init" ]; then 1176 debug "$_me: devfs rulesets already initialized" 1177 return 1178 fi | 1138 _err=1 1139 break 1140 fi 1141 ;; 1142 *) 1143 rulecmd="${line%%"\#*"}" 1144 # evaluate the command incase it includes 1145 # other rules --- 24 unchanged lines hidden (view full) --- 1170 local file _me 1171 _me="devfs_init_rulesets" 1172 1173 # Go through this only once 1174 if [ -n "$devfs_rulesets_init" ]; then 1175 debug "$_me: devfs rulesets already initialized" 1176 return 1177 fi |
1179 for file in $devfs_rulesets ; do | 1178 for file in $devfs_rulesets; do |
1180 devfs_rulesets_from_file $file || return 1 1181 done 1182 devfs_rulesets_init=1 1183 debug "$_me: devfs rulesets initialized" 1184 return 0 1185} 1186 1187# devfs_set_ruleset ruleset [dir] --- 8 unchanged lines hidden (view full) --- 1196 [ -n "$2" ] && devdir="-m "$2"" || devdir= 1197 _me="devfs_set_ruleset" 1198 1199 if [ -z "$rs" ]; then 1200 warn "$_me: you must specify a ruleset number" 1201 return 1 1202 fi 1203 debug "$_me: setting ruleset ($rs) on mount-point (${devdir#-m })" | 1179 devfs_rulesets_from_file $file || return 1 1180 done 1181 devfs_rulesets_init=1 1182 debug "$_me: devfs rulesets initialized" 1183 return 0 1184} 1185 1186# devfs_set_ruleset ruleset [dir] --- 8 unchanged lines hidden (view full) --- 1195 [ -n "$2" ] && devdir="-m "$2"" || devdir= 1196 _me="devfs_set_ruleset" 1197 1198 if [ -z "$rs" ]; then 1199 warn "$_me: you must specify a ruleset number" 1200 return 1 1201 fi 1202 debug "$_me: setting ruleset ($rs) on mount-point (${devdir#-m })" |
1204 if ! /sbin/devfs $devdir ruleset $rs ; then | 1203 if ! /sbin/devfs $devdir ruleset $rs; then |
1205 warn "$_me: unable to set ruleset $rs to ${devdir#-m }" 1206 return 1 1207 fi 1208 return 0 1209} 1210 1211# devfs_apply_ruleset ruleset [dir] 1212# Apply ruleset number $ruleset to the devfs mountpoint $dir. --- 8 unchanged lines hidden (view full) --- 1221 [ -n "$2" ] && devdir="-m "$2"" || devdir= 1222 _me="devfs_apply_ruleset" 1223 1224 if [ -z "$rs" ]; then 1225 warn "$_me: you must specify a ruleset" 1226 return 1 1227 fi 1228 debug "$_me: applying ruleset ($rs) to mount-point (${devdir#-m })" | 1204 warn "$_me: unable to set ruleset $rs to ${devdir#-m }" 1205 return 1 1206 fi 1207 return 0 1208} 1209 1210# devfs_apply_ruleset ruleset [dir] 1211# Apply ruleset number $ruleset to the devfs mountpoint $dir. --- 8 unchanged lines hidden (view full) --- 1220 [ -n "$2" ] && devdir="-m "$2"" || devdir= 1221 _me="devfs_apply_ruleset" 1222 1223 if [ -z "$rs" ]; then 1224 warn "$_me: you must specify a ruleset" 1225 return 1 1226 fi 1227 debug "$_me: applying ruleset ($rs) to mount-point (${devdir#-m })" |
1229 if ! /sbin/devfs $devdir rule -s $rs applyset ; then | 1228 if ! /sbin/devfs $devdir rule -s $rs applyset; then |
1230 warn "$_me: unable to apply ruleset $rs to ${devdir#-m }" 1231 return 1 1232 fi 1233 return 0 1234} 1235 1236# devfs_domount dir [ruleset] 1237# Mount devfs on dir. If ruleset is specified it is set --- 7 unchanged lines hidden (view full) --- 1245 [ -n "$2" ] && rs=$2 || rs= 1246 _me="devfs_domount()" 1247 1248 if [ -z "$devdir" ]; then 1249 warn "$_me: you must specify a mount-point" 1250 return 1 1251 fi 1252 debug "$_me: mount-point is ($devdir), ruleset is ($rs)" | 1229 warn "$_me: unable to apply ruleset $rs to ${devdir#-m }" 1230 return 1 1231 fi 1232 return 0 1233} 1234 1235# devfs_domount dir [ruleset] 1236# Mount devfs on dir. If ruleset is specified it is set --- 7 unchanged lines hidden (view full) --- 1244 [ -n "$2" ] && rs=$2 || rs= 1245 _me="devfs_domount()" 1246 1247 if [ -z "$devdir" ]; then 1248 warn "$_me: you must specify a mount-point" 1249 return 1 1250 fi 1251 debug "$_me: mount-point is ($devdir), ruleset is ($rs)" |
1253 if ! mount -t devfs dev "$devdir" ; then | 1252 if ! mount -t devfs dev "$devdir"; then |
1254 warn "$_me: Unable to mount devfs on $devdir" 1255 return 1 1256 fi 1257 if [ -n "$rs" ]; then 1258 devfs_init_rulesets 1259 devfs_set_ruleset $rs $devdir 1260 devfs -m $devdir rule applyset 1261 fi --- 10 unchanged lines hidden (view full) --- 1272devfs_mount_jail() 1273{ 1274 local jdev rs _me 1275 jdev="$1" 1276 [ -n "$2" ] && rs=$2 || rs="devfsrules_jail" 1277 _me="devfs_mount_jail" 1278 1279 devfs_init_rulesets | 1253 warn "$_me: Unable to mount devfs on $devdir" 1254 return 1 1255 fi 1256 if [ -n "$rs" ]; then 1257 devfs_init_rulesets 1258 devfs_set_ruleset $rs $devdir 1259 devfs -m $devdir rule applyset 1260 fi --- 10 unchanged lines hidden (view full) --- 1271devfs_mount_jail() 1272{ 1273 local jdev rs _me 1274 jdev="$1" 1275 [ -n "$2" ] && rs=$2 || rs="devfsrules_jail" 1276 _me="devfs_mount_jail" 1277 1278 devfs_init_rulesets |
1280 if ! devfs_domount "$jdev" $rs ; then | 1279 if ! devfs_domount "$jdev" $rs; then |
1281 warn "$_me: devfs was not mounted on $jdev" 1282 return 1 1283 fi 1284 return 0 1285} 1286 1287# Provide a function for normalizing the mounting of memory 1288# filesystems. This should allow the rest of the code here to remain 1289# as close as possible between 5-current and 4-stable. 1290# $1 = size 1291# $2 = mount point 1292# $3 = (optional) extra mdmfs flags | 1280 warn "$_me: devfs was not mounted on $jdev" 1281 return 1 1282 fi 1283 return 0 1284} 1285 1286# Provide a function for normalizing the mounting of memory 1287# filesystems. This should allow the rest of the code here to remain 1288# as close as possible between 5-current and 4-stable. 1289# $1 = size 1290# $2 = mount point 1291# $3 = (optional) extra mdmfs flags |
1293mount_md() { | 1292mount_md() 1293{ |
1294 if [ -n "$3" ]; then 1295 flags="$3" 1296 fi 1297 /sbin/mdmfs $flags -s $1 -M md $2 1298} 1299 1300fi | 1294 if [ -n "$3" ]; then 1295 flags="$3" 1296 fi 1297 /sbin/mdmfs $flags -s $1 -M md $2 1298} 1299 1300fi |