diff options
author | Christopher Faylor <me@cgf.cx> | 2007-12-16 21:21:23 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2007-12-16 21:21:23 +0000 |
commit | 634a41403c1439e1c6f3ee4252cf5a091bcc6921 (patch) | |
tree | 5e21dbc7f97ec39c0dc988b2e00de45ff6348fa2 /winsup/cygwin/dtable.cc | |
parent | 68adeb7cdee53b09835d35ee43948c5d1b330fcd (diff) | |
download | cygnal-634a41403c1439e1c6f3ee4252cf5a091bcc6921.tar.gz cygnal-634a41403c1439e1c6f3ee4252cf5a091bcc6921.tar.bz2 cygnal-634a41403c1439e1c6f3ee4252cf5a091bcc6921.zip |
* dtable.cc (POSIX_NAMED_PIPE): New define.
(POSIX_NAMED_PIPE_LEN): Ditto.
(dtable::add_archetype): Use crealloc_abort.
(dtable::init_std_file_from_handle): Specifically detect pipe stdin/stdout.
Pass name to build_fh_dev so that proper name is recorded. Use binmode of fh
if it is set before using get_default_mode. Set proper read/write access when
calling init().
(handle_to_fn): Handle pipes.
* fhandler.cc (fhandler_base::wait_overlapped): Add some debugging.
* fhandler.h (fhandler_base::set_name): Default to just setting the path_conv
name.
(fhandler_pipe::init): Declare.
* pipe.cc (struct pipesync): New struct.
(getov_result): New function. Blocks and retrieves the result of an overlay
I/O operation.
(pipe_handler): New function.
(pipesync::pipesync): New function. Initializer for pipesync struct.
(handler_pipe::init): Define. Detects attempts to set up a "native" pipe
fhandler and creates a thread which accepts input from or output to the
non-cygwin pipe, creating a cygwin pipe wrapper around the non-cygwin pipe.
(fhandler_pipe::create): Add pipe-specific flags to call to init().
* exceptions.cc (ctrl_c_handler): Lock process while we determine what to do.
Diffstat (limited to 'winsup/cygwin/dtable.cc')
-rw-r--r-- | winsup/cygwin/dtable.cc | 86 |
1 files changed, 60 insertions, 26 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc index 575384650..6fcf7086e 100644 --- a/winsup/cygwin/dtable.cc +++ b/winsup/cygwin/dtable.cc @@ -41,6 +41,17 @@ static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, static const char *handle_to_fn (HANDLE, char *); +#define DEVICE_PREFIX "\\device\\" +#define DEVICE_PREFIX_LEN sizeof (DEVICE_PREFIX) - 1 +#define REMOTE "\\Device\\LanmanRedirector\\" +#define REMOTE_LEN sizeof (REMOTE) - 1 +#define REMOTE1 "\\Device\\WinDfs\\Root\\" +#define REMOTE1_LEN sizeof (REMOTE1) - 1 +#define NAMED_PIPE "\\Device\\NamedPipe\\" +#define NAMED_PIPE_LEN sizeof (NAMED_PIPE) - 1 +#define POSIX_NAMED_PIPE "/Device/NamedPipe/" +#define POSIX_NAMED_PIPE_LEN sizeof (POSIX_NAMED_PIPE) - 1 + /* Set aside space for the table of fds */ void dtable_init () @@ -187,7 +198,7 @@ fhandler_base ** dtable::add_archetype () { if (farchetype++ >= narchetypes) - archetypes = (fhandler_base **) crealloc (archetypes, (narchetypes += initial_archetype_size) * sizeof archetypes[0]); + archetypes = (fhandler_base **) crealloc_abort (archetypes, (narchetypes += initial_archetype_size) * sizeof archetypes[0]); return archetypes + farchetype - 1; } @@ -283,13 +294,6 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) else dev = *console_dev; } - else if (ft == FILE_TYPE_PIPE) - { - if (fd == 0) - dev = *piper_dev; - else - dev = *pipew_dev; - } else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0) dev = *tcp_dev; else if (GetCommState (handle, &dcb)) @@ -297,7 +301,12 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) else { name = handle_to_fn (handle, (char *) alloca (CYG_MAX_PATH + 100)); - bin = 0; + if (!strncasematch (name, POSIX_NAMED_PIPE, POSIX_NAMED_PIPE_LEN)) + /* nothing */; + else if (fd == 0) + dev = *piper_dev; + else + dev = *pipew_dev; } } @@ -308,25 +317,31 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle) fhandler_base *fh; if (dev) - fh = build_fh_dev (dev); + fh = build_fh_dev (dev, name); else fh = build_fh_name (name); if (fh) cygheap->fdtab[fd] = fh; - if (!bin) + if (name) { - bin = fh->get_default_fmode (O_RDWR); - if (bin) - /* nothing */; - else if (dev) - bin = O_BINARY; - else if (name != unknown_file) - bin = fh->pc_binmode (); + bin = fh->pc_binmode (); + if (!bin) + { + bin = fh->get_default_fmode (O_RDWR); + if (!bin && dev) + bin = O_BINARY; + } } - fh->init (handle, GENERIC_READ | GENERIC_WRITE, bin); + DWORD access; + if (fd == 0) + access = GENERIC_READ; + else + access = GENERIC_WRITE; /* Should be rdwr for stderr but not sure that's + possible for some versions of handles */ + fh->init (handle, access, bin); set_std_handle (fd); paranoid_printf ("fd %d, handle %p", fd, handle); } @@ -824,11 +839,6 @@ dtable::vfork_child_fixup () } #endif /*NEWVFORK*/ -#define DEVICE_PREFIX "\\device\\" -#define DEVICE_PREFIX_LEN sizeof (DEVICE_PREFIX) - 1 -#define REMOTE "\\Device\\LanmanRedirector\\" -#define REMOTE_LEN sizeof (REMOTE) - 1 - static const char * handle_to_fn (HANDLE h, char *posix_fn) { @@ -900,6 +910,7 @@ handle_to_fn (HANDLE h, char *posix_fn) } char *w32 = win32_fn; + bool justslash = false; if (maxmatchlen) { n = strlen (maxmatchdos); @@ -909,15 +920,38 @@ handle_to_fn (HANDLE h, char *posix_fn) memcpy (w32, maxmatchdos, n); w32[n] = '\\'; } + else if (strncasematch (w32, NAMED_PIPE, NAMED_PIPE_LEN)) + { + debug_printf ("pipe"); + justslash = true; + } else if (strncasematch (w32, REMOTE, REMOTE_LEN)) { w32 += REMOTE_LEN - 2; *w32 = '\\'; debug_printf ("remote drive"); + justslash = true; + } + else if (strncasematch (w32, REMOTE1, REMOTE1_LEN)) + { + w32 += REMOTE1_LEN - 2; + *w32 = '\\'; + debug_printf ("remote drive"); + justslash = true; } + if (!justslash) + cygwin_conv_to_full_posix_path (w32, posix_fn); + else + { + char *s, *d; + for (s = w32, d = posix_fn; *s; s++, d++) + if (*s == '\\') + *d = '/'; + else + *d = *s; + } - debug_printf ("derived path '%s'", w32); - cygwin_conv_to_full_posix_path (w32, posix_fn); + debug_printf ("derived path '%s', posix '%s'", w32, posix_fn); return posix_fn; } |