<div dir="ltr">Thanks for all the great input. I'm an experienced developer but a newbie at wine dev, so the input is greatly appreciated. <div><br></div><div>I'll take a stab at iterating on Bruno's last patch to leverage the server's handles. </div><div>-Matt</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 2, 2015 at 11:13 AM, Bruno Jesus <span dir="ltr"><<a href="mailto:00cpxxx@gmail.com" target="_blank">00cpxxx@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all and sorry, replying from mobile phone so I can't quote things right.<div><br></div><div>There are a few tests covering this so any patch fixing this problem will require reviewing the tests too.</div><div><br></div><div>I tried to fix this last year, the discussion and patch can be found at [1]. There is also a real bug related to this problem (18670 and 26031).</div><div><br></div><div>1- <a href="http://marc.info/?t=138834097400003&r=1&w=2" target="_blank">http://marc.info/?t=138834097400003&r=1&w=2</a></div><div><br></div><div>Best wishes, </div><span class="HOEnZb"><font color="#888888"><div>Bruno</div></font></span><div class="HOEnZb"><div class="h5"><div><br></div><div><div>On Sunday, August 2, 2015, Charles Davis <<a href="mailto:cdavis5x@gmail.com" target="_blank">cdavis5x@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On Jul 31, 2015, at 11:31 PM, Ken Thomases <<a>ken@codeweavers.com</a>> wrote:<br>
><br>
> Hi,<br>
><br>
> Thanks for contributing to Wine.  I've commented on the patch in-line below:<br>
><br>
> On Jul 31, 2015, at 10:19 PM, Matt Durgavich <<a>mattdurgavich@gmail.com</a>> wrote:<br>
><br>
>> +static void close_open_sockets() {<br>
>> +#ifdef HAVE_LIBPROC_H<br>
>> +    int pid = getpid();<br>
>> +    int bufferSizeNeeded = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);<br>
><br>
> This function isn't documented and the header which declares it says it's SPI rather than API and can change at any time.<br>
Well then, we’re kinda screwed if they do change it, because we already use that SPI. (In fact, it’s my fault. ;) In particular, we use it in iphlpapi to figure out which process owns a particular socket. (@Matt: this also means the check for <libproc.h> you added to <a href="http://configure.ac" target="_blank">configure.ac</a> is redundant, because we already check for it. You can delete it.)<br>
><br>
> Also, is this the right approach generally?  This is going to close all Unix sockets opened by the process, not just Win32 sockets opened by ws2_32.<br>
It won’t even (properly) close all (or any, really) of the winsock sockets. That’s because winsock sockets in Wine, like on NT, are NT-style object handles. That’s really what you have to find and close. Also, even if you try to map the FDs back to their corresponding Wine handles, you still won’t necessarily get them all, because the wineserver manages FDs (including sockets, I believe) on Wine’s behalf; they’re only present in the process if Wine bothers to go to the wineserver to get them (cf. dlls/ntdll/server.c).<br>
<br>
So, I suggest enumerating all the socket handles in the process (e.g. by enumerating all handles in this process using toolhelp or psapi, then filtering out the ones that aren’t sockets), and closing those. Or, maybe, having winsock keep track of sockets that it opens (e.g. returned from WSASocket()), then having WSACleanup() close all the ones it knows about. The great thing about doing it either of these ways is that it’ll work elsewhere, too—not just on Mac OS. The second option I gave might be preferable, because e.g. someone could DuplicateHandle() a winsock handle into another process, and WSACleanup() might not close it when it runs. (Someone should write a test for that.)<br>
>   Is it safe/proper for WSACleanup to close sockets that it didn't open?  Isn't it possible that other parts of Wine could open Unix sockets for other reasons?<br>
It is, and in fact, they do. For one thing, Wine programs use Unix-domain (PF_UNIX) sockets to talk to wineserver.<br>
<br>
Chip<br>
<br>
<br>
<br>
</blockquote></div></div>
</div></div></blockquote></div><br></div>