Skip to content

Commit c43606c

Browse files
authored
Merge pull request #3041 from jimklimov/issue-3040-477-msg
Introduce `suggest_NDE_conflict()` helper method, use in libusb faults
2 parents 09a69e6 + eccebbc commit c43606c

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

NEWS.adoc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ https://github.com/networkupstools/nut/milestone/9
141141
[#2957]
142142
* Fixed a couple of ancient memory leaks: one "shared" during driver
143143
program initialization, and one specific to `dummy-ups` wind-down. [#2972]
144+
* Added a `suggest_NDE_conflict()` method so drivers which lack access
145+
to the expected device can consistently suggest that this may be because
146+
of running both an NDE-wrapped service unit and a manually launched
147+
driver program at the same time. Currently added to `libusb{0,1}.c`
148+
code, but may later be expanded to e.g. serial drivers and other media,
149+
when their behavior in such situations gets identified. [follow-up to
150+
issue #477, PR #3041]
144151

145152
- `apc_modbus` driver updates:
146153
* The time stamp and inter-frame delay accounting was fixed, alleviating

common/common-nut_version.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,20 @@ const char *suggest_doc_links(const char *progname, const char *progconf) {
314314

315315
return buf;
316316
}
317+
318+
/* Define this in one spot, to change conditions or wording easily */
319+
void suggest_NDE_conflict(void) {
320+
#if (defined(WITH_SOLARIS_SMF) && WITH_SOLARIS_SMF) || (defined(HAVE_SYSTEMD) && HAVE_SYSTEMD)
321+
upsdebugx(0, "Please check if you are not trying to both "
322+
"start a NUT driver program manually (directly "
323+
"or via upsdrvctl), and as a service at the same "
324+
"time. Please see 'man nut-driver-enumerator' or "
325+
"%s/docs/man/nut-driver-enumerator.html for details",
326+
NUT_WEBSITE_BASE);
327+
/* FIXME: Wiki names are inherently volatile;
328+
* maybe keep a more persistent copy in the
329+
* NUT-website with some knowledge-base ID? */
330+
upsdebugx(1, "Also try NUT GitHub Wiki, seek a page named like "
331+
"https://github.com/networkupstools/nut/wiki/nut%%E2%%80%%90driver%%E2%%80%%90enumerator-(NDE)");
332+
#endif /* WITH_SOLARIS_SMF || HAVE_SYSTEMD */
333+
}

drivers/libusb0.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,12 @@ static int nut_libusb_open(usb_dev_handle **udevp,
754754
"requested criteria",
755755
count_open_attempts - count_open_errors);
756756
}
757+
suggest_NDE_conflict();
758+
/* FIXME: Wiki names are inherently volatile;
759+
* maybe keep a more persistent copy in the
760+
* NUT-website with some knowledge-base ID? */
761+
upsdebugx(1, "For more ideas, please check a NUT GitHub Wiki page named like "
762+
"https://github.com/networkupstools/nut/wiki/%%22Insufficient-permissions%%22-when-starting-USB-drivers");
757763
}
758764

759765
#ifdef WIN32

drivers/libusb1.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,12 @@ static int nut_libusb_open(libusb_device_handle **udevp,
840840
"requested criteria",
841841
count_open_attempts - count_open_errors);
842842
}
843+
suggest_NDE_conflict();
844+
/* FIXME: Wiki names are inherently volatile;
845+
* maybe keep a more persistent copy in the
846+
* NUT-website with some knowledge-base ID? */
847+
upsdebugx(1, "For more ideas, please check a NUT GitHub Wiki page named like "
848+
"https://github.com/networkupstools/nut/wiki/%%22Insufficient-permissions%%22-when-starting-USB-drivers");
843849
}
844850

845851
#ifdef WIN32

include/common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ const char *describe_NUT_VERSION_once(void);
229229
*/
230230
const char *suggest_doc_links(const char *progname, const char *progconf);
231231

232+
/* For drivers that failed to start because they could not hold on to a
233+
* device, on systems where the nut-driver-enumerator could produce units
234+
* that conflict with a manually-launched driver program, suggest that
235+
* this may be the case. Has some work on systems where NDE can be used
236+
* (currently where SMF or SystemD were considered during build), no-op
237+
* on others.
238+
* We define this in one spot, to change conditions or wording easily.
239+
*/
240+
void suggest_NDE_conflict(void);
241+
232242
/* Based on NUT_QUIET_INIT_BANNER envvar (present and empty or "true")
233243
* hide the NUT tool name+version banners; show them by default */
234244
int banner_is_disabled(void);

0 commit comments

Comments
 (0)