NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

using devpubd for device event notifications and actions?



Anyone using devpubd to automate some actions when you add or remove 
devices? Please share how you use devpubd.

I'd like to help work on some documentation for it and help collect
various helper (hooks) scripts.

devpubd as introduced in NetBSD 6.0. (The development code was called 
udevfsd.

It may be started with "/etc/rc.d/devpubd onestart". When it sees an
event via drvctl(4), it will run the /libexec/devpubd-run-hooks script 
with the arguments as the name of the event and the device name. It will 
run all the executables in the /libexec/devpubd-hooks/ directory passing 
along the event type and device name.

Have a look at /libexec/devpubd-hooks/01-makedev as the single example.

If you have user.debug enabled for syslogging you will get each event 
logged. You can also simply do this by adding a new executable hook, 
such as /libexec/devpubd-hooks/99-debug with:
logger $0 $1 $2

Here are a few examples of hardware I attached:

1) Plugged in an external disk via USB:

sd0 at scsibus0 target 0 lun 0: <TOSHIBA, External USB 3.0, 0101> disk fixed
sd0: fabricating a geometry
sd0: 931 GB, 953869 cyl, 64 head, 32 sec, 512 bytes/sect x 1953525165 sectors

The devpubd events are:

 device-attach umass0
 device-attach scsibus0
 device-attach sd0

Any suggestions on how to best identify the disk and its file system for 
mounting?

(Stephen Borrill had provided a script years ago about identifying the 
disklabel or fdisk or raw MSDOS partition before mounting.)

2) Plug in in a sdcard (also used with a camera).

devpubd did nothing.

I normally use it like:

  sudo /sbin/mount_msdos -m 0664 -M 0775 -g users /dev/sd0e /mnt

Any ideas on how I can get inserting or ejecting this sdcard to have a 
drvctl event?

3) Plug in a Canon EOS camera via USB:

ugen0 at uhub3 port 2
ugen0: Canon Inc. Canon Digital Camera, rev 2.00/0.02, addr 4

The devpubd event is:

 device-attach ugen0

How can I script something to look at ugen0 to identify it is my camera?

4) Plugin a different camera via USB:

ugen0 at uhub3 port 2
ugen0: Canon Inc. Canon Digital Camera, rev 2.00/0.02, addr 4

The devpubd event again is:

 device-attach ugen0

Again, how can I script something to look at ugen0 to identify it is 
this camera?

5) Plugged in a Brother laser printer via USB:

ulpt0 at uhub3 port 1 configuration 1 interface 0
ulpt0: Brother HL-5150D, rev 2.00/1.00, addr 2, iclass 7/1
ulpt0: using bi-directional mode

The devpubd event is:

 device-attach ulpt0

Any suggestions on how I can script looking at ulpt0 to identify it?

6) Inserted a disk into my CD drawer and ejected it 30 seconds later. 
Its lights flashed.

The kernel didn't log anything and devpubd didn't notice it.

How to see a inserted CD or DVD?

Please share how you use devpubd.

In particular, I'd like for a single-user X11 desktop environment to 
have:

- plugin in a USB disk or a sdcard and have it detect file system, mount 
it, and then popup a file browser showing its file listing. And maybe 
even create a new icon for unmounting it.  This is the easiest of this 
list.

- plugin a camera, recognize the ugen is a camera and run a script to 
run a script or a gui wrapper around gphoto2

- insert a CD or DVD and have it behave accordingly: mount and show a 
file sytem, or start an audio player to play an audio CD, or start a 
movie player to play a DVD.

- plugin a scanner and have it recognized and a scanner software 
start up.


Home | Main Index | Thread Index | Old Index