Page MenuHomeFreeBSD

Restore ability to shutdown datagram sockets
ClosedPublic

Authored by sobomax on Apr 10 2017, 6:01 PM.

Details

Summary

Historically, the FreeBSD shutdown(2) system call did not make distinction between datagram and stream sockets. This allowed one thread (or process) to interrupt other thread (or process) blocked in recvXXX(2) by calling shutdown() on that socket. The revision D3039 (subsequently checked into svn rev 285910) has removed this behavior. Unfortunately POSIX provides no other clean way to do that and there are quite lot of software that depends on the old behavior. In addition, analysis done in the D3039 used as a basis for making this change is not entirely correct, for example fairly recent Linux kernel (4.4.0 as of time of this writing) actually tears socket down even for datagram socket and causes any current or future blocking reads on that socket to fail with 0-lengh result.

Attached patch makes FreeBSD behavior match our historical behavior and that of our Linux 4.4.0, i.e. return ENOTCONN but still "disconnect" socket and fail any current or future readers.

Test Plan

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

sobomax created this revision.Apr 10 2017, 6:01 PM
sobomax edited the summary of this revision. (Show Details)Apr 10 2017, 6:03 PM
sobomax edited the summary of this revision. (Show Details)
sobomax edited the summary of this revision. (Show Details)Apr 10 2017, 6:08 PM
emaste added a subscriber: emaste.Apr 10 2017, 8:10 PM
ed accepted this revision.Apr 10 2017, 8:45 PM

Looks good to me. Still, could you add a comment to the code explaining the situation?

This revision is now accepted and ready to land.Apr 10 2017, 8:45 PM

I'm not sure I approve of calling a local variable 'fakeerror'. Given that the only value it can take on is ENOTCONN, how about making it a boolean 'soerror_enotconn'?

sobomax edited the summary of this revision. (Show Details)Apr 13 2017, 4:11 AM
sobomax edited edge metadata.Apr 13 2017, 4:39 PM
sobomax updated this revision to Diff 27417.

Rework previous change to restore ability to shutdown datagram
sockets to be easier to understand and put a comment explaining
what's going on and why.

Suggested by: rwatson, ed

This revision now requires review to proceed.Apr 13 2017, 4:39 PM
sobomax updated this revision to Diff 27418.Apr 13 2017, 4:47 PM

Collapse if/return/else/return into a single return statement.

hiren accepted this revision as: hiren.Apr 13 2017, 4:58 PM
hiren added a subscriber: hiren.

Other than it not being able to build, I like the var name change requested by Robert and the general approach.

This revision is now accepted and ready to land.Apr 13 2017, 4:58 PM
glebius accepted this revision.Apr 14 2017, 12:58 AM
This revision was automatically updated to reflect the committed changes.