Date: Thu, 22 Dec 2005 22:09:15 -0800 From: "Darren Pilgrim" <darren.pilgrim@bitfreak.org> To: <freebsd-rc@freebsd.org> Subject: /etc/rc.d/devfs modification to allow wildcard device names in /etc/devfs.conf Message-ID: <000d01c60787$6a431b40$652a15ac@smiley>
next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format. ------=_NextPart_000_000E_01C60744.5C1FDB40 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I recently needed to change the default permissions of some of the "dial out" serial devices on a system for use with NUT (sysutils/nut port). = For the sake of efficiency, I wanted to use a wildcard expression only to = find out that /etc/rc.d/devfs doesn't grok sh-style filename globbing. So I modified the script. I wrapped each sub-procedure in the case structure with a for...done that expands the device string into a list for = iteration. The result is that I can put lines like the following in = /etc/devfs.conf: own cuad[1,2]* nut:nut perm cuad[1,2]* 0660 The non-wildcard equivalent would be: own cuad1 nut:nut own cuad1.init nut:nut own cuad1.lock nut:nut own cuad2 nut:nut own cuad2.init nut:nut own cuad2.lock nut:nut perm cuad1 0660 perm cuad1.init 0660 perm cuad1.lock 0660 perm cuad2 0660 perm cuad2.init 0660 perm cuad2.lock 0660 I wrote two versions of the modification, one takes the device = expression literally (the _literal.patch file), the other explicitly expands it = with ls (the _backticked_ls.patch file). Both appear to work fine, but IMO the latter seems a safer approach. The modifications and testing were done = on a current RELENG_6_0 box where /etc/rc.d/devfs is v1.10. The v1.11 in = -HEAD is effectively identical, so it should apply cleanly to that version as well. ------=_NextPart_000_000E_01C60744.5C1FDB40 Content-Type: application/octet-stream; name="etc_rc.d_devfs_literal.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="etc_rc.d_devfs_literal.patch" --- /usr/src/etc/rc.d/devfs Fri Oct 22 23:50:50 2004=0A= +++ /etc/rc.d/devfs Wed Dec 21 01:16:24 2005=0A= @@ -41,19 +41,25 @@=0A= {=0A= if [ -r /etc/devfs.conf ]; then=0A= cd /dev=0A= - while read action device parameter; do=0A= + while read action devicelist parameter; do=0A= case "${action}" in=0A= - l*) if [ -c ${device} -a ! -e ${parameter} ]; then=0A= - ln -fs ${device} ${parameter}=0A= - fi=0A= + l*) for device in ${devicelist}; do=0A= + if [ -c ${device} -a ! -e ${parameter} ]; then=0A= + ln -fs ${device} ${parameter}=0A= + fi=0A= + done=0A= ;;=0A= - o*) if [ -c ${device} ]; then=0A= - chown ${parameter} ${device}=0A= - fi=0A= + o*) for device in ${devicelist}; do=0A= + if [ -c ${device} ]; then=0A= + chown ${parameter} ${device}=0A= + fi=0A= + done=0A= ;;=0A= - p*) if [ -c ${device} ]; then=0A= - chmod ${parameter} ${device}=0A= - fi=0A= + p*) for device in ${devicelist}; do=0A= + if [ -c ${device} ]; then=0A= + chmod ${parameter} ${device}=0A= + fi=0A= + done=0A= ;;=0A= esac=0A= done < /etc/devfs.conf=0A= ------=_NextPart_000_000E_01C60744.5C1FDB40 Content-Type: application/octet-stream; name="etc_rc.d_devfs_backticked_ls.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="etc_rc.d_devfs_backticked_ls.patch" --- /usr/src/etc/rc.d/devfs Fri Oct 22 23:50:50 2004=0A= +++ /etc/rc.d/devfs Thu Dec 22 21:33:50 2005=0A= @@ -41,19 +41,25 @@=0A= {=0A= if [ -r /etc/devfs.conf ]; then=0A= cd /dev=0A= - while read action device parameter; do=0A= + while read action devicelist parameter; do=0A= case "${action}" in=0A= - l*) if [ -c ${device} -a ! -e ${parameter} ]; then=0A= - ln -fs ${device} ${parameter}=0A= - fi=0A= + l*) for device in `ls ${devicelist}`; do=0A= + if [ -c ${device} -a ! -e ${parameter} ]; then=0A= + ln -fs ${device} ${parameter}=0A= + fi=0A= + done=0A= ;;=0A= - o*) if [ -c ${device} ]; then=0A= - chown ${parameter} ${device}=0A= - fi=0A= + o*) for device in `ls ${devicelist}`; do=0A= + if [ -c ${device} ]; then=0A= + chown ${parameter} ${device}=0A= + fi=0A= + done=0A= ;;=0A= - p*) if [ -c ${device} ]; then=0A= - chmod ${parameter} ${device}=0A= - fi=0A= + p*) for device in `ls ${devicelist}`; do=0A= + if [ -c ${device} ]; then=0A= + chmod ${parameter} ${device}=0A= + fi=0A= + done=0A= ;;=0A= esac=0A= done < /etc/devfs.conf=0A= ------=_NextPart_000_000E_01C60744.5C1FDB40--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000d01c60787$6a431b40$652a15ac>