Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please document how to run with LIBUSB_DEBUG=x or enable libusb debug output with nut debug options #2616

Open
tormodvolden opened this issue Sep 3, 2024 · 11 comments

Comments

@tormodvolden
Copy link
Contributor

To investigate USB issues it is important to see the debug output from libusb. Either the env var LIBUSB_DEBUG must be set to e.g. 4, or the program can call libusb_set_debug() to set debug level per libusb context.

@tormodvolden tormodvolden changed the title Please document how to run with LIBUSB_DEBUG=x or enable it with debug options Please document how to run with LIBUSB_DEBUG=x or enable libusb debug output with nut debug options Sep 3, 2024
@jimklimov
Copy link
Member

jimklimov commented Sep 4, 2024

As a quick shot with existing builds - does it suffice to export the envvar in USB-capable driver units/init-scripts (commonly via nut.conf)?

For later iterations, I'd envision something like what's done in recent years for nut_debug_level via DEBUG_MIN settings and real-time protocol settings to dial the knob in-vivo.

"Per context" here maps to one process's usage of libusb (from init to close), right?

@jimklimov jimklimov added this to the 2.8.3 milestone Sep 4, 2024
@tormodvolden
Copy link
Contributor Author

Yes, if there is a mechanism to set environment variables when executing the driver binaries, that will work.

Setting the env var on the command line when launching a program is technically easy but there are syntax differences between operating systems (or rather their shells), and when things e.g. run via systemd it becomes more difficult for many end-users.

Per-context refers to the libusb concept of context. You can have multiple libusb contexts in one process without them interfering with each other. They will for instance have their own list of discovered devices and their own set of callbacks for events, their own debug level and so forth. This makes sense e.g. for a larger program with plugins or modules that do USB but operate independently.

@jimklimov
Copy link
Member

Got it, thanks!

@jimklimov
Copy link
Member

@jimklimov
Copy link
Member

Made a quick improvement via docs; a configurable/run-time "knob" may be on the table some time in the future, so I would keep this issue open.

@masterwishx
Copy link
Contributor

exported LIBUSB_DEBUG = 4 is not working yet ?

@jimklimov
Copy link
Member

For environment variable setup through nut.conf file sourced for service startup (including drivers as a service - but not used directly as a program nor via upsdrvctl), either way - for a shell interpreter you would

export LIBUSB_DEBUG=4

Not exported, no spaces around = ...

@masterwishx
Copy link
Contributor

For environment variable setup through nut.conf file sourced for service startup (including drivers as a service - but not used directly as a program nor via upsdrvctl), either way - for a shell interpreter you would

export LIBUSB_DEBUG=4

Not exported, no spaces around = ...

In nut plugin setup config all settings with spaces, but not a problem I can check both with and without spaces.
So libusb debug work with debug_min=6 also?

@jimklimov
Copy link
Member

jimklimov commented Oct 2, 2024

We here are making NUT, not its HA plugin, sorry ;)

From what I saw, it is set up by yaml files that NUT *.conf files get generated from, not by editing NUT configs in UI directly. Maybe you should "cut out the middleman" and run NUT programs directly while investigating?..

AFAIK the plugin uses packaged (or custom-built, per wiki) NUT binaries and scripts etc., so maybe you can inject the EnvironmentVariable=LIBUSB_DEBUG=4 to the [email protected] definition temporarily - assuming plugin rewrites nut.conf so you can't really edit it (and chattr to make it immutable is not helpful either)?..

And "no", the debug_min setting for NUT verbosity is not currently linked to libusb's own debug. Perhaps adding it as a setting to be recognized from ups.conf and causing a setenv() early in drivers/main.c (rather than diligent setting of libusb context verbosity, as proposed in that issue originally) is also a decent quick solution.

@masterwishx
Copy link
Contributor

We here are making NUT, not its HA plugin, sorry ;)

From what I saw, it is set up by yaml files that NUT *.conf files get generated from, not by editing NUT configs in UI directly. Maybe you should "cut out the middleman" and run NUT programs directly while investigating?..

AFAIK the plugin uses packaged (or custom-built, per wiki) NUT binaries and scripts etc., so maybe you can inject the EnvironmentVariable=LIBUSB_DEBUG=4 to the [email protected] definition temporarily - assuming plugin rewrites nut.conf so you can't really edit it (and chattr to make it immutable is not helpful either)?..

And "no", the debug_min setting for NUT verbosity is not currently linked to libusb's own debug. Perhaps adding it as a setting to be recognized from ups.conf and causing a setenv() early in drivers/main.c (rather than diligent setting of libusb context verbosity, as proposed in that issue originally) is also a decent quick solution.

Sure, You are 100% right.
BTW, I'm on Unraid plugin for NUT not HA :).

@jimklimov
Copy link
Member

Oops :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants