This is the mail archive of the
cygwin-developers
mailing list for the Cygwin project.
improve cygwin_attach_handle_to_fd()
- From: Basin Ilya <basinilya at gmail dot com>
- To: cygwin-developers at cygwin dot com
- Date: Thu, 1 Oct 2015 12:52:57 +0300
- Subject: improve cygwin_attach_handle_to_fd()
- Authentication-results: sourceware.org; auth=none
Hi All.
There's undocumented function cygwin_attach_handle_to_fd() , which is
similar to Visual C _open_osfhandle() for wrapping Windows file handles.
I wanted to wrap a handle returned by CreateNamedPipe() using a custom
tool running in background and then dup the fd to parent shell using
exec 4</proc/$!/fd/4
I knew Cygwin internally used CreateNamedPipe() instead of CreatePipe()
and hoped the idea would work. Unfortunately it didn't, mainly because
cygwin_attach_handle_to_fd() calls some other windows functions on the
handle, which is fine for normal files, but makes a connected pipe unusable.
Also for stealing a pipe handle via procfs, the fd should have a special
name like "pipe:[652]". You cannot freely choose the name with
cygwin_attach_handle_to_fd()
Do you think it is possible to add another function for wrapping native
pipes and sockets? It could be less destructive for a hanlde, if it took
all the needed info from its parameters instead of querying the hanlde.