This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 36b42b87741 drivers/net/tun.c: Let a signal end a blocked read() or
write().
36b42b87741 is described below
commit 36b42b87741086fe6a264d9a281b745f2c9ea99e
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 26 08:35:53 2026 +0100
drivers/net/tun.c: Let a signal end a blocked read() or write().
tun_read() and tun_write() ignored the result of nxsem_wait() and went
back to wait. A signal did not end a read() that waits for a packet or
a write() that waits for the reader, and pthread_cancel() did not end
the thread there. Linux returns EINTR (or restarts the call) in this
case.
Return the error of nxsem_wait() (-EINTR, -ECANCELED). Nothing was
read or written at that point. The wait flag can stay set: a later
notification then wakes the next read() or write() once, and it checks
the buffers and waits again.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
drivers/net/tun.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 1bf547fae04..836457e7dae 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1057,7 +1057,14 @@ static ssize_t tun_write(FAR struct file *filep, FAR
const char *buffer,
priv->write_wait = true;
nxmutex_unlock(&priv->lock);
- nxsem_wait(&priv->write_wait_sem);
+
+ /* A signal or a cancellation ends the wait: nothing written yet */
+
+ ret = nxsem_wait(&priv->write_wait_sem);
+ if (ret < 0)
+ {
+ return ret;
+ }
}
nxmutex_unlock(&priv->lock);
@@ -1157,7 +1164,14 @@ static ssize_t tun_read(FAR struct file *filep, FAR char
*buffer,
priv->read_wait = true;
nxmutex_unlock(&priv->lock);
- nxsem_wait(&priv->read_wait_sem);
+
+ /* A signal or a cancellation ends the wait: nothing read yet */
+
+ ret = nxsem_wait(&priv->read_wait_sem);
+ if (ret < 0)
+ {
+ return ret;
+ }
}
nxmutex_unlock(&priv->lock);