[Midnightbsd-cvs] src: sbin/devd: Add functions to replace usbd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Nov 16 17:08:57 EST 2008


Log Message:
-----------
Add functions to replace usbd

Modified Files:
--------------
    src/sbin/devd:
        Makefile (r1.2 -> r1.3)
        devd.8 (r1.1.1.2 -> r1.2)
        devd.cc (r1.2 -> r1.3)
        devd.conf.5 (r1.1.1.1 -> r1.2)
        devd.hh (r1.2 -> r1.3)

-------------- next part --------------
Index: devd.conf.5
===================================================================
RCS file: /home/cvs/src/sbin/devd/devd.conf.5,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/devd/devd.conf.5 -L sbin/devd/devd.conf.5 -u -r1.1.1.1 -r1.2
--- sbin/devd/devd.conf.5
+++ sbin/devd/devd.conf.5
@@ -22,7 +22,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: src/sbin/devd/devd.conf.5,v 1.8 2003/03/03 11:51:30 ru Exp $
+.\" $FreeBSD: src/sbin/devd/devd.conf.5,v 1.11 2006/10/24 20:20:41 ru Exp $
 .\"
 .\" The section on comments was taken from named.conf.5, which has the
 .\" following copyright:
@@ -41,7 +41,7 @@
 .\" ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 .\" SOFTWARE.
 .\"
-.Dd October 17, 2002
+.Dd October 25, 2006
 .Dt DEVD.CONF 5
 .Os
 .Sh NAME
@@ -60,19 +60,22 @@
 .Pp
 The following statements are supported:
 .Bl -tag -width ".Ic options"
-.It Ic options
-specifies various options and parameters for the operation of
-.Xr devd 8 .
 .It Ic attach
-specifies various matching criteria and actions to perform when
+Specifies various matching criteria and actions to perform when
 a newly attached device matches said criteria.
 .It Ic detach
-specifies various matching criteria and actions to perform when
+Specifies various matching criteria and actions to perform when
 a newly detached device matches said criteria.
 .It Ic nomatch
-specifies various matching criteria and actions to perform when
+Specifies various matching criteria and actions to perform when
 no device driver currently loaded in the kernel claims a (new)
 device.
+.It Ic notify
+Specifies various matching criteria and actions to perform when the kernel
+sends an event notification to userland.
+.It Ic options
+Specifies various options and parameters for the operation of
+.Xr devd 8 .
 .El
 .Pp
 Statements may occur in any order in the configuration file, and may be
@@ -80,6 +83,254 @@
 Further details on the syntax and meaning of each statement and their
 substatements are explained below.
 .Pp
+Each statement, except
+.Ic options
+has a priority (an arbitrary number) associated with it, where
+.Ql 0
+is defined as the lowest priority.
+If two statements match the same event, only the action of the statement with
+highest priority will be executed.
+In this way generic statements can be overridden for devices or
+notifications that require special attention.
+.Pp
+The general syntax of a statement is:
+.Pp
+.Bd -literal -offset indent
+statement priority {
+	substatement "value";
+	...
+	substatement "value";
+};
+.Ed
+.Ss Sub-statements
+The following sub-statements are supported within the
+.Ic options
+statement.
+.Bl -tag -width ".Ic directory"
+.It Ic directory Qq Ar /some/path ;
+Adds the given directory to the list of directories from which
+.Xr devd 8
+will read
+configuration files.
+Any number of
+.Ic directory
+statements can be used.
+.It Ic pid-file Qq Pa /var/run/devd.pid ;
+Specifies PID file.
+.It Ic set Ar regexp-name Qq Ar (some|regexp) ;
+Creates a regular expression and assigns it to the variable
+.Ar regexp-name .
+The variable is avaiable throughout the rest of
+the configuration file.
+All regular expressions have an implicit
+.Ql ^$
+around them.
+.El
+.Pp
+The following sub-statements are supported within the
+.Ic attach
+and
+.Ic detach
+statements.
+.Bl -tag -width ".Ic directory"
+.It Ic action Qq Ar command ;
+Command to execute upon a successful match.
+Example
+.Dq Li "/etc/pccard_ether $device-name start" .
+.It Ic class Qq Ar string ;
+This is shorthand for
+.Dq Ic match Qo Li class Qc Qq Ar string .
+.It Ic device-name Qq string ;
+This is shorthand for
+.Dq Ic match Qo Li device-name Qc Qq Ar string .
+This matches a device named
+.Ar string ,
+which is allowed to be a regular expression or a variable previously created
+containing a regular expression.
+The
+.Dq Li device-name
+variable
+is available for later use with the
+.Ic action
+statement.
+.It Ic match Qo Ar variable Qc Qq Ar value ;
+Matches the content of
+.Ar value
+against
+.Ar variable ;
+the content of
+.Ar value
+may be a regular expression.
+Not required during
+.Ic attach
+nor
+.Ic detach
+events since the
+.Ic device-name
+statement takes care of all device matching.
+For a partial list of variables, see below.
+.It Ic media-type Qq Ar string ;
+For network devices,
+.Ic media-type
+will match devices that have the given media type.
+Valid media types are:
+.Dq Li Ethernet ,
+.Dq Li Tokenring ,
+.Dq Li FDDI ,
+.Dq Li 802.11 ,
+.Dq Li ATM ,
+and
+.Dq Li CARP .
+.It Ic subdevice Qq Ar string ;
+This is shorthand for
+.Dq Ic match Qo Li subdevice Qc Qq Ar string .
+.El
+.Pp
+The following sub-statements are supported within the
+.Ic nomatch
+statement.
+.Bl -tag -width ".Ic directory"
+.It Ic action Qq Ar command ;
+Same as above.
+.It Ic match Qo Ar variable Qc Qq Ar value ;
+Matches the content of
+.Ar value
+against
+.Ar variable ;
+the content of
+.Ar value
+may be a regular expression.
+For a partial list of variables, see below.
+.El
+.Pp
+The following sub-statements are supported within the
+.Ic notify
+statement.
+The
+.Dq Li notify
+variable is avaiable inside this statement and contains, a value, depending
+on which system and subsystem that delivered the event.
+.Bl -tag -width ".Ic directory"
+.It Ic action Qq Ar command ;
+Command to execute upon a successful match.
+Example
+.Dq Li "/etc/rc.d/power_profile $notify" .
+.It Ic match Qo Ar system | subsystem | type | notify Qc Qq Ar value ;
+Any number of
+.Ic match
+statements can exist within a
+.Ic notify
+statement;
+.Ar value
+can be either a fixed string or a regular expression.
+Below is a list of avaiable systems, subsystems, and types.
+.It Ic media-type Qq Ar string ;
+See above.
+.El
+.Ss Variables that can be used with the match statement
+A partial list of variables and their possible values that can be used together
+with the
+.Ic match
+statement.
+.Pp
+.Bl -tag -width ".Li manufacturer" -compact
+.It Ic Variable
+.Ic Description
+.It Li bus
+Device name of parent bus.
+.It Li cisproduct
+CIS-product.
+.It Li cisvendor
+CIS-vendor.
+.It Li class
+Device class.
+.It Li device
+Device ID.
+.It Li device-name
+Name of attached/detached device.
+.It Li function
+Card functions.
+.It Li manufacturer
+Manufacturer ID (pccard).
+.It Li notify
+Match the value of the
+.Dq Li notify
+variable.
+.It Li product
+Product ID (pccard).
+.It Li serial
+Serial Number (USB).
+.It Li slot
+Card slot.
+.It Li subvendor
+Sub-vendor ID.
+.It Li subdevice
+Sub-device ID.
+.It Li subsystem
+Matches a subsystem of a system, see below.
+.It Li system
+Matches a system type, see below.
+.It Li type
+Type of notification, see below.
+.It Li vendor
+Vendor ID.
+.El
+.Ss Notify matching
+A partial list of systems, subsystems, and types used within the
+.Ic notify
+mechanism.
+.Pp
+.Bl -tag -width ".Li IFNET" -compact
+.It Sy System
+.It Li ACPI
+Events related to the ACPI subsystem.
+.Bl -tag -width ".Sy Subsystem" -compact
+.It Sy Subsystem
+.It Li ACAD
+AC line state ($notify=0x00 is offline, 0x01 is online).
+.It Li Button
+Button state ($notify=0x00 is power, 0x01 is sleep).
+.It Li CMBAT
+Battery events.
+.It Li Lid
+Lid state ($notify=0x00 is closed, 0x01 is open).
+.It Li Thermal
+Thermal zone events.
+.El
+.Pp
+.It Li IFNET
+Events related to the network subsystem.
+.Bl -tag -width ".Sy Subsystem" -compact
+.It Sy Subsystem
+.It Ar interface
+The
+.Dq subsystem
+is the actual name of the network interface on which the event
+took place.
+.Bl -tag -width ".Li LINK_DOWN" -compact
+.It Sy Type
+.It Li LINK_UP
+Carrier status changed to UP.
+.It Li LINK_DOWN
+Carrier status changed to DOWN.
+.El
+.El
+.El
+.Pp
+A link state change to UP on the interface
+.Dq Li fxp0
+would result in the following notify event:
+.Bd -literal -offset indent
+system=IFNET, subsystem=fxp0, type=LINK_UP
+.Ed
+.Pp
+An AC line state change to
+.Dq offline
+would result in the following event:
+.Bd -literal -offset indent
+system=ACPI, subsystem=ACAD, notify=0x00
+.Ed
+.Ss Comments
 Comments may appear anywhere that whitespace may appear in a
 configuration file.
 To appeal to programmers of all kinds, they can
@@ -125,5 +376,58 @@
 .Xr devd 8
 configuration file.
 .El
+.Sh EXAMPLES
+.Bd -literal
+#
+# This will catch link down events on the interfaces fxp0 and ath0
+#
+notify 0 {
+	match "system"			"IFNET";
+	match "subsystem"		"(fxp0|ath0)";
+	match "type"			"LINK_DOWN";
+	action "logger $subsystem is DOWN";
+};
+
+#
+# Match lid open/close events
+# These can be combined to a single event, by passing the
+# value of $notify to the external script.
+#
+notify 0 {
+	match "system"			"ACPI";
+	match "subsystem"		"Lid";
+	match "notify"			"0x00";
+	action "logger Lid closed, we can sleep now!";
+};
+
+notify 0 {
+	match "system"			"ACPI";
+	match "subsystem"		"Lid";
+	match "notify"			"0x01";
+	action "logger Lid opened, the sleeper must awaken!";
+};
+
+#
+# Try to configure ath and wi devices with pccard_ether
+# as they are attached.
+#
+attach 0 {
+        device-name "(ath|wi)[0-9]+";
+        action "/etc/pccard_ether $device-name start";
+};
+
+#
+# Stop ath and wi devices as they are detached from
+# the system.
+#
+detach 0 {
+        device-name "(ath|wi)[0-9]+";
+        action "/etc/pccard_ether $device-name stop";
+};
+.Ed
+.Pp
+The installed
+.Pa /etc/devd.conf
+has many additional examples.
 .Sh SEE ALSO
 .Xr devd 8
Index: devd.hh
===================================================================
RCS file: /home/cvs/src/sbin/devd/devd.hh,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/devd/devd.hh -L sbin/devd/devd.hh -u -r1.2 -r1.3
--- sbin/devd/devd.hh
+++ sbin/devd/devd.hh
@@ -23,7 +23,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sbin/devd/devd.hh,v 1.3 2005/07/10 03:37:15 imp Exp $
+ * $FreeBSD: src/sbin/devd/devd.hh,v 1.4 2006/01/30 22:50:13 pjd Exp $
  */
 
 #ifndef DEVD_HH
Index: devd.cc
===================================================================
RCS file: /home/cvs/src/sbin/devd/devd.cc,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/devd/devd.cc -L sbin/devd/devd.cc -u -r1.2 -r1.3
--- sbin/devd/devd.cc
+++ sbin/devd/devd.cc
@@ -34,7 +34,7 @@
 //	  - devd.conf needs more details on the supported statements.
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sbin/devd/devd.cc,v 1.22.2.5 2005/12/19 03:33:05 jkoshy Exp $");
+__FBSDID("$FreeBSD: src/sbin/devd/devd.cc,v 1.33 2006/09/17 22:49:26 ru Exp $");
 
 #include <sys/param.h>
 #include <sys/socket.h>
@@ -110,11 +110,7 @@
 
 event_proc::~event_proc()
 {
-	vector<eps *>::const_iterator i;
-
-	for (i = _epsvec.begin(); i != _epsvec.end(); i++)
-		delete *i;
-	_epsvec.clear();
+	delete_and_clear(_epsvec);
 }
 
 void
@@ -173,7 +169,7 @@
 	_re = "^";
 	_re.append(c.expand_string(string(re)));
 	_re.append("$");
-	regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB);
+	regcomp(&_regex, _re.c_str(), REG_EXTENDED | REG_NOSUB | REG_ICASE);
 }
 
 match::~match()
@@ -199,7 +195,7 @@
 #include <net/if.h>
 #include <net/if_media.h>
 
-media::media(config &c, const char *var, const char *type)
+media::media(config &, const char *var, const char *type)
 	: _var(var), _type(-1)
 {
 	static struct ifmedia_description media_types[] = {
@@ -382,7 +378,7 @@
 	pfh = pidfile_open(_pidfile.c_str(), 0600, &otherpid);
 	if (pfh == NULL) {
 		if (errno == EEXIST)
-			 errx(1, "devd already running, pid: %d", (int)otherpid);
+			errx(1, "devd already running, pid: %d", (int)otherpid);
 		warn("cannot open pid file");
 	}
 }
@@ -390,14 +386,16 @@
 void
 config::write_pidfile()
 {
+	
 	pidfile_write(pfh);
 }
-  	 
+
 void
 config::remove_pidfile()
 {
+	
 	pidfile_remove(pfh);
-} 	 
+}
 
 void
 config::add_attach(int prio, event_proc *p)
@@ -604,7 +602,7 @@
 {
 	vector<event_proc *> *l;
 	vector<event_proc *>::const_iterator i;
-	char *s;
+	const char *s;
 
 	switch (type) {
 	default:
@@ -904,7 +902,7 @@
 static void
 usage()
 {
-	fprintf(stderr, "usage: %s [-Ddn]\n", getprogname());
+	fprintf(stderr, "usage: %s [-Ddn] [-f file]\n", getprogname());
 	exit(1);
 }
 
Index: devd.8
===================================================================
RCS file: /home/cvs/src/sbin/devd/devd.8,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sbin/devd/devd.8 -L sbin/devd/devd.8 -u -r1.1.1.2 -r1.2
--- sbin/devd/devd.8
+++ sbin/devd/devd.8
@@ -23,7 +23,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\" $FreeBSD: src/sbin/devd/devd.8,v 1.14.2.1 2005/12/19 03:33:05 jkoshy Exp $
+.\" $FreeBSD: src/sbin/devd/devd.8,v 1.17 2006/09/17 22:49:26 ru Exp $
 .\"
 .Dd November 24, 2005
 .Dt DEVD 8
@@ -33,9 +33,8 @@
 .Nd "device state change daemon"
 .Sh SYNOPSIS
 .Nm
-.Op Fl Dd
+.Op Fl Ddn
 .Op Fl f Ar file
-.Op Fl n
 .Sh DESCRIPTION
 The
 .Nm
@@ -43,7 +42,7 @@
 kernel events happen.
 .Pp
 The following options are accepted.
-.Bl -tag -width indent-two
+.Bl -tag -width ".Fl f Ar file"
 .It Fl D
 Enable debugging messages.
 .It Fl d
Index: Makefile
===================================================================
RCS file: /home/cvs/src/sbin/devd/Makefile,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/devd/Makefile -L sbin/devd/Makefile -u -r1.2 -r1.3
--- sbin/devd/Makefile
+++ sbin/devd/Makefile
@@ -1,9 +1,9 @@
-# $FreeBSD: src/sbin/devd/Makefile,v 1.6 2004/12/21 09:59:42 ru Exp $
+# $FreeBSD: src/sbin/devd/Makefile,v 1.8 2006/01/30 22:50:13 pjd Exp $
 
 PROG_CXX=devd
 SRCS=	devd.cc token.l parse.y y.tab.h
 MAN=	devd.8 devd.conf.5
-WARNS?=	1
+WARNS?=	4
 
 NO_SHARED?=YES
 
@@ -13,8 +13,6 @@
 YFLAGS+=-v
 CFLAGS+=-I. -I${.CURDIR}
 
-WARNS?=6
-
 CLEANFILES= y.output
 
 .include <bsd.prog.mk>


More information about the Midnightbsd-cvs mailing list