Skip to content

Commit

Permalink
drivers/upsdrvquery.c, NEWS.adoc: upsdrvquery_read_timeout(): fix pri…
Browse files Browse the repository at this point in the history
…vate use of timeval={-1,-1} as select(..., NULL) for indefinite wait [#1922, #2392, #2686, #2670]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Dec 2, 2024
1 parent 35edb4f commit a9b75b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ https://github.com/networkupstools/nut/milestone/11
a `*_s()` variant was available was not handled correctly. [PR #2583]
* A recently introduced `allow_killpower` did not actually work as an
`ups.conf` flag (only as a protocol command). [issue #2605, PR #2606]
* The ability of two copies of the driver program to talk to each other
with `upsdrvquery.c` code was not complete for the case of indefinite
`select()` wait timeout. Now `upsdrvquery_read_timeout()` fixed private
use of `struct timeval={-1,-1}` as a trigger to `select(..., NULL)`,
as logged in one part of code and not handled in the other, for the
indefinite wait [#1922, #2392, #2686, #2670]
- development iterations of NUT should now identify with not only the semantic
version of a preceding release, but with git-derived information about the
Expand Down
4 changes: 3 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3247 utf-8
personal_ws-1.1 en 3249 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -2977,6 +2977,7 @@ timehead
timername
timestamp
timeticks
timeval
tios
tmp
tmpfiles
Expand Down Expand Up @@ -3075,6 +3076,7 @@ upsdebugx
upsdev
upsdrv
upsdrvctl
upsdrvquery
upsdrvsvcctl
upserror
upsfetch
Expand Down
7 changes: 6 additions & 1 deletion drivers/upsdrvquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ ssize_t upsdrvquery_read_timeout(udq_pipe_conn_t *conn, struct timeval tv) {
struct timeval start, now, presleep;
#endif

upsdebugx(5, "%s: tv={sec=%" PRIiMAX ", usec=%06" PRIiMAX "}%s",
__func__, (intmax_t)tv.tv_sec, (intmax_t)tv.tv_usec,
tv.tv_sec < 0 || tv.tv_usec < 0 ? " (unlimited timeout)" : ""
);

if (!conn || INVALID_FD(conn->sockfd)) {
if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_CONNECT)
upslog_with_errno(LOG_ERR, "socket not initialized");
Expand All @@ -248,7 +253,7 @@ ssize_t upsdrvquery_read_timeout(udq_pipe_conn_t *conn, struct timeval tv) {
FD_ZERO(&rfds);
FD_SET(conn->sockfd, &rfds);

if (select(conn->sockfd + 1, &rfds, NULL, NULL, &tv) < 0) {
if (select(conn->sockfd + 1, &rfds, NULL, NULL, tv.tv_sec < 0 || tv.tv_usec < 0 ? NULL : &tv) < 0) {
if (nut_debug_level > 0 || nut_upsdrvquery_debug_level >= NUT_UPSDRVQUERY_DEBUG_LEVEL_DIALOG)
upslog_with_errno(LOG_ERR, "select with socket");
/* upsdrvquery_close(conn); */
Expand Down

0 comments on commit a9b75b1

Please sign in to comment.