From 38cd556af8e851298dd365e5c8cddcc7a1c2e760 Mon Sep 17 00:00:00 2001 From: ligd Date: Sun, 26 Aug 2018 07:17:31 -0600 Subject: [PATCH] Write to a pipe when there are no readers from the pipe should return -EPIPE. --- drivers/pipes/pipe_common.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/pipes/pipe_common.c b/drivers/pipes/pipe_common.c index 532e705671..bd5a1a1be5 100644 --- a/drivers/pipes/pipe_common.c +++ b/drivers/pipes/pipe_common.c @@ -531,11 +531,24 @@ ssize_t pipecommon_write(FAR struct file *filep, FAR const char *buffer, DEBUGASSERT(dev); pipe_dumpbuffer("To PIPE:", (FAR uint8_t *)buffer, len); + /* Handle zero-length writes */ + if (len == 0) { return 0; } + /* REVISIT: "If all file descriptors referring to the read end of a pipe + * have been closed, then a write will cause a SIGPIPE signal to be + * generated for the calling process. If the calling process is ignoring + * this signal, then write(2) fails with the error EPIPE." + */ + + if (dev->d_nreaders <= 0) + { + return -EPIPE; + } + /* At present, this method cannot be called from interrupt handlers. That * is because it calls nxsem_wait (via pipecommon_semtake below) and * nxsem_wait cannot be called from interrupt level. This actually