casaroli opened a new pull request, #21416: URL: https://github.com/apache/nuttx/pull/21416
## Summary `connect()`, `poll()` and `select()` of a `SOCK_DGRAM` Unix domain socket returned `ENOSYS`. A program that writes to `/dev/log` (the `logger` command, for example) connects a datagram socket and calls `send()`: on NuttX it lost each message. A daemon could not wait for messages on `/dev/log` with `poll()`. - `connect()` keeps the name of the bound receiver. `send()` and `write()` without an address send to it, `getpeername()` gives it, and `AF_UNSPEC` removes it. The errors are those of a stream `connect()`: `ENOENT`, `ECONNREFUSED`. POSIX says that a connected datagram socket takes datagrams only from its peer. The receiver has one FIFO for all senders, so the sender checks this, as Linux does: a send from another socket fails with `EPERM`. - `bind()` of a datagram socket now creates and opens the receive FIFO, and `close()` closes it, so `poll()` can watch it: `POLLIN` when a datagram waits, `POLLOUT` always. `recv(MSG_DONTWAIT)` on an empty socket returns `EAGAIN`. - drivers/pipes: the close of the last writer sent `POLLHUP` also for buffer policy 1, which `pipecommon_poll()` does not report (bcddaa59a90). The datagram FIFO has policy 1, and each send opens and closes it, so `poll()` got `POLLHUP` after each send. - `sendto()` to an abstract name used the FIFO of the empty name. - The first commit adds a blank line that nxstyle asks for in `local_recvmsg.c` (CI checks the whole file). ## Impact - Datagram sockets: `connect()`, `send()` and `write()` without an address, `getpeername()`, `poll()` and `select()` now work. A second `bind()` of a datagram socket fails with `EINVAL`. - A bound datagram socket allocates its receive FIFO at `bind()`, not at the first `recvfrom()`. `struct local_conn_s` grows by `UNIX_PATH_MAX` + 1 bytes with `CONFIG_NET_LOCAL_DGRAM`. - The pipe change affects only buffer policy 1, which only datagram sockets use. - Stream sockets and socket pairs: no change. The same code in flat, protected and kernel builds; no architecture code. - Documentation: no page describes Unix domain sockets; no change. ## Testing Test program `dgramconn.c` (POSIX, 20 cases): `connect()` to a bound datagram socket, `getpeername()`, `send()`, `write()` and `sendto()` with a NULL address, `poll(POLLIN)` empty, after a send and while a thread sends after 200 ms, no `POLLHUP` while a thread sends a datagram that is too large, `poll(POLLOUT)`, `select()`, `recv(MSG_DONTWAIT)` and `O_NONBLOCK` on an empty socket, a connected receiver and a stranger, `connect(AF_UNSPEC)`, a second `connect()`, `ENOENT` for a missing path, `ECONNREFUSED` for a regular file and after the close of the receiver, an abstract name. On Linux 7.0 (arm64) all 20 cases pass. qemu-armv8a (HVF) with `NET`, `NET_LOCAL`, `NET_LOCAL_STREAM`, `NET_LOCAL_DGRAM`, `PIPES`, `NETDEV_LATEINIT`, `NET_SOCKOPTS`; knsh runs the test as an ELF program, nsh (flat) as a builtin application: | | master ae2f4f9d87f | this PR | |---|---|---| | `dgramconn` on knsh (kernel) | `connect` FAIL (`ENOSYS`) | 20 PASS | | `dgramconn` on nsh (flat) | `connect` FAIL (`ENOSYS`) | 20 PASS | | ostest on knsh, nsh, and the flat build with the test | status 0 | status 0 | Builds with `EXTRAFLAGS="-Wno-cpp -Werror"`: qemu-armv8a:nsh with `NET`, `NET_LOCAL`, `NETDEV_LATEINIT`, `NET_SOCKOPTS` and datagram sockets only, and with stream sockets only; qemu-armv8a:knsh with `NET`, `NET_LOCAL`, `NETDEV_LATEINIT`, `NET_SOCKOPTS` and `NET_LOCAL_SCM`; mps2-an500:knsh (protected) with `NET`, `NET_LOCAL`, `NETDEV_LATEINIT`, `NET_SOCKOPTS`; qemu-armv8a:nsh with pipes and no network; sim:udgram (datagram sockets only). All OK, no warnings. The tests ran on master ae2f4f9d87f; the branch is rebased on 1ebdb91036a (the new commits touch no file of this PR; after the rebase only code comments changed). `tools/checkpatch.sh -c -u -m -g` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
