Add devd and hooks
This commit is contained in:
		
							
								
								
									
										315
									
								
								etc.BSD/devd.conf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										315
									
								
								etc.BSD/devd.conf
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,315 @@ | ||||
| # $FreeBSD: src/etc/devd.conf,v 1.38 2007/06/21 22:50:36 njl Exp $ | ||||
| # | ||||
| # Refer to devd.conf(5) and devd(8) man pages for the details on how to | ||||
| # run and configure devd. | ||||
| # | ||||
|  | ||||
| # NB: All regular expressions have an implicit ^$ around them. | ||||
| # NB: device-name is shorthand for 'match device-name' | ||||
|  | ||||
| options { | ||||
| 	# Each directory directive adds a directory the list of directories | ||||
| 	# that we scan for files.  Files are read-in in the order that they | ||||
| 	# are returned from readdir(3).  The rule-sets are combined to | ||||
| 	# create a DFA that's used to match events to actions. | ||||
| 	directory "/etc/devd"; | ||||
| 	directory "/usr/local/etc/devd"; | ||||
| 	pid-file "/var/run/devd.pid"; | ||||
|  | ||||
| 	# Setup some shorthand for regex that we use later in the file. | ||||
| 	#XXX Yes, these are gross -- imp | ||||
| 	set scsi-controller-regex | ||||
| 		"(aac|adv|adw|aha|ahb|ahc|ahd|aic|amd|amr|asr|bt|ciss|ct|dpt|\ | ||||
| 		esp|ida|iir|ips|isp|mlx|mly|mpt|ncr|ncv|nsp|stg|sym|trm|wds)\ | ||||
| 		[0-9]+"; | ||||
| }; | ||||
|  | ||||
| # Note that the attach/detach with the highest value wins, so that one can | ||||
| # override these general rules. | ||||
|  | ||||
| # | ||||
| # Configure the interface on attach.  Due to a historical accident, this | ||||
| # script is called pccard_ether. | ||||
| # | ||||
| notify 0 { | ||||
| 	match "system"		"IFNET"; | ||||
| 	match "type"		"ATTACH"; | ||||
| 	action "/etc/rc.devd net.$subsystem start"; | ||||
| }; | ||||
|  | ||||
| notify 0 { | ||||
| 	match "system"		"IFNET"; | ||||
| 	match "type"		"DETACH"; | ||||
| 	action "/etc/rc.devd net.$subsystem stop"; | ||||
| }; | ||||
|  | ||||
| # | ||||
| # Try to configure the interface when the network comes up and deconfigure | ||||
| # when it goes down | ||||
| # | ||||
| notify 0 { | ||||
| 	match "system"		"IFNET"; | ||||
| 	match "type"		"LINK_UP"; | ||||
| 	media-type		"ethernet"; | ||||
| 	action "/etc/rc.devd net.$subsystem start"; | ||||
| }; | ||||
|  | ||||
| notify 0 { | ||||
| 	match "system"		"IFNET"; | ||||
| 	match "type"		"LINK_DOWN"; | ||||
| 	media-type		"ethernet"; | ||||
| 	action "/etc/rc.devd net.$subsystem stop"; | ||||
| }; | ||||
| # | ||||
| # Like Ethernet devices, but separate because | ||||
| # they have a different media type.  We may want | ||||
| # to exploit this later. | ||||
| # | ||||
| detach 0 { | ||||
| 	media-type "802.11"; | ||||
| 	action "/etc/rc.devd net.$device-name stop"; | ||||
| }; | ||||
| attach 0 { | ||||
| 	media-type "802.11"; | ||||
| 	action "/etc/rc.devd net.$device-name start"; | ||||
| }; | ||||
| notify 0 { | ||||
| 	match "system"		"IFNET"; | ||||
| 	match "type"		"LINK_UP"; | ||||
| 	media-type		"802.11"; | ||||
| 	action "/etc/rc.devd net.$subsystem start"; | ||||
| }; | ||||
| notify 0 { | ||||
| 	match "system"		"IFNET"; | ||||
| 	match "type"		"LINK_DOWN"; | ||||
| 	media-type		"802.11"; | ||||
| 	action "/etc/rc.devd net.$subsystem stop"; | ||||
| }; | ||||
|  | ||||
| # An entry like this might be in a different file, but is included here | ||||
| # as an example of how to override things.  Normally 'ed50' would match | ||||
| # the above attach/detach stuff, but the value of 100 makes it | ||||
| # hard wired to 1.2.3.4. | ||||
| attach 100 { | ||||
| 	device-name "ed50"; | ||||
| 	action "ifconfig $device-name inet 1.2.3.4 netmask 0xffff0000"; | ||||
| }; | ||||
| detach 100 { | ||||
| 	device-name "ed50"; | ||||
| }; | ||||
|  | ||||
| # When a USB Bluetooth dongle appears activate it | ||||
| attach 100 { | ||||
| 	device-name "ubt[0-9]+"; | ||||
| 	action "/etc/rc.d/bluetooth start $device-name"; | ||||
| }; | ||||
| detach 100 { | ||||
| 	device-name "ubt[0-9]+"; | ||||
| 	action "/etc/rc.d/bluetooth stop $device-name"; | ||||
| }; | ||||
|  | ||||
| # When a USB keyboard arrives, attach it as the console keyboard. | ||||
| attach 100 { | ||||
| 	device-name "ukbd0"; | ||||
| 	action "/etc/rc.d/syscons setkeyboard /dev/ukbd0"; | ||||
| }; | ||||
| detach 100 { | ||||
| 	device-name "ukbd0"; | ||||
| 	action "/etc/rc.d/syscons setkeyboard /dev/kbd0"; | ||||
| }; | ||||
|  | ||||
| # The entry below starts moused when a mouse is plugged in. Moused | ||||
| # stops automatically (actually it bombs :) when the device disappears. | ||||
| attach 100 { | ||||
| 	device-name "ums[0-9]+"; | ||||
| 	action "/etc/rc.devd moused.$device-name start"; | ||||
| }; | ||||
|  | ||||
| # Firmware download into the ActiveWire board. After the firmware download is | ||||
| # done the device detaches and reappears as something new and shiny | ||||
| # automatically. | ||||
| attach 100 { | ||||
| 	match "vendor"	"0x0854"; | ||||
| 	match "product"	"0x0100"; | ||||
| 	match "release"	"0x0000"; | ||||
| 	action "/usr/local/bin/ezdownload -f /usr/local/share/usb/firmware/0854.0100.0_01.hex $device-name"; | ||||
| }; | ||||
|  | ||||
| # Firmware download for Entrega Serial DB25 adapter. | ||||
| attach 100 { | ||||
| 	match "vendor"	"0x1645"; | ||||
| 	match "product"	"0x8001"; | ||||
| 	match "release"	"0x0101"; | ||||
| 	action "if ! kldstat -n usio > /dev/null 2>&1 ; then kldload usio; fi /usr/sbin/ezdownload -v -f /usr/share/usb/firmware/1645.8001.0101 /dev/$device-name"; | ||||
| }; | ||||
|  | ||||
| # This entry starts the ColdSync tool in daemon mode. Make sure you have an up | ||||
| # to date /usr/local/etc/palms. We override the 'listen' settings for port and | ||||
| # type in /usr/local/etc/coldsync.conf. | ||||
| attach 100 { | ||||
| 	device-name "ugen[0-9]+"; | ||||
| 	match "vendor" "0x082d"; | ||||
| 	match "product" "0x0100"; | ||||
| 	match "release" "0x0100"; | ||||
| 	action "/usr/local/bin/coldsync -md -p /dev/$device-name -t usb"; | ||||
| }; | ||||
|  | ||||
| # | ||||
| # Rescan scsi device-names on attach, but not detach.  However, it is | ||||
| # disabled by default due to reports of problems. | ||||
| # | ||||
| attach 0 { | ||||
| 	device-name "$scsi-controller-regex"; | ||||
| //	action "camcontrol rescan all"; | ||||
| }; | ||||
|  | ||||
| # Don't even try to second guess what to do about drivers that don't | ||||
| # match here.  Instead, pass it off to syslog.  Commented out for the | ||||
| # moment, as the pnpinfo variable isn't set in devd yet.  Individual | ||||
| # variables within the bus supplied pnpinfo are set. | ||||
| nomatch 0 { | ||||
| #	action "logger Unknown device: $pnpinfo $location $bus"; | ||||
| }; | ||||
|  | ||||
| # Various logging of unknown devices. | ||||
| nomatch 10 { | ||||
| 	match "bus" "uhub[0-9]+"; | ||||
| 	action "logger Unknown USB device: vendor $vendor product $product \ | ||||
| 		bus $bus"; | ||||
| }; | ||||
|  | ||||
| # Some PC-CARDs don't offer numerical manufacturer/product IDs, just | ||||
| # show the CIS info there. | ||||
| nomatch 20 { | ||||
| 	match "bus" "pccard[0-9]+"; | ||||
| 	match "manufacturer" "0xffffffff"; | ||||
| 	match "product" "0xffffffff"; | ||||
| 	action "logger Unknown PCCARD device: CISproduct $cisproduct \ | ||||
| 		CIS-vendor $cisvendor bus $bus"; | ||||
| }; | ||||
|  | ||||
| nomatch 10 { | ||||
| 	match "bus" "pccard[0-9]+"; | ||||
| 	action "logger Unknown PCCARD device: manufacturer $manufacturer \ | ||||
| 		product $product CISproduct $cisproduct CIS-vendor \ | ||||
| 		$cisvendor bus $bus"; | ||||
| }; | ||||
|  | ||||
| nomatch 10 { | ||||
| 	match "bus" "cardbus[0-9]+"; | ||||
| 	action "logger Unknown Cardbus device: device $device class $class \ | ||||
| 		vendor $vendor bus $bus"; | ||||
| }; | ||||
|  | ||||
| # Switch power profiles when the AC line state changes. | ||||
| notify 10 { | ||||
| 	match "system"		"ACPI"; | ||||
| 	match "subsystem"	"ACAD"; | ||||
| 	action "/etc/rc.d/power_profile $notify"; | ||||
| }; | ||||
|  | ||||
| # Notify all users before beginning emergency shutdown when we get | ||||
| # a _CRT or _HOT thermal event and we're going to power down the system | ||||
| # very soon. | ||||
| notify 10 { | ||||
| 	match "system"		"ACPI"; | ||||
| 	match "subsystem"	"Thermal"; | ||||
| 	match "notify"		"0xcc"; | ||||
| 	action "logger -p kern.emerg 'WARNING: system temperature too high, shutting down soon!'"; | ||||
| }; | ||||
|  | ||||
| # Sample ZFS problem reports handling. | ||||
| notify 10 { | ||||
| 	match "system"		"ZFS"; | ||||
| 	match "type"		"zpool"; | ||||
| 	action "logger -p kern.err 'ZFS: failed to load zpool $pool'"; | ||||
| }; | ||||
|  | ||||
| notify 10 { | ||||
| 	match "system"		"ZFS"; | ||||
| 	match "type"		"vdev"; | ||||
| 	action "logger -p kern.err 'ZFS: vdev failure, zpool=$pool type=$type'"; | ||||
| }; | ||||
|  | ||||
| notify 10 { | ||||
| 	match "system"		"ZFS"; | ||||
| 	match "type"		"data"; | ||||
| 	action "logger -p kern.warn 'ZFS: zpool I/O failure, zpool=$pool error=$zio_err'"; | ||||
| }; | ||||
|  | ||||
| notify 10 { | ||||
| 	match "system"		"ZFS"; | ||||
| 	match "type"		"io"; | ||||
| 	action "logger -p kern.warn 'ZFS: vdev I/O failure, zpool=$pool path=$vdev_path offset=$zio_offset size=$zio_size error=$zio_err'"; | ||||
| }; | ||||
|  | ||||
| notify 10 { | ||||
| 	match "system"		"ZFS"; | ||||
| 	match "type"		"checksum"; | ||||
| 	action "logger -p kern.warn 'ZFS: checksum mismatch, zpool=$pool path=$vdev_path offset=$zio_offset size=$zio_size'"; | ||||
| }; | ||||
|  | ||||
| # User requested suspend, so perform preparation steps and then execute | ||||
| # the actual suspend process. | ||||
| notify 10 { | ||||
| 	match "system"		"ACPI"; | ||||
| 	match "subsystem"	"Suspend"; | ||||
| 	action "/etc/rc.suspend acpi $notify"; | ||||
| }; | ||||
| notify 10 { | ||||
| 	match "system"		"ACPI"; | ||||
| 	match "subsystem"	"Resume"; | ||||
| 	action "/etc/rc.resume acpi $notify"; | ||||
| }; | ||||
|  | ||||
| /* EXAMPLES TO END OF FILE | ||||
|  | ||||
| # The following might be an example of something that a vendor might | ||||
| # install if you were to add their device.  This might reside in | ||||
| # /usr/local/etc/devd/deqna.conf.  A deqna is, in this hypothetical | ||||
| # example, a pccard ethernet-like device.  Students of history may | ||||
| # know other devices by this name, and will get the in-jokes in this | ||||
| # entry. | ||||
| nomatch 10 { | ||||
| 	match "bus" "pccard[0-9]+"; | ||||
| 	match "manufacturer" "0x1234"; | ||||
| 	match "product" "0x2323"; | ||||
| 	action "kldload if_deqna"; | ||||
| }; | ||||
| attach 10 { | ||||
| 	device-name "deqna[0-9]+"; | ||||
| 	action "/etc/pccard_ether $device-name start"; | ||||
| }; | ||||
| detach 10 { | ||||
| 	device-name "deqna[0-9]+"; | ||||
| 	action "/etc/pccard_ether $device-name stop"; | ||||
| }; | ||||
|  | ||||
| # Examples of notify hooks.  A notify is a generic way for a kernel | ||||
| # subsystem to send event notification to userland. | ||||
| # | ||||
| # Here are some examples of ACPI notify handlers.  ACPI subsystems that | ||||
| # generate notifies include the AC adapter, power/sleep buttons, | ||||
| # control method batteries, lid switch, and thermal zones. | ||||
| # | ||||
| # Information returned is not always the same as the ACPI notify | ||||
| # events.  See the ACPI specification for more information about | ||||
| # notifies.  Here is the information returned for each subsystem: | ||||
| # | ||||
| # ACAD:		AC line state (0 is offline, 1 is online) | ||||
| # Button:	Button pressed (0 for power, 1 for sleep) | ||||
| # CMBAT:	ACPI battery events | ||||
| # Lid:		Lid state (0 is closed, 1 is open) | ||||
| # Suspend, Resume: Suspend and resume notification | ||||
| # Thermal:	ACPI thermal zone events | ||||
| # | ||||
| # This example calls a script when the AC state changes, passing the | ||||
| # notify value as the first argument.  If the state is 0x00, it might | ||||
| # call some sysctls to implement economy mode.  If 0x01, it might set | ||||
| # the mode to performance. | ||||
| notify 10 { | ||||
| 	match "system"		"ACPI"; | ||||
| 	match "subsystem"	"ACAD"; | ||||
| 	action			"/etc/acpi_ac $notify"; | ||||
| }; | ||||
| */ | ||||
							
								
								
									
										27
									
								
								etc.BSD/rc.devd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								etc.BSD/rc.devd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| #!/bin/sh | ||||
|  | ||||
| export IN_BACKGROUND=yes | ||||
| export IN_HOTPLUG=yes | ||||
|  | ||||
| getmedia() { | ||||
| 	ifconfig $1 | while read line; do | ||||
| 		case ${line} in | ||||
| 			media:" "*) echo "${line}"; return;; | ||||
| 		esac | ||||
| 	done | ||||
| } | ||||
|  | ||||
| set -x | ||||
| if [ ! -e /etc/init.d/"$1" ]; then | ||||
| 	base=$(basename ${1%%.*}) | ||||
| 	if [ "${base}" = "net" ]; then | ||||
| 		# We only create links for pyhsical interfaces | ||||
| 		[ -n "$(getmedia ${1#*.})" ] || exit 1 | ||||
| 		base="net.lo0" | ||||
| 	fi | ||||
| 	if [ -e /etc/init.d/"${base}" -a "${base}" != "$1" ]; then | ||||
| 		ln -s "${base}" /etc/init.d/$1 | ||||
| 	fi | ||||
| fi | ||||
|  | ||||
| exec /etc/init.d/$1 $2 | ||||
							
								
								
									
										43
									
								
								init.d.BSD/devd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								init.d.BSD/devd
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| #!/sbin/runscript | ||||
| # Copyright 1999-2007 Gentoo Foundation | ||||
| # Copyright 2007 Roy Marples | ||||
| # All rights reserved | ||||
|  | ||||
| # Redistribution and use in source and binary forms, with or without | ||||
| # modification, are permitted provided that the following conditions | ||||
| # are met: | ||||
| # 1. Redistributions of source code must retain the above copyright | ||||
| #    notice, this list of conditions and the following disclaimer. | ||||
| # 2. Redistributions in binary form must reproduce the above copyright | ||||
| #    notice, this list of conditions and the following disclaimer in the | ||||
| #    documentation and/or other materials provided with the distribution. | ||||
| # | ||||
| # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||||
| # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||||
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||||
| # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||||
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||||
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||||
| # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||||
| # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||||
| # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
| # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
| # SUCH DAMAGE. | ||||
|  | ||||
| command=/sbin/devd | ||||
| command_args=${devd_args} | ||||
| name="Device State Change Daemon" | ||||
|  | ||||
| depend() { | ||||
| 	need localmount | ||||
| 	after bootmisc | ||||
| 	before net.lo0 | ||||
| } | ||||
|  | ||||
| start_pre() { | ||||
|     sysctl hw.bus.devctl_disable=0 >/dev/null | ||||
| } | ||||
|  | ||||
| stop_post() { | ||||
|     sysctl hw.bus.devctl_disable=1 >/dev/null | ||||
| } | ||||
		Reference in New Issue
	
	Block a user