Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142239636
D10351.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D10351.id.diff
View Options
Index: head/sys/kern/uipc_socket.c
===================================================================
--- head/sys/kern/uipc_socket.c
+++ head/sys/kern/uipc_socket.c
@@ -2343,13 +2343,27 @@
soshutdown(struct socket *so, int how)
{
struct protosw *pr = so->so_proto;
- int error;
+ int error, soerror_enotconn;
if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))
return (EINVAL);
+
+ soerror_enotconn = 0;
if ((so->so_state &
- (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0)
- return (ENOTCONN);
+ (SS_ISCONNECTED | SS_ISCONNECTING | SS_ISDISCONNECTING)) == 0) {
+ /*
+ * POSIX mandates us to return ENOTCONN when shutdown(2) is
+ * invoked on a datagram sockets, however historically we would
+ * actually tear socket down. This is known to be leveraged by
+ * some applications to unblock process waiting in recvXXX(2)
+ * by other process that it shares that socket with. Try to meet
+ * both backward-compatibility and POSIX requirements by forcing
+ * ENOTCONN but still asking protocol to perform pru_shutdown().
+ */
+ if (so->so_type != SOCK_DGRAM)
+ return (ENOTCONN);
+ soerror_enotconn = 1;
+ }
CURVNET_SET(so->so_vnet);
if (pr->pr_usrreqs->pru_flush != NULL)
@@ -2360,11 +2374,12 @@
error = (*pr->pr_usrreqs->pru_shutdown)(so);
wakeup(&so->so_timeo);
CURVNET_RESTORE();
- return (error);
+ return ((error == 0 && soerror_enotconn) ? ENOTCONN : error);
}
wakeup(&so->so_timeo);
CURVNET_RESTORE();
- return (0);
+
+ return (soerror_enotconn ? ENOTCONN : 0);
}
void
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jan 18, 4:56 PM (9 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27712790
Default Alt Text
D10351.id.diff (1 KB)
Attached To
Mode
D10351: Restore ability to shutdown datagram sockets
Attached
Detach File
Event Timeline
Log In to Comment