Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 24 Aug 2020 15:50:58 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r364695 - stable/12/sys/compat/linux
Message-ID:  <202008241550.07OFowDR052512@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Mon Aug 24 15:50:57 2020
New Revision: 364695
URL: https://svnweb.freebsd.org/changeset/base/364695

Log:
  MFC r347969 by dchagin:
  
  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

Modified:
  stable/12/sys/compat/linux/linux_socket.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/compat/linux/linux_socket.c
==============================================================================
--- stable/12/sys/compat/linux/linux_socket.c	Mon Aug 24 15:49:37 2020	(r364694)
+++ stable/12/sys/compat/linux/linux_socket.c	Mon Aug 24 15:50:57 2020	(r364695)
@@ -805,6 +805,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);
@@ -812,7 +814,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 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008241550.07OFowDR052512>