Import hotplugd(8) from OpenBSD.
[dragonfly.git] / sbin / hotplugd / hotplugd.8
1 .\"     $OpenBSD: hotplugd.8,v 1.10 2009/03/20 17:53:14 jasper Exp $
2 .\"
3 .\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
4 .\"
5 .\" Permission to use, copy, modify, and distribute this software for any
6 .\" purpose with or without fee is hereby granted, provided that the above
7 .\" copyright notice and this permission notice appear in all copies.
8 .\"
9 .\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 .\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 .\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 .\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 .\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 .\"
17 .Dd $Mdocdate: December 7 2008 $
18 .Dt HOTPLUGD 8
19 .Os
20 .Sh NAME
21 .Nm hotplugd
22 .Nd devices hot plugging monitor daemon
23 .Sh SYNOPSIS
24 .Nm hotplugd
25 .Op Fl d Ar device
26 .Sh DESCRIPTION
27 The
28 .Nm
29 daemon monitors the
30 .Xr hotplug 4
31 pseudo-device, acting on signaled events by executing the scripts in the
32 .Pa /etc/hotplug
33 directory.
34 By default it uses the
35 .Pa /dev/hotplug
36 device for reading events from, but an alternative device can be
37 specified with the
38 .Fl d
39 option.
40 .Pp
41 Actions can be configured either for device attachment or detachment.
42 On device attachment the
43 .Pa attach
44 script is executed if it exists.
45 On device detachment the
46 .Pa detach
47 script is executed if it exists.
48 In both cases two parameters are passed to the scripts: the class and name
49 of the attached or detached device.
50 The device class corresponds to the classes described in the
51 .Aq Pa sys/device.h
52 header file and can be one of the following:
53 .Pp
54 .Bl -tag -width Ds -offset indent -compact
55 .It 0
56 generic, no special info
57 .It 1
58 CPU (carries resource utilization)
59 .It 2
60 disk drive
61 .It 3
62 network interface
63 .It 4
64 tape device
65 .It 5
66 serial line interface
67 .El
68 .Pp
69 Not all classes are really usable.
70 For example, it's unlikely that a CPU will be hotplugged.
71 .Pp
72 The device name is the usual name,
73 as listed in
74 .Xr MAKEDEV 8 ,
75 and the unit number, e.g.\&
76 .Pa sd1 .
77 .Sh FILES
78 .Bl -tag -width "/dev/hotplug/attach" -compact
79 .It /dev/hotplug
80 Pseudo-device file.
81 .It /etc/hotplug
82 Directory where the scripts to execute are located.
83 .It /etc/hotplug/attach
84 Script to execute on device attachment.
85 .It /etc/hotplug/detach
86 Script to execute on device detachment.
87 .El
88 .Sh EXAMPLES
89 Sample
90 .Pa attach
91 script:
92 .Bd -literal -offset indent
93 #!/bin/sh
94
95 DEVCLASS=$1
96 DEVNAME=$2
97
98 case $DEVCLASS in
99 2)
100         # disk devices
101         disklabel=`/sbin/disklabel $DEVNAME 2\*(Gt&1 | \e
102             sed -n '/^label: /s/^label: //p'`
103         case $disklabel in
104         Sony*DSC*)
105                 # Sony DSC camera
106                 mount -o nodev,nosuid /dev/"$DEVNAME"i /mnt/camera
107                 ;;
108         esac
109         ;;
110 3)
111         # network devices; requires hostname.$DEVNAME
112         sh /etc/netstart $DEVNAME
113         ;;
114 esac
115 .Ed
116 .Sh SEE ALSO
117 .Xr hotplug 4
118 .Sh HISTORY
119 The
120 .Nm
121 program first appeared in
122 .Ox 3.6 .
123 .Sh AUTHORS
124 The
125 .Nm
126 program was written by
127 .An Alexander Yurchenko Aq grange@openbsd.org .