Skip to content

tools/nut-usbinfo.pl: Fixes#913

Merged
clepple merged 4 commits intonetworkupstools:masterfrom
hadess:wip/hadess/nut-usbinfo-fixes
Dec 13, 2020
Merged

tools/nut-usbinfo.pl: Fixes#913
clepple merged 4 commits intonetworkupstools:masterfrom
hadess:wip/hadess/nut-usbinfo-fixes

Conversation

@hadess
Copy link
Copy Markdown
Contributor

@hadess hadess commented Nov 26, 2020

Misc fixes

See https://lwn.net/Articles/837033/ for an in-depth explanation of how
"bind" events should be handled in udev rules.

In short:
"
The ACTION line causes the entire file to be skipped for anything other than
ADD or CHANGE events; in particular, that is what will happen with BIND
events. That will cause properties associated with those events to be
lost — and the device in question to be set up improperly (if at all).
"
Why "!= usb" when we're already checking for usb and other values
above? Always go to the end label if we didn't already jump to the
section containing the actual rules.
This piece of the code was really confusing because it looked like, at a
glance (and at more than a glance), that the line which we'd have read
in the generated rules file was commented out.

Turns out that beginning of lines in the generated rules could be in the
middle of the line in the code that generated it. Reindent everything so
that each line in the output corresponds to one line in the input,
except for empty lines.

There are no differences in output between the versions before and after
this change.
@jimklimov
Copy link
Copy Markdown
Member

LGTM for most of the changes, just gotta trust your research and judgement about the udev rules :) Thanks!

I will leave this PR open for a few days to give a chance for others to comment if something would concern them.

@hadess
Copy link
Copy Markdown
Contributor Author

hadess commented Nov 27, 2020

LGTM for most of the changes, just gotta trust your research and judgement about the udev rules :) Thanks!

You might want to test them, even summarily, as I don't have the hardware to test it.

@clepple
Copy link
Copy Markdown
Member

clepple commented Nov 28, 2020

@hadess I probably need to reread the LWN article and the bugs linked from it, but assuming that the NUT rules are changing permissions on nodes created from ADD events, what is the harm in skipping that when a BIND event comes in?

It sounds like users of 4.14+ kernels should be seeing regressions of some sort, but I'm not sure what that looks like for NUT.

I have no problem testing the two later commits at the same time, but scheduling time to test on non-production hardware might be tough (I had a few batteries die on non-critical UPSes around the house, and I haven't replaced them yet), so I want to understand what I'm looking for before rewiring things.

@hadess
Copy link
Copy Markdown
Contributor Author

hadess commented Nov 28, 2020

@hadess I probably need to reread the LWN article and the bugs linked from it, but assuming that the NUT rules are changing permissions on nodes created from ADD events, what is the harm in skipping that when a BIND event comes in?

The properties you set when processing an event aren't kept across subsequent events, so your device would end up without any properties. That's why the original rules also handled change events.

@hadess
Copy link
Copy Markdown
Contributor Author

hadess commented Nov 28, 2020

It sounds like users of 4.14+ kernels should be seeing regressions of some sort, but I'm not sure what that looks like for NUT.

Newer kernels and older systemd would see no properties set on the NUT handled devices. This is worked-around in newer versions of systemd.

@clepple clepple added need testing Code looks reasonable, but the feature would better be tested against hardware or OSes USB labels Nov 28, 2020
@clepple
Copy link
Copy Markdown
Member

clepple commented Dec 13, 2020

@hadess did a quick sanity check, and everything seems to work fine with Ubuntu 20.04, plus the following NUT, systemd, and kernel versions. Thanks again for the fix and patient explanations.

commit 38b5f96

$ systemd --version
systemd 245 (245.4-4ubuntu3.3)

$ uname -a
Linux voyager 5.4.0-58-generic #64-Ubuntu SMP Wed Dec 9 08:16:25 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

@clepple clepple merged commit 504d2c0 into networkupstools:master Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

need testing Code looks reasonable, but the feature would better be tested against hardware or OSes USB

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants