Author: markj
Date: Mon Nov 18 15:27:52 2019
New Revision: 354813
URL: https://svnweb.freebsd.org/changeset/base/354813

Log:
  MFC r354629:
  Fix handling of PIPE_EOF in the direct write path.

Modified:
  stable/12/sys/kern/sys_pipe.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/kern/sys_pipe.c
==============================================================================
--- stable/12/sys/kern/sys_pipe.c       Mon Nov 18 14:12:33 2019        
(r354812)
+++ stable/12/sys/kern/sys_pipe.c       Mon Nov 18 15:27:52 2019        
(r354813)
@@ -972,15 +972,8 @@ retry:
                goto error1;
        }
 
-       while (wpipe->pipe_map.cnt != 0) {
-               if (wpipe->pipe_state & PIPE_EOF) {
-                       wpipe->pipe_map.cnt = 0;
-                       pipe_destroy_write_buffer(wpipe);
-                       pipeselwakeup(wpipe);
-                       pipeunlock(wpipe);
-                       error = EPIPE;
-                       goto error1;
-               }
+       while (wpipe->pipe_map.cnt != 0 &&
+           (wpipe->pipe_state & PIPE_EOF) == 0) {
                if (wpipe->pipe_state & PIPE_WANTR) {
                        wpipe->pipe_state &= ~PIPE_WANTR;
                        wakeup(wpipe);
@@ -995,12 +988,16 @@ retry:
                        break;
        }
 
-       if (wpipe->pipe_state & PIPE_EOF)
+       if ((wpipe->pipe_state & PIPE_EOF) != 0) {
+               wpipe->pipe_map.cnt = 0;
+               pipe_destroy_write_buffer(wpipe);
+               pipeselwakeup(wpipe);
                error = EPIPE;
-       if (error == EINTR || error == ERESTART)
+       } else if (error == EINTR || error == ERESTART) {
                pipe_clone_write_buffer(wpipe);
-       else
+       } else {
                pipe_destroy_write_buffer(wpipe);
+       }
        pipeunlock(wpipe);
        KASSERT((wpipe->pipe_state & PIPE_DIRECTW) == 0,
            ("pipe %p leaked PIPE_DIRECTW", wpipe));
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to