Write to a pipe when there are no readers from the pipe should return -EPIPE.

This commit is contained in:
ligd 2018-08-26 07:17:31 -06:00 committed by Gregory Nutt
parent 2e8eba35ff
commit 38cd556af8
1 changed files with 13 additions and 0 deletions

View File

@ -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