Fixes bug in sys_pipe()
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 6 Sep 2013 02:18:41 +0000 (19:18 -0700)
committerBarret Rhoden <brho@cs.berkeley.edu>
Thu, 12 Sep 2013 00:45:45 +0000 (17:45 -0700)
Under some circumstances, a writer could block and then never wake up.

kern/src/vfs.c

index 4c91522..b707fd2 100644 (file)
@@ -1750,6 +1750,13 @@ ssize_t pipe_file_write(struct file *file, const char *buf, size_t count,
                }
                cv_wait(&pii->p_cv);
                cpu_relax();
+               /* Still need to check in the loop, in case the last reader left while
+                * we slept. */
+               if (!pii->p_nr_readers) {
+                       cv_unlock(&pii->p_cv);
+                       set_errno(EPIPE);
+                       return -1;
+               }
        }
        /* We might need to wrap-around with our copy, so we'll do the copy in two
         * passes.  This will copy up to the end of the buffer, then on the next