Author: dchagin
Date: Sun May 19 09:23:20 2019
New Revision: 347969
URL: https://svnweb.freebsd.org/changeset/base/347969

Log:
  Linux send() call returns EAGAIN instead of ENOTCONN in case when the
  socket is non-blocking and connect() is not finished yet.
  
  Initial patch developed by Steven Hartland in 2008 and adopted by me.
  
  PR:           129169
  Reported by:  smh@
  MFC after:    2 weeks

Modified:
  head/sys/compat/linux/linux_socket.c

Modified: head/sys/compat/linux/linux_socket.c
==============================================================================
--- head/sys/compat/linux/linux_socket.c        Sun May 19 09:18:09 2019        
(r347968)
+++ head/sys/compat/linux/linux_socket.c        Sun May 19 09:23:20 2019        
(r347969)
@@ -798,6 +798,8 @@ linux_send(struct thread *td, struct linux_send_args *
                caddr_t to;
                int tolen;
        } */ bsd_args;
+       struct file *fp;
+       int error, fflag;
 
        bsd_args.s = args->s;
        bsd_args.buf = (caddr_t)PTRIN(args->msg);
@@ -805,7 +807,21 @@ linux_send(struct thread *td, struct linux_send_args *
        bsd_args.flags = args->flags;
        bsd_args.to = NULL;
        bsd_args.tolen = 0;
-       return (sys_sendto(td, &bsd_args));
+       error = sys_sendto(td, &bsd_args);
+       if (error == ENOTCONN) {
+               /*
+                * Linux doesn't return ENOTCONN for non-blocking sockets.
+                * Instead it returns the EAGAIN.
+                */
+               error = getsock_cap(td, args->s, &cap_send_rights, &fp,
+                   &fflag, NULL);
+               if (error == 0) {
+                       if (fflag & FNONBLOCK)
+                               error = EAGAIN;
+                       fdrop(fp, td);
+               }
+       }
+       return (error);
 }
 
 struct linux_recv_args {
_______________________________________________
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