Comments (3)
FWIW, libusb1 as of 1.0.16 sports a libusb_get_port_numbers()
API that returns the entire device path, rather than just the terminal port number. That would be a stable way to refer to a unique point in the USB topology, and is stable against enumeration order and unplug/replug events (so long as the replug is into the same port).
But I agree that port
is probably a more useful, less bespoke approach and probably involves less code. In particular, one can use udev
(or devd
or similar) to give a symbolic link to a particular point in the USB topology. In udev
, for example,
SUBSYSTEM=="usb", KERNEL=="5-1.1", OWNER="nut", SYMLINK+="ups0"
will create
$ ls /dev/ups0
lrwxrwxrwx 1 root root 15 Jun 26 09:37 /dev/ups0 -> bus/usb/005/011
as well as set the owner of the raw bus/usb
device. Since 1.0.23, libusb1 has had libusb_wrap_sys_device
to allow the use of such device nodes to directly access a given device without enumeration. See
https://github.com/libusb/libusb/blob/e678b3fad58a508cbd0a6e6dc777fb48346f948b/examples/testlibusb.c#L242-L261 for an example of its use.
(ETA: it is purely a coincidence that device path "1.1" has device number "11" as of the commands above. There is no relation between these digit strings.)
Would you like me to try to raise a PR?
from nut.
Yes, thanks - I suppose that would be welcome (keeping port=auto
for guessing as is done now). Just in case, keep in mind that not all world is Linux - though in this case it is rather for libusb1
project's headache to do things right. Just that wordings of such devfs paths can differ a lot.
In any case, if these methods only appeared from some intermediate version of the library, it sounds right to check for their existence in m4/nut_check_libusb.m4
and ifdef
the new feature based on that (and also log a message that port!=auto
is ignored in libusb0.c
). If the provided path does not seem like an expected UPS in builds that support the feature, driver should fail to start; if the feature is not supported - log but ignore (do port=auto
as we always did).
from nut.
OK, I tried and I'm sorry, but I don't think I'm going to be able to raise a PR in the near term.
-
libusb1
requires the client to continue to manage the system fd that gets wrapped bylibusb_wrap_sys_device
, and to close it after closing the USB device, which is not particularly pleasant and would require violence to the somewhat inconsistent abstraction layer aroundUSBDevice_t
andusb_communication_subdriver_t
objects.-
IMHO, it would be much better if the library
dup()
'd the descriptor andclose()
d the one they had when the device got closed; then the client could optionally retain the fd or not, as desired. Oh well. -
Also IMHO, it's a bit odd to have both
USBDevice_t
-s andusb_dev_handle
-s as part of theusb_communication_subdriver_t
interface. The use of the latter basically ensures that this interface is a thin shim aroundlibusb[01]
and requires that all callers understand the internals (and proper destruction) ofUSBDevice_t
.
-
-
The use of
libusb_get_port_numbers
might seem more enticing, but the violence required for theUSBDeviceMatcher
objects is also more than I want to take on right now; the other annoying bit, formatting a temporary string from the array contents for the matchers' use, at least occurs just once. (In particular,USBMATCHER_REGEXP_ARRAY_LIMIT
is now defined by two nested conditionals and there's not just one optional slot in the resulting array. It's tempting to make all slots non-optional and just leave the regexp asNULL
if the feature isn't supported, but even that is... tedious, but probably the easiest answer.)
For my case, busport
happens to work, because the two UPSes are siblings on the same hub, but that's not a particularly fantastic requirement. So it goes.
from nut.
Related Issues (20)
- CI: Ensure that all `addvar()` defined options are reflected in `nutconf` library and tool, maybe augeas lenses, etc.
- `upsdrvctl` would benefit from CLI options to list known devices, and their current health
- Switched from blazer_usb to nutdrv_qx - Battery voltage repporting wrong value HOT 4
- EATON Ellipse Eco: battery test vs battery charge
- Fix uses of `banner_is_disabled()` to not preclude `-V` printouts
- RFE: Extend `upsdrv(svc)ctl` with a `status-all` to check all known NUT-related daemons or service units
- Default "scan all" by `nut-scanner` aborts on error of one bus (at least "init libusb") and does not complete other buses HOT 2
- Thread count in parallel `nut-scanner` should scale down in case of "Too many open files" HOT 1
- SMART1000RMXL2U vendor specific instcmd sequence for individual outlet bank control HOT 1
- [HCL] APC Back-UPS "Essential" BE850G2-FR supported by usbhid-ups HOT 1
- RICHCOMM_USB >> Fatal error: 'vendorid' is not a valid variable name for this driver. HOT 2
- USBHID-UPS Invalid parameter with AMETEK Powervar UPM 2 HOT 2
- Warning: excessive poll failures adding APC NMC card HOT 1
- CI: a step towards faster builds: use `libcommon*` as layers or separate flavours, not as independent builds where avoidable
- common.c/.h: warning: '%s' directive argument is null [-Wformat-overflow=] HOT 10
- CI: Add embedded build/test cases with buildroot, OpenWRT, etc.
- Can't power off ups device from Truenas HOT 10
- CI: `clang-18` complains about a lot of `switch` clauses without a `default` label
- [HCL] TED Electric 3100VA 1800W UPS Line Interactive supported by probably Richcomm HOT 19
- RFE: SHM and/or FUSE to access nut-client information
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nut.