Skip to content

libnvme: examples: fix select() usage in telemetry-listen - #3914

Merged
igaw merged 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:fix-telemetry-listen-select
Aug 26, 2026
Merged

libnvme: examples: fix select() usage in telemetry-listen#3914
igaw merged 1 commit into
linux-nvme:masterfrom
prabhakarpujeri:fix-telemetry-listen-select

Conversation

@prabhakarpujeri

Copy link
Copy Markdown

Problem

Port of linux-nvme/libnvme#1126 to libnvme3 (the example has the same misuse vector).

wait_events() passes the count of uevent fds to select() as nfds; the argument is max-fd+1, and with stdio occupying 0-2 the uevent fds always start at 3, so for the common 1-3 controller case the watcher never wakes on any telemetry AEN. Additionally, select() clears inactive fds in the passed set, and the same set is reused — after the first event the loop only monitors fds that happened to be active. With no controller it spins at 100% CPU, and calloc() isn't checked.

Fix

Track maxfd while FD_SETing; pass maxfd + 1 to select() on a re-armed local copy of the set; skip the wait loop when no controller was found; check calloc().

Testing

  • Full meson suite green. The select-nfds semantics were verified with a standalone snippet in the 1.x PR (same mechanism applies verbatim).

select() takes the highest watched fd plus one, not the number of
watched fds.  With stdio occupying 0-2, the uevent fds of 1-3
controllers sit above the count, so select(nr) never wakes on any
of them - the listener's whole purpose silently dead for the
common 1-3 controller case.  Also select() clears inactive bits in
the passed set: restore the watched set on a local copy each round
(otherwise the first event permanently disables all other fds),
skip the loop entirely when no controller was found (select(0,...)
returns immediately, spinning at 100% CPU), and guard calloc().

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
@igaw
igaw force-pushed the fix-telemetry-listen-select branch from fe1fdbe to 76e5180 Compare August 26, 2026 13:48
@igaw

igaw commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

removed the libnvme 1 reference.

@igaw
igaw merged commit cc34fe8 into linux-nvme:master Aug 26, 2026
30 checks passed
@igaw

igaw commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants