Skip site navigation (1)Skip section navigation (2)
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

[-- Attachment #1 --]
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.

[-- Attachment #2 --]
--- /usr/src/etc/rc.d/devfs	Fri Oct 22 23:50:50 2004
+++ /etc/rc.d/devfs	Wed Dec 21 01:16:24 2005
@@ -41,19 +41,25 @@
 {
 	if [ -r /etc/devfs.conf ]; then
 		cd /dev
-		while read action device parameter; do
+		while read action devicelist parameter; do
 			case "${action}" in
-			l*)	if [ -c ${device} -a ! -e ${parameter} ]; then
-					ln -fs ${device} ${parameter}
-				fi
+			l*)	for device in ${devicelist}; do
+					if [ -c ${device} -a ! -e ${parameter} ]; then
+						ln -fs ${device} ${parameter}
+					fi
+				done
 				;;
-			o*)	if [ -c ${device} ]; then
-					chown ${parameter} ${device}
-				fi
+			o*)	for device in ${devicelist}; do
+					if [ -c ${device} ]; then
+						chown ${parameter} ${device}
+					fi
+				done
 				;;
-			p*)	if [ -c ${device} ]; then
-					chmod ${parameter} ${device}
-				fi
+			p*)	for device in ${devicelist}; do
+					if [ -c ${device} ]; then
+						chmod ${parameter} ${device}
+					fi
+				done
 				;;
 			esac
 		done < /etc/devfs.conf

[-- Attachment #3 --]
--- /usr/src/etc/rc.d/devfs	Fri Oct 22 23:50:50 2004
+++ /etc/rc.d/devfs	Thu Dec 22 21:33:50 2005
@@ -41,19 +41,25 @@
 {
 	if [ -r /etc/devfs.conf ]; then
 		cd /dev
-		while read action device parameter; do
+		while read action devicelist parameter; do
 			case "${action}" in
-			l*)	if [ -c ${device} -a ! -e ${parameter} ]; then
-					ln -fs ${device} ${parameter}
-				fi
+			l*)	for device in `ls ${devicelist}`; do
+					if [ -c ${device} -a ! -e ${parameter} ]; then
+						ln -fs ${device} ${parameter}
+					fi
+				done
 				;;
-			o*)	if [ -c ${device} ]; then
-					chown ${parameter} ${device}
-				fi
+			o*)	for device in `ls ${devicelist}`; do
+					if [ -c ${device} ]; then
+						chown ${parameter} ${device}
+					fi
+				done
 				;;
-			p*)	if [ -c ${device} ]; then
-					chmod ${parameter} ${device}
-				fi
+			p*)	for device in `ls ${devicelist}`; do
+					if [ -c ${device} ]; then
+						chmod ${parameter} ${device}
+					fi
+				done
 				;;
 			esac
 		done < /etc/devfs.conf

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000d01c60787$6a431b40$652a15ac>