Re: [PATCH] poll.2: explicitly say what happens for regular files &c.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/24/23 14:13, наб wrote:
Naively, one may consider being "ready" to mean, for example,
   lseek(0, 0, SEEK_END); poll({.fd = 0, .events = POLLIN}, 0);
to be able to say whether new data has appeared at the end of the file.

This is not the case, and poll() is only meaningful as
"will a read or a write sleep": regular files and block devices are
always ready to return an empty read in this case, for example,
and you need to use inotify to achieve this.

Under Linux this is governed by DEFAULT_POLLMASK
   (EPOLLIN | EPOLLOUT | EPOLLRDNORM | EPOLLWRNORM)
being returned if no explicit poll operation is defined for the file.

As contrast, unpollables like the above are refused by epoll_ctl(ADD).

I explicitly hit the two keywords I searched for (regular, block)
before just writing a test program to confirm that poll() behaved as
expected and is not a good fit for my use-case.

This behaviour is guaranteed by POSIX (Issue 8 Draft 3):
51381  The poll( ) and ppoll( ) functions shall support regular files, terminal and pseudo-terminal
51382  devices, FIFOs, pipes, and sockets. The behavior of poll( ) and ppoll( ) on elements of fds that refer
51383  to other types of file is unspecified.

51384  Regular files shall always poll TRUE for reading and writing.

51385  A file descriptor for a socket that is listening for connections shall indicate that it is ready for
51386  reading, once connections are available. A file descriptor for a socket that is connecting
51387  asynchronously shall indicate that it is ready for writing, once a connection has been established.

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@xxxxxxxxxxxxxxxxxx>

Patch applied.  Thanks,
Alex

---
  man2/poll.2 | 7 +++++++
  1 file changed, 7 insertions(+)

diff --git a/man2/poll.2 b/man2/poll.2
index 0b834306a..c2982a243 100644
--- a/man2/poll.2
+++ b/man2/poll.2
@@ -123,6 +123,13 @@ .SH DESCRIPTION
  .IP \[bu]
  the timeout expires.
  .PP
+Being "ready" means that the requested operation will not block; thus,
+.BR poll ()ing
+regular files, block devices, and other files with no reasonable
+polling semantic
+.I always
+returns instantly as ready to read and write.
+.PP
  Note that the
  .I timeout
  interval will be rounded up to the system clock granularity,

--
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux