Skip to content

fs/vfs: Report POLLERR in the read and write sets of select(). - #20648

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:select-pollerr
Oct 14, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
casaroli:select-pollerr

Conversation

@casaroli

@casaroli casaroli commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

depends-on: [/pull/20661 apache/nuttx-apps/pull/3845]

Summary

select() put a descriptor with POLLERR only in exceptfds. A caller that asked only for readfds or writefds, which is the usual case, did not see the error: select() returned 0, also with no timeout, where 0 means that the timeout expired.

POSIX says that a descriptor is ready for reading (or writing) when the call would not block, "whether or not the function would transfer data successfully", so also when it would return an error. Linux reports POLLERR in the read and write sets.

This PR reports POLLERR in readfds and writefds. poll() reports POLLHUP and POLLERR also when they were not asked for, so the PR sets only the bits of the sets that the caller asked for: before, a descriptor in writefds only could also appear in readfds on POLLHUP. exceptfds does not change.

Impact

select() callers that ask for readfds or writefds now see a descriptor with an error as ready, and the following read() or write() returns the error. exceptfds is as before.

Testing

qemu-armv8a:nsh (flat) with CONFIG_PIPES=y and the default CONFIG_DEV_PIPE_NPOLLWAITERS=4. A test program starts 6 threads that call select() with no timeout on the read end of one pipe, then writes 6 bytes. The pipe has 4 poll slots, so threads 5 and 6 get POLLERR:

master this PR
select() calls with no timeout that returned 0 2 of 6 0 of 6

With this PR the two threads see the descriptor in readfds, and their read() waits for the data. ostest exits with status 0 on both. Build: qemu-armv8a:knsh and lm3s6965-ek:qemu-flat, no warnings. tools/checkpatch.sh -c -u -m -g passes.

select() put a descriptor with POLLERR only in exceptfds.  A caller that
asked only for readfds or writefds did not see the error: select()
returned 0, also with no timeout, where 0 means that the timeout
expired.  POSIX says that a descriptor is ready for reading or writing
when the call would not block, also when it would return an error.
For example, a fifth thread that polls a pipe with
CONFIG_DEV_PIPE_NPOLLWAITERS=4 gets POLLERR, and its select() with no
timeout returned 0 at once.

Report POLLERR in readfds and writefds, as Linux does.  poll() reports
POLLHUP and POLLERR also when they were not asked for, so set only the
bits of the sets that the caller asked for.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@github-actions github-actions Bot added Area: File System File System issues Size: S The size of the change in this PR is small labels Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report

arduino-mega2560

  • flash: .data +16 B (+0.0%, 65,952 B / 262,144 B, total: 25% used)
  • sram: .data +16 B (+0.6%, 2,718 B / 8,192 B, total: 33% used)

esp32-devkitc

  • ROM: .dram0.data +16 B, .flash.rodata +12 B, .flash.text +60 B (+0.1%, 125,240 B / 4,194,272 B, total: 3% used)
  • dram0_0_seg: .dram0.data +16 B (+0.2%, 10,012 B / 180,736 B, total: 6% used)
  • drom0_0_seg: .flash.rodata +12 B (+0.1%, 13,472 B / 4,194,272 B, total: 0% used)
  • irom0_0_seg: .flash.text +60 B (+0.1%, 89,416 B / 3,342,304 B, total: 3% used)

hifive1-revb

  • flash: .data +8 B, .text +88 B (+0.1%, 84,348 B / 4,194,304 B, total: 2% used)
  • sram: .bss -16 B, .data +8 B (-0.2%, 3,956 B / 16,384 B, total: 24% used)

mirtoo

  • kseg0_progmem: .data +4 B, .text +12 B (+0.0%, 67,952 B / 131,072 B, total: 52% used)
  • kseg1_datamem: .data +4 B (+0.2%, 2,588 B / 32,256 B, total: 8% used)

qemu-armv8a

  • Code: .rodata +16 B, .text.lib_fwrite_unlocked +64 B, .text.nsh_cmdparm.constprop.0 +16 B, .text.nsh_parse_command +12 B (+0.0%, 347,636 B)
  • Data: .data.g_version +2 B (+0.0%, 77,476 B)

qemu-intel64

  • Code: .text +108 B (+0.0%, 8,682,620 B)

rx65n-rsk2mb

  • RAM: .data +4 B (+0.1%, 6,590 B / 262,144 B, total: 3% used)
  • ROM: .rodata +16 B (+0.0%, 87,092 B / 2,097,152 B, total: 4% used)

s698pm-dkit

  • Code: .text +144 B (+0.0%, 374,816 B)

stm32-nucleo-f103rb

  • flash: .text +92 B (+0.3%, 34,752 B / 131,072 B, total: 27% used)

@xiaoxiang781216
xiaoxiang781216 merged commit 02a168d into apache:master Oct 14, 2026
54 of 106 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants