rc.subr (117977) | rc.subr (119166) |
---|---|
1# $NetBSD: rc.subr,v 1.49 2002/05/21 12:31:01 lukem Exp $ | 1# $NetBSD: rc.subr,v 1.49 2002/05/21 12:31:01 lukem Exp $ |
2# $FreeBSD: head/etc/rc.subr 117977 2003-07-24 18:17:21Z mtm $ | 2# $FreeBSD: head/etc/rc.subr 119166 2003-08-20 06:15:18Z mtm $ |
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 --- 1017 unchanged lines hidden (view full) --- 1028 chown root:wheel $_cur 1029 ;; 1030 remove) 1031 mv -f $_cur $_back 1032 ;; 1033 esac 1034 fi 1035} | 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 --- 1017 unchanged lines hidden (view full) --- 1028 chown root:wheel $_cur 1029 ;; 1030 remove) 1031 mv -f $_cur $_back 1032 ;; 1033 esac 1034 fi 1035} |
1036 1037# devfs_link dir src link 1038# Make a symbolic link 'link' to src in chroot/dev. 1039# Returns 0 on sucess. 1040# 1041devfs_link() 1042{ 1043 local dir src link _me 1044 dir="$1" 1045 src="$2" 1046 link="$3" 1047 _me="devfs_link" 1048 1049 if [ -z "$dir" -o -z "$src" -o -z "$link" ]; then 1050 warn "devfs_link(): requires three arguments." 1051 return 1 1052 fi 1053 if [ -z "$dir" ]; then 1054 warn "$_me: the directory ($dir) does not exist" 1055 return 1 1056 fi 1057 cd ${chroot}/dev 1058 if ! ln -sf $src $link ; then 1059 warn "$_me: unable to link $link --> $src in $dir" 1060 return 1 1061 fi 1062 return 0 1063} 1064 1065# devfs_rulesets_from_file file 1066# Reads a set of devfs commands from file, and creates 1067# the specified rulesets with their rules. Returns non-zero 1068# if there was an error. 1069# 1070devfs_rulesets_from_file() 1071{ 1072 local file _err _me 1073 file="$1" 1074 _me="devfs_rulesets_from_file" 1075 _err=0 1076 1077 if [ -z "$file" ]; then 1078 warn "$_me: you must specify a file" 1079 return 1 1080 fi 1081 if [ ! -e "$file" ]; then 1082 debug "$_me: no such file ($file)" 1083 return 0 1084 fi 1085 debug "reading rulesets from file ($file)" 1086 { while read line 1087 do 1088 case $line in 1089 \#*) 1090 continue 1091 ;; 1092 \[*\]*) 1093 rulenum=`expr "$line" : "\[.*=\([0-9]*\)\]"` 1094 if [ -z "$rulenum" ]; then 1095 warn "$_me: cannot extract rule number ($line)" 1096 _err=1 1097 break 1098 fi 1099 rulename=`expr "$line" : "\[\(.*\)=[0-9]*\]"` 1100 if [ -z "$rulename" ]; then 1101 warn "$_me: cannot extract rule name ($line)" 1102 _err=1 1103 break; 1104 fi 1105 eval $rulename=\$rulenum 1106 debug "found ruleset: $rulename=$rulenum" 1107 if ! /sbin/devfs rule -s $rulenum delset ; then 1108 _err=1 1109 break 1110 fi 1111 ;; 1112 *) 1113 rulecmd="${line%%"\#*"}" 1114 # evaluate the command incase it includes 1115 # other rules 1116 if [ -n "$rulecmd" ]; then 1117 debug "adding rule ($rulecmd)" 1118 if ! eval /sbin/devfs rule -s $rulenum $rulecmd 1119 then 1120 _err=1 1121 break 1122 fi 1123 fi 1124 ;; 1125 esac 1126 if [ $_err -ne 0 ]; then 1127 debug "error in $_me" 1128 break 1129 fi 1130 done } < $file 1131 return $_err 1132} 1133 1134# devfs_init_rulesets 1135# Initializes rulesets from configuration files. Returns 1136# non-zero if there was an error. 1137# 1138devfs_init_rulesets() 1139{ 1140 local file _me 1141 _me="devfs_init_rulesets" 1142 1143 # Go through this only once 1144 if [ -n "$devfs_rulesets_init" ]; then 1145 debug "$_me: devfs rulesets already initialized" 1146 return 1147 fi 1148 for file in $devfs_rulesets ; do 1149 devfs_rulesets_from_file $file || return 1 1150 done 1151 devfs_rulesets_init=1 1152 debug "$_me: devfs rulesets initialized" 1153 return 0 1154} 1155 1156# devfs_set_ruleset ruleset [dir] 1157# Sets the default ruleset of dir to ruleset. The ruleset arguement 1158# must be a ruleset name as specified in devfs.rules(5) file. 1159# Returns non-zero if it could not set it successfully. 1160# 1161devfs_set_ruleset() 1162{ 1163 local devdir rs _me 1164 [ -n "$1" ] && eval rs=\$$1 || rs= 1165 [ -n "$2" ] && devdir="-m "$2"" || devdir= 1166 _me="devfs_set_ruleset" 1167 1168 if [ -z "$rs" ]; then 1169 warn "$_me: you must specify a ruleset number" 1170 return 1 1171 fi 1172 debug "$_me: setting ruleset ($rs) on mount-point (${devdir#-m })" 1173 if ! /sbin/devfs $devdir ruleset $rs ; then 1174 warn "$_me: unable to set ruleset $rs to ${devdir#-m }" 1175 return 1 1176 fi 1177 return 0 1178} 1179 1180# devfs_apply_ruleset ruleset [dir] 1181# Apply ruleset number $ruleset to the devfs mountpoint $dir. 1182# The ruleset argument must be a ruleset name as specified 1183# in a devfs.rules(5) file. Returns 0 on success or non-zero 1184# if it could not apply the ruleset. 1185# 1186devfs_apply_ruleset() 1187{ 1188 local devdir rs _me 1189 [ -n "$1" ] && eval rs=\$$1 || rs= 1190 [ -n "$2" ] && devdir="-m "$2"" || devdir= 1191 _me="devfs_apply_ruleset" 1192 1193 if [ -z "$rs" ]; then 1194 warn "$_me: you must specify a ruleset" 1195 return 1 1196 fi 1197 debug "$_me: applying ruleset ($rs) to mount-point (${devdir#-m })" 1198 if ! /sbin/devfs $devdir rule -s $rs applyset ; then 1199 warn "$_me: unable to apply ruleset $rs to ${devdir#-m }" 1200 return 1 1201 fi 1202 return 0 1203} 1204 1205# devfs_domount dir [ruleset] 1206# Mount devfs on dir. If ruleset is specified it is set 1207# on the mount-point. It must also be a ruleset name as specified 1208# in a devfs.rules(5) file. Returns 0 on success. 1209# 1210devfs_domount() 1211{ 1212 local devdir rs _me 1213 devdir="$1" 1214 [ -n "$2" ] && rs=$2 || rs= 1215 _me="devfs_domount()" 1216 1217 if [ -z "$devdir" ]; then 1218 warn "$_me: you must specify a mount-point" 1219 return 1 1220 fi 1221 debug "$_me: mount-point is ($devdir), ruleset is ($rs)" 1222 if ! mount -t devfs dev "$devdir" ; then 1223 warn "$_me: Unable to mount devfs on $devdir" 1224 return 1 1225 fi 1226 if [ -n "$rs" ]; then 1227 devfs_init_rulesets 1228 devfs_set_ruleset $rs $devdir 1229 fi 1230 return 0 1231} 1232 1233# devfs_mount_jail dir [ruleset] 1234# Mounts a devfs file system appropriate for jails 1235# on the directory dir. If ruleset is specified, the ruleset 1236# it names will be used instead. If present, ruleset must 1237# be the name of a ruleset as defined in a devfs.rules(5) file. 1238# This function returns non-zero if an error occurs. 1239# 1240devfs_mount_jail() 1241{ 1242 local jdev rs _me 1243 jdev="$1" 1244 [ -n "$2" ] && rs=$2 || rs="devfsrules_jail" 1245 _me="devfs_mount_jail" 1246 1247 devfs_init_rulesets 1248 if ! devfs_domount "$jdev" $rs ; then 1249 warn "$_me: devfs was not mounted on $jdev" 1250 return 1 1251 fi 1252 return 0 1253} |
|