On Wed, Jun 10, 2026 at 04:41:26PM -0500, izzy Meyer wrote:
> Hello misc@
> 
> I have slowly been working on this now-sprawling hotplugd(8) attach
> script but I'm not a fan of how messy and complex it has gotten. Any
> tips to clean it up and make it more modular? I don't like the usbdevs
> hack, it feels uncomfortable to me for some reason. How do your
> hotplugd(8) scripts look?

Here's mine

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#!/bin/sh

DEVCLASS=$1
DEVNAME=$2

case $DEVNAME in
audio[0-9])
        sndioctl server.device=${DEVNAME#audio}
        ;;
midi[0-9])
        sndioctl -f midithru/0 server.port=+${DEVNAME#midi}
        ;;
urndis0)
        ifconfig $DEVNAME autoconf
esac
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

The midi part requires the diff that just went to tech@, though

> 
> /etc/hotplug $ bat -l sh -pp attach
> #!/bin/ksh
> 
> DEVCLASS=$1
> DEVICE=$2
> 
> [ "$DEVCLASS" -eq 0 ] || exit 0
> 
> case "$DEVICE" in
>     ugen*)
>         # printer for CUPS
>         if usbdevs -v | grep -q '03f0:dd11'; then
> 
>             ugen=$(usbdevs -v | awk '
>                 /03f0:dd11/ { found=1 }
>                 found && /driver: ugen[0-9]+/ {
>                     sub(/^[[:space:]]*driver: /, "")
>                     print
>                     exit
>                 }
>             ')
> 
>             [ "$DEVICE" = "$ugen" ] || exit 0
> 
>             usbctl=$(usbdevs -v | awk -v dev="$ugen" '
>                 /^Controller \/dev\/usb[0-9]+:/ {
>                     ctl=$2
>                     sub(":", "", ctl)
>                 }
>                 $0 ~ ("driver: " dev "$") {
>                     print ctl
>                     exit
>                 }
>             ')
> 
>             logger -t hotplug "Printer attached"
> 
>             if [ -n "$usbctl" ]; then
>                 chown _cups:_saned /dev/${ugen}.* "$usbctl"
>                 chmod 660 /dev/${ugen}.* "$usbctl"
>             fi
>         # usb midi keyboard setup for LMMS
>         elif usbdevs -v | grep -q '28e9:0001'; then
>             logger -t hotplug "USB Midi Keyboard Attached"
>             
>             ( midicat -q midi/0 -q midithru/0 ) &
>         fi
>         ;;

Hopefully the midicat(1)-based plmbing won't be needed anymore. See:

https://marc.info/?l=openbsd-tech&m=178116365373422

>     uvideo*)
>         # usb webcam setup for video calls
>         logger -t hotplug "USB Webcam attached"
> 
>         chown nobody:nobody /dev/video*
>         chmod 0777 /dev/video*
>         ;;

I'd suggest simply changing /dev/video* ownership to your user id,
after each upgrade.

Another option, for multi-user machines, would be to add /dev/video*
to /etc/fbtab, ex:

/dev/ttyC0      0600    /dev/video0:/dev/video1

This changes the video devices ownership to the user logged on the
console. Not perfect as /dev/videoN are not revoked when you logout,
but it's much better than world readable devices.

Reply via email to