Skip to content

Commit fde2fdd

Browse files
authored
Merge pull request #2400 from jimklimov/issue-2399
drivers/libusb{0,1}.c, NEWS.adoc: avoid spurious syslog of `(nut_)libusb_get_string: Success`
2 parents 429d38e + 4d6663e commit fde2fdd

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

NEWS.adoc

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ https://github.com/networkupstools/nut/milestone/11
5959
(similar to `runtimecal` in some other drivers, may be refactored
6060
to that configuration and logic model in later NUT releases)
6161
62+
- USB drivers could log `(nut_)libusb_get_string: Success` due to either
63+
reading an empty string or getting a success code `0` from libusb.
64+
This difference should now be better logged, and not into syslog. [#2399]
65+
6266
- upsmon: it was realized that the `POWERDOWNFLAG` must be explicitly set in
6367
the configuration file, there is no built-in default in the binary program
6468
(the settings facilitated by the `configure` script during build "only"

drivers/libusb0.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* @author Copyright (C)
66
* 2003 - 2007 Arnaud Quette <[email protected]>
77
* 2005 - 2007 Peter Selinger <[email protected]>
8+
* 2021 - 2024 Jim Klimov <[email protected]>
89
*
910
* This program is sponsored by MGE UPS SYSTEMS - opensource.mgeups.com
1011
*
@@ -37,7 +38,7 @@
3738
#endif
3839

3940
#define USB_DRIVER_NAME "USB communication driver (libusb 0.1)"
40-
#define USB_DRIVER_VERSION "0.47"
41+
#define USB_DRIVER_VERSION "0.48"
4142

4243
/* driver description structure */
4344
upsdrv_info_t comm_upsdrv_info = {
@@ -781,6 +782,7 @@ static int libusb_strerror(const int ret, const char *desc)
781782
return 0;
782783
#endif /* WIN32 */
783784

785+
case 0: /** TOTHINK: Should this (probably LIBUSB_SUCCESS) be quiet? */
784786
default: /* Undetermined, log only */
785787
upslogx(LOG_DEBUG, "%s: %s", desc, usb_strerror());
786788
return 0;
@@ -907,6 +909,18 @@ static int libusb_get_string(
907909
errno = -ret;
908910
#endif
909911

912+
/** 0 can be seen as an empty string, or as a success for
913+
* logging below - also tends to happen */
914+
if (ret == 0) {
915+
size_t len = strlen(buf);
916+
upsdebugx(2, "%s: usb_get_string_simple() returned "
917+
"0 (might be just success code), "
918+
"actual buf length is %" PRIuSIZE, __func__, len);
919+
/* if (len) */
920+
return len;
921+
/* else may log "libusb_get_string: Success" and return 0 below */
922+
}
923+
910924
return libusb_strerror(ret, __func__);
911925
}
912926

drivers/libusb1.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @author Copyright (C) 2016 Eaton
66
* Copyright (C) 2016 Arnaud Quette <[email protected]>
7-
* Copyright (C) 2021 Jim Klimov <[email protected]>
7+
* Copyright (C) 2021-2024 Jim Klimov <[email protected]>
88
*
99
* The logic of this file is ripped from mge-shut driver (also from
1010
* Arnaud Quette), which is a "HID over serial link" UPS driver for
@@ -33,7 +33,7 @@
3333
#include "nut_stdint.h"
3434

3535
#define USB_DRIVER_NAME "USB communication driver (libusb 1.0)"
36-
#define USB_DRIVER_VERSION "0.47"
36+
#define USB_DRIVER_VERSION "0.48"
3737

3838
/* driver description structure */
3939
upsdrv_info_t comm_upsdrv_info = {
@@ -872,6 +872,7 @@ static int nut_libusb_strerror(const int ret, const char *desc)
872872
return 0;
873873
#endif /* WIN32 */
874874

875+
case LIBUSB_SUCCESS: /** TOTHINK: Should this be quiet? */
875876
case LIBUSB_ERROR_OTHER: /** Other error */
876877
default: /** Undetermined, log only */
877878
upslogx(LOG_DEBUG, "%s: %s", desc, libusb_strerror((enum libusb_error)ret));
@@ -1022,6 +1023,18 @@ static int nut_libusb_get_string(
10221023
ret = libusb_get_string_descriptor_ascii(udev, (uint8_t)StringIdx,
10231024
(unsigned char*)buf, (int)buflen);
10241025

1026+
/** 0 can be seen as an empty string, or as LIBUSB_SUCCESS for
1027+
* logging below - also tends to happen */
1028+
if (ret == 0) {
1029+
size_t len = strlen(buf);
1030+
upsdebugx(2, "%s: libusb_get_string_descriptor_ascii() returned "
1031+
"0 (might be just LIBUSB_SUCCESS code), "
1032+
"actual buf length is %" PRIuSIZE, __func__, len);
1033+
/* if (len) */
1034+
return len;
1035+
/* else may log "nut_libusb_get_string: Success" and return 0 below */
1036+
}
1037+
10251038
return nut_libusb_strerror(ret, __func__);
10261039
}
10271040

0 commit comments

Comments
 (0)