mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-02-02 12:30:24 +08:00
81ceb96528
When a process sends a file descriptor via an SCM_RIGHTS control message, it creates a temporary copy of the fhandler associated with that descriptor and sends a serialization of that copy. The deserialization done by the receiver involves duplicating handles from the copy, so the latter must stay alive until the deserialization is done. But it must ultimately be closed in order to avoid a memory leak. We coordinate all this as follows: - Introduce a new struct scm_pending_fd that contains information about the temporary copy. For brevity, call such a struct a "pending fd" in what follows. - Maintain a list of pending fds in shared memory. - Add several methods for manipulating the list to the af_unix_shmem_t and fhandler_socket_unix classes. - Also add a lock, 'scm_fd_lock', to control access to the list. - When a serialized fhandler is received, the receiver sends an ack back to the sender in an administrative packet with a control message of a new (Cygwin-specific) type SCM_RIGHTS_ACK. - grab_admin_pkt is called in various places to process these packets. A complication here is that the process that calls grab_admin_pkt might not be the process that originally sent the serialized fhandler. (It could be a subprocess of the original process, for example.) This is why we need to maintain the list of pending fds in shared memory. - Each fhandler_socket_unix keeps a count of the pending fds that it has created but not yet processed; this count is in a new data member 'my_npending_fd'. - fhandler_socket_unix::close tries to process any remaining pending fds before closing, but it gives up after a short timeout and forcibly deletes them if necessary.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cygwin documentation is available on the net at https://cygwin.com You might especially be interested in https://cygwin.com/faq/faq.html#faq.programming.building-cygwin