diff options
Diffstat (limited to 'winsup')
-rw-r--r-- | winsup/cygwin/ChangeLog | 13 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.cc | 5 | ||||
-rw-r--r-- | winsup/cygwin/fhandler.h | 4 | ||||
-rw-r--r-- | winsup/cygwin/fhandler_fifo.cc | 41 | ||||
-rw-r--r-- | winsup/cygwin/pinfo.cc | 1 | ||||
-rw-r--r-- | winsup/cygwin/pipe.cc | 89 | ||||
-rw-r--r-- | winsup/cygwin/strace.cc | 4 |
7 files changed, 77 insertions, 80 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index ee3c3fb..93d0829 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,16 @@ +2005-04-22 Christopher Faylor <cgf@timesys.com> + + * fhandler.cc (fhandler_base::read): Remove unused signal state tweaks. + * fhandler.h (fhandler_pipe::create_selectable): Declare. + (fhandler_fifo::close_one_end): Declare. + * fhandler_fifo.cc (fhandler_fifo::close_one_end): Define. + (fhandler_fifo::open_not_mine): Use close_one_end to close appropriate + end of pipe. + * pinfo.cc (_pinfo::commune_recv): Ditto. + * pipe.cc (fhandler_pipe::create_selectable): Rename from + create_selectable_pipe. Reorganize. + (fhandler_pipe::create): Use create_selectable. + 2005-04-21 Christopher Faylor <cgf@timesys.com> * shared.cc (shared_info::initialize): Test previous version of shared diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc index d84aeb5..e2d0344 100644 --- a/winsup/cygwin/fhandler.cc +++ b/winsup/cygwin/fhandler.cc @@ -699,7 +699,6 @@ fhandler_base::read (void *in_ptr, size_t& len) { char *ptr = (char *) in_ptr; ssize_t copied_chars = 0; - bool need_signal = !!read_state; int c; while (len) @@ -723,7 +722,6 @@ fhandler_base::read (void *in_ptr, size_t& len) goto out; } - need_signal = false; raw_read (ptr + copied_chars, len); if (!copied_chars) /* nothing */; @@ -792,9 +790,6 @@ fhandler_base::read (void *in_ptr, size_t& len) #endif out: - if (need_signal) - signal_read_state (2); - debug_printf ("returning %d, %s mode", len, rbinary () ? "binary" : "text"); return; } diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h index 7611378..f063f45 100644 --- a/winsup/cygwin/fhandler.h +++ b/winsup/cygwin/fhandler.h @@ -503,7 +503,8 @@ public: HANDLE get_guard () const {return guard;} int ready_for_read (int fd, DWORD howlong); static int create (fhandler_pipe *[2], unsigned, int, bool = false); - bool is_slow () {return 1;} + bool is_slow () {return true;} + static int create_selectable (LPSECURITY_ATTRIBUTES, HANDLE&, HANDLE&, DWORD, bool); friend class fhandler_fifo; }; @@ -525,6 +526,7 @@ public: void set_use (); int dup (fhandler_base *child); bool is_slow () {return 1;} + void close_one_end (); }; class fhandler_dev_raw: public fhandler_base diff --git a/winsup/cygwin/fhandler_fifo.cc b/winsup/cygwin/fhandler_fifo.cc index b654dc2..42b1851 100644 --- a/winsup/cygwin/fhandler_fifo.cc +++ b/winsup/cygwin/fhandler_fifo.cc @@ -67,14 +67,30 @@ fhandler_fifo::close () } #define DUMMY_O_RDONLY 4 + +void +fhandler_fifo::close_one_end () +{ + int testflags = (get_flags () & (O_RDWR | O_WRONLY | O_APPEND)) ?: DUMMY_O_RDONLY; + static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR}; + HANDLE *handles[2] = {&(get_handle ()), &(get_output_handle ())}; + for (int i = 0; i < 2; i++) + if (!(testflags & flagtypes[i])) + { + CloseHandle (*handles[i]); + *handles[i] = NULL; + } + else if (i == 0 && !read_state) + { + create_read_state (2); + need_fork_fixup (true); + } +} int fhandler_fifo::open_not_mine (int flags) { winpids pids; - static int flagtypes[] = {DUMMY_O_RDONLY | O_RDWR, O_WRONLY | O_APPEND | O_RDWR}; - HANDLE *usehandles[2] = {&(get_handle ()), &(get_output_handle ())}; int res = 0; - int testflags = (flags & (O_RDWR | O_WRONLY | O_APPEND)) ?: DUMMY_O_RDONLY; for (unsigned i = 0; i < pids.npids; i++) { @@ -109,22 +125,11 @@ fhandler_fifo::open_not_mine (int flags) } } - for (int i = 0; i < 2; i++) - if (!(testflags & flagtypes[i])) - CloseHandle (r.handles[i]); - else - { - *usehandles[i] = r.handles[i]; - - if (i == 0) - { - read_state = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL); - need_fork_fixup (true); - } - } - - res = 1; + set_io_handle (r.handles[0]); + set_output_handle (r.handles[1]); set_flags (flags); + close_one_end (); + res = 1; goto out; } diff --git a/winsup/cygwin/pinfo.cc b/winsup/cygwin/pinfo.cc index 79829e3..a0f7c48 100644 --- a/winsup/cygwin/pinfo.cc +++ b/winsup/cygwin/pinfo.cc @@ -611,6 +611,7 @@ _pinfo::commune_recv () break; } debug_printf ("fifo found %p, %p", it[0], it[1]); + fh->close_one_end (); /* FIXME: not quite right - need more handshaking */ } CloseHandle (hp); diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc index aed84e0..0d9c0cd 100644 --- a/winsup/cygwin/pipe.cc +++ b/winsup/cygwin/pipe.cc @@ -318,21 +318,17 @@ leave: FILE_READ_ATTRIBUTES access, on later versions of win32 where this is supported. This access is needed by NtQueryInformationFile, which is used to implement select and nonblocking writes. - Note that the return value is either NO_ERROR or GetLastError, + Note that the return value is either 0 or GetLastError, unlike CreatePipe, which returns a bool for success or failure. */ -static int -create_selectable_pipe (PHANDLE read_pipe_ptr, - PHANDLE write_pipe_ptr, - LPSECURITY_ATTRIBUTES sa_ptr, - DWORD psize) +int +fhandler_pipe::create_selectable (LPSECURITY_ATTRIBUTES sa_ptr, HANDLE& r, + HANDLE& w, DWORD psize, bool fifo) { /* Default to error. */ - *read_pipe_ptr = *write_pipe_ptr = INVALID_HANDLE_VALUE; - - HANDLE read_pipe = INVALID_HANDLE_VALUE, write_pipe = INVALID_HANDLE_VALUE; + r = w = INVALID_HANDLE_VALUE; /* Ensure that there is enough pipe buffer space for atomic writes. */ - if (psize < PIPE_BUF) + if (!fifo && psize < PIPE_BUF) psize = PIPE_BUF; char pipename[CYG_MAX_PATH]; @@ -342,9 +338,9 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, to be as robust as possible. */ while (1) { - static volatile LONG pipe_unique_id; + static volatile ULONG pipe_unique_id; - __small_sprintf (pipename, "\\\\.\\pipe\\cygwin-%d-%ld", myself->pid, + __small_sprintf (pipename, "\\\\.\\pipe\\cygwin-%p-%p", myself->pid, InterlockedIncrement ((LONG *) &pipe_unique_id)); debug_printf ("CreateNamedPipe: name %s, size %lu", pipename, psize); @@ -358,84 +354,67 @@ create_selectable_pipe (PHANDLE read_pipe_ptr, the pipe was not created earlier by some other process, even if the pid has been reused. We avoid FILE_FLAG_FIRST_PIPE_INSTANCE because that is only available for Win2k SP2 and WinXP. */ - SetLastError (0); - read_pipe = CreateNamedPipe (pipename, - PIPE_ACCESS_INBOUND, - PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, - 1, /* max instances */ - psize, /* output buffer size */ - psize, /* input buffer size */ - NMPWAIT_USE_DEFAULT_WAIT, - sa_ptr); + r = CreateNamedPipe (pipename, PIPE_ACCESS_INBOUND, + PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1, psize, + psize, NMPWAIT_USE_DEFAULT_WAIT, sa_ptr); - DWORD err = GetLastError (); /* Win 95 seems to return NULL instead of INVALID_HANDLE_VALUE */ - if ((read_pipe || !err) && read_pipe != INVALID_HANDLE_VALUE) + if (r && r != INVALID_HANDLE_VALUE) { - debug_printf ("pipe read handle %p", read_pipe); + debug_printf ("pipe read handle %p", r); break; } + DWORD err = GetLastError (); switch (err) { case ERROR_PIPE_BUSY: /* The pipe is already open with compatible parameters. Pick a new name and retry. */ debug_printf ("pipe busy, retrying"); - continue; + break; case ERROR_ACCESS_DENIED: /* The pipe is already open with incompatible parameters. Pick a new name and retry. */ debug_printf ("pipe access denied, retrying"); - continue; - case ERROR_CALL_NOT_IMPLEMENTED: - /* We are on an older Win9x platform without named pipes. - Return an anonymous pipe as the best approximation. */ - debug_printf ("CreateNamedPipe not implemented, resorting to " - "CreatePipe size %lu", psize); - if (CreatePipe (read_pipe_ptr, write_pipe_ptr, sa_ptr, psize)) + break; + default: + /* CreateNamePipe failed. Maybe we are on an older Win9x platform without + named pipes. Return an anonymous pipe as the best approximation. */ + debug_printf ("CreateNamedPipe failed, resorting to CreatePipe size %lu", + psize); + if (CreatePipe (&r, &w, sa_ptr, psize)) { - debug_printf ("pipe read handle %p", *read_pipe_ptr); - debug_printf ("pipe write handle %p", *write_pipe_ptr); - return NO_ERROR; + debug_printf ("pipe read handle %p", r); + debug_printf ("pipe write handle %p", w); + return 0; } err = GetLastError (); debug_printf ("CreatePipe failed, %E"); return err; - default: - debug_printf ("CreateNamedPipe failed, %E"); - return err; } - /* NOTREACHED */ } debug_printf ("CreateFile: name %s", pipename); /* Open the named pipe for writing. Be sure to permit FILE_READ_ATTRIBUTES access. */ - write_pipe = CreateFile (pipename, - GENERIC_WRITE | FILE_READ_ATTRIBUTES, - 0, /* share mode */ - sa_ptr, - OPEN_EXISTING, - 0, /* flags and attributes */ - 0); /* handle to template file */ - - if (write_pipe == INVALID_HANDLE_VALUE) + w = CreateFile (pipename, GENERIC_WRITE | FILE_READ_ATTRIBUTES, 0, sa_ptr, + OPEN_EXISTING, 0, 0); + + if (!w || w == INVALID_HANDLE_VALUE) { /* Failure. */ DWORD err = GetLastError (); debug_printf ("CreateFile failed, %E"); - CloseHandle (read_pipe); + CloseHandle (r); return err; } - debug_printf ("pipe write handle %p", write_pipe); + debug_printf ("pipe write handle %p", w); /* Success. */ - *read_pipe_ptr = read_pipe; - *write_pipe_ptr = write_pipe; - return NO_ERROR; + return 0; } int @@ -444,9 +423,9 @@ fhandler_pipe::create (fhandler_pipe *fhs[2], unsigned psize, int mode, bool fif HANDLE r, w; SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none; int res = -1; - int ret; - if ((ret = create_selectable_pipe (&r, &w, sa, psize)) != NO_ERROR) + int ret = create_selectable (sa, r, w, psize, fifo); + if (ret) __seterrno_from_win_error (ret); else { diff --git a/winsup/cygwin/strace.cc b/winsup/cygwin/strace.cc index 1a73e3d..8716cce 100644 --- a/winsup/cygwin/strace.cc +++ b/winsup/cygwin/strace.cc @@ -54,7 +54,9 @@ strace::hello () if (active) { prntf (1, NULL, "**********************************************"); - prntf (1, NULL, "Program name: %s (%d)", myself->progname, myself->pid ?: GetCurrentProcessId ()); + prntf (1, NULL, "Program name: %s (pid %d, ppid %d)", myself->progname, + myself->pid ?: GetCurrentProcessId (), + myself->ppid ?: 1); prntf (1, NULL, "App version: %d.%d, api: %d.%d", user_data->dll_major, user_data->dll_minor, user_data->api_major, user_data->api_minor); |