Discussion:
[Nut-upsuser] NUT + devd + FreeBSD
Daniel O'Connor
2007-10-30 01:45:13 UTC
Permalink
I made the following devd script..

sh
cd /tmp
fetch
mkdir /usr/local/etc/devd
sed -Ene 's/SYSFS\{idVendor\}==\"(.*)\", SYSFS\{idProduct\}==\"(.*)\", MODE=.*/attach 100 {\
device-name "ugen[0-9]+";\
match "vendor" "0x\1";\
match "product" "0x\2";\
action "chown @RUN_AS_GROUP@ \/dev\/$device-name*; chmod 660 \/dev\/$device-name*";\
};\
/p' </usr/ports/sysutils/nut/work/nut-2.2.0/scripts/udev/nut-usbups.rules.in | sed -e 's#@RUN_AS_GROUP@#uucp#g' > /usr/local/etc/devd/nut.conf
/etc/rc.d/devd restart

Unfortunately the uucp user is not in operator so it can't search the USB
bus and hence the above doesn't work 100%.

I think probably the best way would be to make a nutmon user that is a member
of the uucp and operator group.

I did that with..
echo '*LOCKED*' | pw useradd nutmon -u 95 -c 'NUT monitor user' -d /var/empty -g operator -G dialer -s /usr/sbin/nologin -H 0
then..
cd /usr/ports/sysutils/nut
make NUT_USER=nutmon NUT_GROUP=operator

And re-run the sed above but with operator instead of uucp.

--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part.
Url : http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20071030/1189f9f9/attachment.pgp
Charles Lepple
2007-10-30 02:48:26 UTC
Permalink
Post by Daniel O'Connor
I made the following devd script..
That's pretty intense, but it's a nice reuse of the udev data.

If you want, we can create a packaging/FreeBSD directory (or just
packaging/BSD, if devd is not specific to FreeBSD) to hold the script
and instructions.

Or how much of this should end up in the port files?
--
- Charles Lepple
Daniel O'Connor
2007-10-30 03:28:58 UTC
Permalink
Post by Charles Lepple
Post by Daniel O'Connor
I made the following devd script..
That's pretty intense, but it's a nice reuse of the udev data.
Hey, machines exist to do work for us, not the other way around ;)

Although IMO a source file that is cleaner could be used instead and
then the udev & devd scripts can be derived from it.
Post by Charles Lepple
If you want, we can create a packaging/FreeBSD directory (or just
packaging/BSD, if devd is not specific to FreeBSD) to hold the script
and instructions.
Or how much of this should end up in the port files?
It could all go in the port files trivially.

I think that if the port or NUT generated that file it would be ideal,
the later is probably better since NUT's list of supported UPSs will
grow but devd's file format won't change (much).
--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: This is a digitally signed message part.
Url : http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20071030/24dc8ead/attachment.pgp
Charles Lepple
2014-07-18 13:11:56 UTC
Permalink
Post by Daniel O'Connor
I made the following devd script..
sh
cd /tmp
fetch
mkdir /usr/local/etc/devd
sed -Ene 's/SYSFS\{idVendor\}==\"(.*)\", SYSFS\{idProduct\}==\"(.*)\", MODE=.*/attach 100 {\
device-name "ugen[0-9]+";\
match "vendor" "0x\1";\
match "product" "0x\2";\
};\
/etc/rc.d/devd restart
Hi Daniel,

Dusting off this thread, since the FreeBSD ports tree picked up NUT
2.7.2 and now includes an auto-generated nut-usb.conf devd file.

However, I also noticed this PR filed against the port:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191777

Somewhere along the line, I must have changed things from "attach" to
"notify", and dropped the device-name match. However, their solution
to that bug was to remove the star after the device name. What was the
rationale for the wildcard? Does this handle the bus scanning
permissions?

Thanks,
--
- Charles Lepple
Daniel O'Connor
2014-08-12 12:39:59 UTC
Permalink
Post by Charles Lepple
Post by Daniel O'Connor
I made the following devd script..
Dusting off this thread, since the FreeBSD ports tree picked up NUT
2.7.2 and now includes an auto-generated nut-usb.conf devd file.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191777
Somewhere along the line, I must have changed things from "attach" to
"notify", and dropped the device-name match. However, their solution
to that bug was to remove the star after the device name. What was the
rationale for the wildcard? Does this handle the bus scanning
permissions?
Sorry for the delay in replying, I forgot about this email :(

I think the wildcard was there because of the way the previous USB stack worked - it created /dev/ugen0.1 (one node for each endpoint) but you only got /dev/ugen0 from devd and so if your program tried to do anything except send control messages it would fail.

With respect to device-name being empty - I guess things changed as it worked for me when I wrote it :)

I don't actually use devd.conf currently as I lost the patch so I resorted to putting the nut user in operator (bleh) which has access to the USB device nodes by default.

I did some fiddling and came up with..
notify 100 {
match "system" "USB";
match "subsystem" ?DEVICE";
match "type" "ATTACH";
match "vendor" "0x0463";
match "product" "0xffff";
action "chgrp uucp /dev/$cdev; chmod g+rw /dev/$cdev";
};

This works for my MGE Ellipse and I don?t see why it wouldn?t work more generally if your script was modified.

FYI devd sees the following when the device is connected

Processing event '!system=USB subsystem=DEVICE type=ATTACH ugen=ugen1.2 cdev=ugen1.2 vendor=0x0463 product=0xffff devclass=0x00 devsubclass=0x00 sernum="000000000" release=0x4241 mode=host port=1 parent=ugen1.1'
Pushing table
setting system=USB
setting subsystem=DEVICE
setting type=ATTACH
setting ugen=ugen1.2
setting cdev=ugen1.2
setting vendor=0x0463
setting product=0xffff
setting devclass=0x00
setting devsubclass=0x00
setting sernum=000000000
setting release=0x4241
setting mode=host
setting port=1
setting parent=ugen1.1

There is also a subsystem=INTERFACE event which is very similar.

--
Daniel O'Connor software and network engineer
for Genesis Software - http://www.gsoft.com.au
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
Charles Lepple
2014-08-17 19:58:23 UTC
Permalink
Post by Daniel O'Connor
I did some fiddling and came up with..
notify 100 {
match "system" "USB";
match "subsystem" ?DEVICE";
match "type" "ATTACH";
match "vendor" "0x0463";
match "product" "0xffff";
action "chgrp uucp /dev/$cdev; chmod g+rw /dev/$cdev";
};
This works for my MGE Ellipse and I don?t see why it wouldn?t work more generally if your script was modified.
Daniel,

Thanks for the info. (Sorry for the delay; couldn't test on a FreeBSD box last week.) I think I have it generating things in that format now:

https://github.com/clepple/nut/compare/freebsd_devd_take2

For reference, which version of FreeBSD are you using? I got this to work on 9.2 and 10.0.
--
Charles Lepple
clepple at gmail
O'Connor, Daniel
2014-08-17 22:08:45 UTC
Permalink
Post by Charles Lepple
Post by Daniel O'Connor
I did some fiddling and came up with..
notify 100 {
match "system" "USB";
match "subsystem" ?DEVICE";
match "type" "ATTACH";
match "vendor" "0x0463";
match "product" "0xffff";
action "chgrp uucp /dev/$cdev; chmod g+rw /dev/$cdev";
};
This works for my MGE Ellipse and I don?t see why it wouldn?t work more generally if your script was modified.
https://github.com/clepple/nut/compare/freebsd_devd_take2
Looks good!
Post by Charles Lepple
For reference, which version of FreeBSD are you using? I got this to work on 9.2 and 10.0.
It was tested on a 9.2 (ish) system.

--
Daniel O'Connor
"The nice thing about standards is that there
are so many of them to choose from."
-- Andrew Tanenbaum
GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C
Loading...