From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Laight Subject: RE: [Bug 106241] New: shutdown(3)/close(3) behaviour is incorrect for sockets in accept(3) Date: Fri, 6 Nov 2015 15:07:30 +0000 Message-ID: <063D6719AE5E284EB5DD2968C1650D6D1CBCD484@AcuExch.aculab.com> References: <201510221951.t9MJp5LC005892@room101.nl.oracle.com> <20151022215741.GW22011@ZenIV.linux.org.uk> <201510230952.t9N9qYZJ021998@room101.nl.oracle.com> <20151024023054.GZ22011@ZenIV.linux.org.uk> <201510270908.t9R9873a001683@room101.nl.oracle.com> <562F577E.6000901@oracle.com> <20151029145847.GA10859@netbsd.org> <063D6719AE5E284EB5DD2968C1650D6D1CBC66C8@AcuExch.aculab.com> <20151030210943.GJ22011@ZenIV.linux.org.uk> <063D6719AE5E284EB5DD2968C1650D6D1CBCC02B@AcuExch.aculab.com> <20151104162735.GS22011@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: 8BIT Cc: 'David Holland' , Alan Burlison , "Casper.Dik@oracle.com" , David Miller , "eric.dumazet@gmail.com" , "stephen@networkplumber.org" , "netdev@vger.kernel.org" To: 'Al Viro' Return-path: Received: from smtp-out4.electric.net ([192.162.216.187]:57416 "EHLO smtp-out4.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754484AbbKFPIp convert rfc822-to-8bit (ORCPT ); Fri, 6 Nov 2015 10:08:45 -0500 In-Reply-To: <20151104162735.GS22011@ZenIV.linux.org.uk> Content-Language: en-US Sender: netdev-owner@vger.kernel.org List-ID: From: Al Viro > Sent: 04 November 2015 16:28 > On Wed, Nov 04, 2015 at 03:54:09PM +0000, David Laight wrote: > > > Sigh... The kernel has no idea when other threads are done with "all > > > io activities using that fd" - it can wait for them to leave the > > > kernel mode, but there's fuck-all it can do about e.g. a userland > > > loop doing write() until there's more data to send. And no, you can't > > > rely upon them catching EBADF on the next iteration - by the time they > > > get there, close() might very well have returned and open() from yet > > > another thread might've grabbed the same descriptor. Welcome to your > > > data being written to hell knows what... > > > > That just means that the application must use dup2() rather than close(). > > It must do that anyway since the thread it is trying to stop might be > > sleeping in the system call stub in libc at the time a close() and open() > > happen. > > Oh, _lovely_. So instead of continuation of that write(2) going down > the throat of something opened by unrelated thread, it (starting from a > pretty arbitrary point) will go into the descriptor the closing thread > passed to dup2(). Until it, in turn, gets closed, at which point we > are back to square one. That, of course, makes it so much better - > whatever had I been thinking about that made me miss that? Do I detect a note of sarcasm. You'd open "/dev/null" (lacking a "/dev/error") and use that as the source fd. So any writes (etc) would be discarded in a safe manner, and nothing will block. David