chiark / gitweb /
[PATCH] added RFC-dev.d document detailing how /etc/dev.d/ works.
[elogind.git] / docs / RFC-dev.d
1  /etc/dev.d/  How it works, and what it is for
2  
3  by Greg Kroah-Hartman <greg@kroah.com> March 2004
4
5 The /etc/dev.d directory works much like the /etc/hotplug.d/ directory
6 in that it is a place to put symlinks or programs that get called when
7 an event happens in the system.  Programs will get called whenever the
8 device naming program in the system has either named a new device and
9 created a /dev node for it, or when a /dev node has been removed from
10 the system due to a device being removed.
11
12 The directory tree under /etc/dev.d/ dictate which program is run first,
13 and when some programs will be run or not.  The device naming program
14 calls the programs in the following order:
15         /etc/dev.d/DEVNODE/*.dev
16         /etc/dev.d/SUBSYSTEM/*.dev
17         /etc/dev.d/default/*.dev
18
19 The .dev extension is needed to allow automatic package managers to
20 deposit backup files in these directories safely.
21
22 The DEVNODE name is the name of the /dev file that has been created.
23 This value, including the /dev path, will also be exported to userspace
24 in the DEVNODE environment variable.
25
26 The SUBSYSTEM name is the name of the sysfs subsystem that originally
27 generated the hotplug event that caused the device naming program to
28 create or remove the /dev node originally.  This value is passed to
29 userspace as the first argument to the program.
30
31 The default directory will always be run, to enable programs to catch
32 every device add and remove in a single place.
33
34 All environment variables that were originally passed by the hotplug
35 call that caused this device action will also be passed to the program
36 called in the /etc/dev.d/ directories.  Examples of these variables are
37 ACTION, DEVPATH, and others.  See the hotplug documentation for full
38 description of this
39
40 An equivalent shell script that would do this same kind of action would
41 be:
42         DIR="/etc/dev.d"
43         export DEVNODE="whatever_dev_name_udev_just_gave"
44         for I in "${DIR}/$DEVNODE/"*.dev "${DIR}/$1/"*.dev "${DIR}/default/"*.dev ; do
45                 if [ -f $I ]; then $I $1 ; fi
46         done
47         exit 1;
48
49