Commit Graph

89 Commits

Author SHA1 Message Date
Ken Brown 440559c40a Cygwin: FIFO: synchronize the blocking mode of a writer's pipe
The blocking mode of the Windows pipe underlying a writer is set to
match that of the writer itself when the latter is opened.  Define
fhandler_fifo::fcntl to keep the pipe and the writer in sync if the
blocking mode is changed via fcntl.
2019-04-26 07:45:37 -04:00
Ken Brown 9957a7895b Cygwin: FIFO: restart listen_client thread after fork/exec
This allows writers to connect immediately.  Previously the lct wasn't
restarted until the reader attempted to read.
2019-04-22 07:55:58 -04:00
Ken Brown 4443100b53 Cygwin: FIFO: stop the listen_client thread before fork/exec
Add methods need_fixup_before, init_fixup_before, and
fixup_before_fork_exec to accomplish this.  Stopping the thread makes
sure that the client handler lists of the parent and child remain in
sync while the forking/execing is in progress.
2019-04-20 14:31:07 -04:00
Ken Brown 252cd0ce2b Cygwin: FIFO: close connect_evt handles as soon as possible
Keeping them open too long can cause an attempt to close them twice
after a fork or exec.
2019-04-20 14:31:07 -04:00
Ken Brown 24c56e5a2c Cygwin: FIFO: avoid WFMO error in listen_client_thread
Don't set lct_termination_evt to NULL too early in
fhandler_fifo::stop_listen_client.  Doing so leads to an "Invalid
Handle" error in WFMO.
2019-04-20 14:31:07 -04:00
Ken Brown ef269531a9 Cygwin: FIFO: duplicate the i/o handle when opening a duplexer
Don't use the same i/o handle for the first client handler as is used
for the fhandler itself; this can lead to a later attempt to close the
same handle twice.  Instead use a duplicate.
2019-04-20 14:31:07 -04:00
Ken Brown 4ecea14a58 Cygwin: FIFO: stop the listen_client thread on an opening error
Don't just close the thread handle.
2019-04-20 14:31:07 -04:00
Ken Brown 230c5df2df Cygwin: FIFO: avoid hang after exec
Define fhandler:fifo::fixup_after_exec, which sets listen_client_thr
and lct_termination_evt to NULL.  This forces the listen_client thread
to restart on the first attempt to read after an exec.  Previously the
exec'd process could hang in fhandler_fifo::raw_read.
2019-04-18 19:34:07 +02:00
Ken Brown 2b4cf7622e Cygwin: FIFO: fix and simplify listen_client_thread
Remove fifo_client_handler::connect and move its code into
listen_client_thread.  That way we can check the return status when a
client handler's connect_evt is signaled.  Previously we incorrectly
assumed there was a successful connection.

Also simplify listen_client_thread in the following ways:

- Replace fhandler_fifo::disconnect_and_reconnect by a new
  delete_client_handler method.  Now we just delete invalid client
  handlers rather than trying to re-use them.

- Try to maintain a client handler list that consists of connected
  client handlers and exactly one that is listening for a connection.
  This allows us to call WaitForMultipleObjects with only two wait
  objects.

- Remove 'dummy_evt' from the fifo_client_handler struct; it is no
  longer needed.

- On exit from listen_client_thread, delete the "extra" (listening)
  client handler.  Otherwise there could be a connection that doesn't
  get recorded in the client handler list.  This could happen when a
  file descriptor is being duplicated.
2019-04-16 12:54:43 +02:00
Ken Brown bb46627871 Cygwin: FIFO: improve raw_write
Don't set the write end of the pipe to non-blocking mode if the FIFO
is opened in blocking mode.

In fhandler_fifo::raw_write in blocking mode, wait for the write to
complete rather than returning -1 with EAGAIN.

If the amount to write is large, write in smaller chunks (of size
determined by a new data member max_atomic_write), as in
fhandler_base_overlapped.

For convenience, add two new NTSTATUS codes, STATUS_THREAD_SIGNALED
and STATUS_THREAD_CANCELED, to ntdll.h.
2019-04-16 12:54:43 +02:00
Ken Brown a7d08b3ecd Cygwin: FIFO: start the listen_client thread when duping a reader
Otherwise it doesn't get started until the dup'd fd tries to read,
which delays client connections.
2019-04-16 12:54:43 +02:00
Ken Brown 7b28776d3f Cygwin: FIFO: fix clone
After copyto is called, make the new fhandler's pipe_name point to the
new fhandler's pipe_name_buf, which is a *copy* of the old fhandler's
pipe_name_buf.  Previously, get_pipe_name would return the wrong
result after a clone/dup, causing create_pipe_instance and open_pipe
to fail.

Also, stop the listen_client thread when cloning.  Otherwise the
thread can keep accepting connections that the cloned fhandler won't
know about.

Do this via a new method fhandler_fifo::stop_listen_client, extracted
from fhandler_fifo::close.
2019-04-16 12:54:43 +02:00
Ken Brown c5bc7a8065 Cygwin: FIFO: use a retry loop when opening a writer
There may be short periods when there's no pipe instance available.
Keep trying.
2019-04-16 12:54:43 +02:00
Ken Brown 6b20be0944 Cygwin: FIFO: fix the use of the read_ready event
Make read_ready a manual reset event.  It should always be set shortly
after startup of the listen_client thread and remain set until the
thread terminates.  (We don't want writers to connect without being
recorded in the client handler list.)

Remove the unnecessary code that checks for read_ready when a reader
is opening.
2019-04-16 12:54:43 +02:00
Ken Brown 3ef03376c5 Cygwin: FIFO: fix fifo_client_handler::close
Make sure that fhandler_base::close rather than fhandler_fifo::close
is called on the fhandler.  Also, delete the fhandler, since we
allocated it.
2019-04-16 12:54:43 +02:00
Ken Brown 513f050cbf Cygwin: FIFO: fix the error checking in raw_read
If the pipe is empty, we can get either ERROR_NO_DATA or
ERROR_PIPE_LISTENING.
2019-04-16 12:54:43 +02:00
Ken Brown 0c72e766e2 Cygwin: FIFO: fix a thinko in listen_client_thread 2019-04-16 12:54:43 +02:00
Ken Brown 1643789517 Cygwin: FIFO: remember the type of the fhandler
Add data members 'reader', 'writer', and 'duplexer' to the
fhandler_fifo class.  Set them in fhandler_fifo::open.  ('duplexer'
replaces the previous '_duplexer'.)

This will be useful in later commits.
2019-04-16 12:54:43 +02:00
Ken Brown 5281699926 Cygwin: FIFO: hit_eof: add a call to fifo_client_lock
The second check of nconnected needs to be protected by a lock as well
as the first.
2019-04-16 12:54:43 +02:00
Ken Brown b63843ed56 Cygwin: FIFO: rename client[] to fc_handler[]
The word "client" suggests something that holds a handle to the client
side of the pipe (in Windows terminology).  But our
fifo_client_handlers hold a handle the server side of the pipe, and
they *connect* to clients.
2019-04-16 12:54:43 +02:00
Takashi Yano a9c661a94d Cygwin: [gs]et_io_handle(): renamed to [gs]et_handle().
- Unify get_io_handle() and get_handle() to get_handle().
  Both of them returned same value; io_handle.
- Rename set_io_handle() to set_handle().
2019-03-30 20:08:36 +01:00
Ken Brown a137da74ba Cygwin: FIFO: add support for the duplex case
If a FIFO is opened with O_RDWR access, create the pipe with
read/write access, and make the first client have the handle of that
pipe as its I/O handle.

Adjust fhandler_fifo::raw_read to account for the result of trying to
read from that client if there's no data.
2019-03-27 14:01:45 +01:00
Ken Brown 1aa438a94c Cygwin: FIFO: update set_close_on_exec
Deal with each client.
2019-03-27 14:01:45 +01:00
Ken Brown e02a0f7295 Cygwin: FIFO: update fixup_after_fork
Fixup each client.  Reset listen_client_thr and lct_termination_evt.
2019-03-27 14:01:45 +01:00
Ken Brown 035bf7dc84 Cygwin: FIFO: update clone and dup
Deal with all clients.
2019-03-27 14:01:45 +01:00
Ken Brown c6e221c036 Cygwin: FIFO: improve EOF detection
Add a hit_eof method that tries to detect whether any clients are
connected.  Before concluding that there are none, it gives the
listen_client thread time to update the client data.
2019-03-27 14:01:45 +01:00
Ken Brown c75e077f99 Cygwin: FIFO: add a spinlock
Don't let listen_client_thread and raw_read access the client list
simultaneously.
2019-03-27 14:01:45 +01:00
Ken Brown 48d4cce3be Cygwin: FIFO: allow multiple writers
Introduce a 'fifo_client_handler' structure that can be used by a
reader to communicate with a writer using an instance of the named
pipe.  An fhandler_fifo opened for reading creates a thread that does
the following:

 - maintains a list of fifo_client_handlers
 - listens for_clients trying to connect
 - creates new pipe instances as needed so that there's always at
   least one available for connecting.

The pipe instances are initially created in blocking mode, but they
are set to be non-blocking after a connection is made.

fhandler_fifo::raw_read now loops through the connected clients and
reads from the first one that has data available.

New fhandler_fifo methods: add_client, listen_client,
listen_client_thread, check_listen_client_thread.

Replace the create_pipe method by create_pipe_instance, which allows
unlimited pipe instances.

New helper functions: create_event, set_pipe_non_blocking.
2019-03-27 14:01:45 +01:00
Ken Brown 5955da96e2 Cygwin: FIFO: stop using overlapped I/O
Make fhandler_fifo a derived class of fhandler_base instead of
fhandler_base_overlapped.

Replace the create_pipe macro, which is based on
fhandler_pipe::create, by new create_pipe and open_pipe methods.
These use NT functions instead of Win32 functions.  Replace fifo_name
by get_pipe_name, which returns a pointer to a UNICODE_STRING.

Remove the fnevent macro, which would now be needed only once.

Add a raw_write method, adapted from fhandler_base::raw_write.

Adapt all functions to the changes above.
2019-03-27 14:01:45 +01:00
Corinna Vinschen 323b48b975 Cygwin: lseek: return ESPIPE rather than EINVAL when called on a fifo
Thanks to Henri for tracking this down:
https://cygwin.com/ml/cygwin/2018-10/msg00062.html

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2018-10-10 13:20:45 +02:00
Corinna Vinschen 6e623e9320 Switching the Cygwin DLL to LGPLv3+, dropping commercial buyout option
Bump GPLv2+ to GPLv3+ for some files, clarify BSD 2-clause.

Everything else stays under GPLv3+.

New Linking Exception exempts resulting executables from LGPLv3 section 4.

Add CONTRIBUTORS file to keep track of licensing.

Remove 'Copyright Red Hat Inc' comments.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2016-06-23 10:09:17 +02:00
Yaakov Selkowitz 1f36328e7f Throughout, (mainly in fhandler*) fix remaining gcc 4.7 mismatch
warnings between regparm definitions and declarations.
* smallprint.cc (__small_vswprintf): Conditionalize declaration and
setting of l_opt for only x86_64.
* spawn.cc (child_info_spawn::worker): Remove unused 'pid' variable.
* thread.cc (verifyable_object_isvalid): Temporarily define as
non-inline with gcc 4.7+, regardless of target.
2013-05-01 01:20:37 +00:00
Corinna Vinschen 61522196c7 * Merge in cygwin-64bit-branch. 2013-04-23 09:44:36 +00:00
Christopher Faylor 6e75c72b89 Throughout, change __attribute__ ((regparm (N))) to just __regN. Throughout,
(mainly in fhandler*) start fixing gcc 4.7.2 mismatch between regparm
definitions and declarations.
* gendef: Define some functions to take @ declaration to accommodate _regN
defines which use __stdcall.
* gentls_offsets: Define __regN macros as empty.
* autoload.cc (wsock_init): Remove unneeded regparm attribute.
* winsup.h (__reg1): Define.
(__reg2): Define.
(__reg3): Define.
* advapi32.cc (DuplicateTokenEx): Coerce some initializers to avoid warnings
from gcc 4.7.2.
* exceptions.cc (status_info): Declare struct to use NTSTATUS.
(cygwin_exception::dump_exception): Coerce e->ExceptionCode to NTSTATUS.
* fhandler_clipboard.cc (cygnativeformat): Redefine as UINT to avoid gcc 4.7.2
warnings.
(fhandler_dev_clipboard::read): Ditto.
2013-01-21 04:34:52 +00:00
Christopher Faylor ff8ba3cabe * exceptions.cc (sigpacket::process): Reorganize to avoid use of tls before
initialization.
* fhandler_fifo.cc (fhandler_fifo::arm): Avoid improper printing of integer as
a string in debug output.
2012-12-07 20:59:44 +00:00
Christopher Faylor 4ae6378382 Add '#include "cygwait.h"' throughout, where appropriate.
* DevNotes: Add entry cgf-000012.
* Makefile.in (DLL_OFILES): Add cygwait.o.
* sigproc.h: Remove cygwait definitions.
* cygwait.h: New file.  Define/declare Cygwin waitfor functions.
* cygwait.cc: Ditto.
* exceptions.cc: Include cygwait.h.
(handle_sigsuspend): Accommodate change in cancelable_wait arguments.
(sigpacket::process): Display thread tls in debugging output.
* fhandler.cc (fhandler_base_overlapped::wait_overlapped): Use symbolic names
for signal and cancel return.
* fhandler_console.cc (fhandler_console::read): Ditto.
(fhandler_dev_dsp::Audio_out::waitforspace): Ditto.
fhandler_dev_dsp::Audio_in::waitfordata): Ditto.
* fhandler_fifo.cc (fhandler_fifo::wait): Ditto.
* fhandler_serial.cc (fhandler_serial::raw_read): Ditto.
* fhandler_tty.cc (fhandler_pty_slave::read): Ditto.
* select.cc (cygwin_select): Ditto.
* wait.cc (wait4): Ditto.
* thread.cc (cancelable_wait): Move definition to cygwait.h.
(pthread_cond::wait): Accommodate change in cancelable_wait arguments.
(pthread_mutex::lock): Ditto.
(pthread_spinlock::lock): Ditto.
(pthread::join): Ditto.
(pthread::thread_init_wrapper): Display tls in debugging output.
(semaphore::_timedwait): Ditto.
* thread.h (cw_sig_wait): Move to cygwait.h.
(cw_cancel_action): Delete.
(cancelable_wait): Move declaration to cygwait.h.
2012-06-17 20:50:24 +00:00
Christopher Faylor 1ad58ee709 * fhandler.h (fhandler_fifo::arm): Declare new function.
* fhandler_fifo.cc (fhandler_fifo::arm): Define new function.
(fhandler_fifo::open): Fix handling of RDWR pipes to avoid opening a second
handle.  Use arm() function to set events.
(fhandler_fifo::raw_read): Correctly go into "connect again logic" when we
detect another writer is available.  Use arm() function to set event.
* pipe.cc (fhandler_pipe::create): Add more detail to debugging output.
2012-01-22 21:43:25 +00:00
Christopher Faylor 57af01797e Rename cygWFMO to cygwait throughout and use the magic of polymorphism to "wait
for stuff".
* fhandler.cc (fhandler_base_overlapped::wait_overlapped): Use simplified arg
form of cygwait.
* fhandler_console.cc (fhandler_console::read): Ditto.
* fhandler_audio.cc (fhandler_dev_dsp::Audio_out::waitforspac): Ditto.
(fhandler_dev_dsp::Audio_in::waitfordata): Ditto.
* fhandler_fifo.cc (fhandler_fifo::wait): Ditto.
* fhandler_serial.cc (fhandler_serial::raw_read): Ditto.
(fhandler_serial::raw_write): Ditto.
* select.cc (cygwin_select): Ditto.
* sigproc.h (cygwait): Rename from cygWFMO.  Define two argument and single
argument forms of this function.
* fhandler_tty.cc (fhandler_pty_slave::open): Use method to query if tty is
open.
(fhandler_pty_slave::read): Send SIGHUP when master is detected as closed.
(fhandler_pty_common::close): Close input_available_event in callers since
master may need to signal it first.
(fhandler_pty_master::close): Lie and set input_available_event when closing,
then close input_available_event.
(fhandler_pty_slave::close): Close input_available_event explicitly here.
* tty.h (tty::is_master_closed): Declare new method.
2011-12-09 16:02:56 +00:00
Christopher Faylor 9bab9bfeb5 * fhandler_fifo.cc (fhandler_fifo::wait): Fix stupid typo and actually wait for
the handle.
2011-12-07 03:07:25 +00:00
Christopher Faylor 79e59d522a * sigproc.cc (cygWFMO): Don't assume that cancellable event is always
available.
* fhandler_dsp.cc (fhandler_dev_dsp::Audio_out::waitforspace): Use cygWFMO
instead of WaitForMultipleObjects.
(fhandler_dev_dsp::Audio_in::waitfordata): Ditto.
* fhandler_fifo.cc (fhandler_fifo::wait): Ditto.
* fhandler_serial.cc (fhandler_serial::raw_read): Ditto.
(fhandler_serial::raw_write): Ditto.
* fhandler_tty.cc (fhandler_pty_slave::read): Ditto.
* select.cc (cygwin_select): Ditto for degenerate case.
2011-12-04 18:32:00 +00:00
Christopher Faylor 9f65451e3e * fhandler.h (fhandler_pipe::create): Rename from the misnamed
"create_selectable".  Change return to DWORD.
(fhandler_pty_common::pipesize): New constant.
* fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Reflect create_selectable
name change.
* miscfuncs.cc (CreatePipeOverlapped): Ditto.
* pipe.cc (fhandler_pipe::create): Ditto.
(fhandler_pipe::create): Rename from the misnamed "create_selectable".  Return
DWORD.  Only set pipe size to default when it is passed in as zero.
* fhandler_tty.cc (fhandler_pty_master::setup): Ditto.  Use
fhandler_pty_common::pipesize rather than a raw constant.
* tty.cc (tty::not_allocated): Ditto.
* sigproc.cc (sigproc_init): Use create_selectable to create the signal pipe to
get a more appropriate message based pipe.
2011-11-23 18:56:57 +00:00
Christopher Faylor cd071d1363 * fhandler.h (fhandler_pipe::create_selectable): Remove optional argument, take
an options argument for CreateNamedPipe/CreateFile.  Change handle arguments to
expect pointers.
(fhandler_fifo::fifo_state): Delete.
(fhandler_fifo::dummy_client): Ditto.
(fhandler_fifo::open_nonserver): Ditto.
(fhandler_fifo::wait_state): Ditto.
(fhandler_fifo::raw_write): Ditto.
(fhandler_fifo::read_ready): New field.
(fhandler_fifo::write_ready): Ditto.
(fhandler_fifo::wait): Modify argument.
(fhandler_fifo::fifo_name): Add a new argument.
(fhandler_fifo::fixup_after_fork): New function.
* fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Remove initialization of
expunged elements.  Initialize new handles to NULL.
(fhandler_fifo::open_nonserver): Delete.
(fnevent): New macro for creating a named event.
(fnpipe): New macro for creating a unique named pipe name.
(create_pipe): New macro for simplification of named pipe creation.
(fhandler_fifo::fifo_name): Use new argument when creating a shared name.
(fhandler_fifo::open): Rewrite.  Use events to synchronize.
(pure_debug_printf): New macro, active only when DEBUGGING.
(fhandler_fifo::wait): Rewrite to wait for new fifo events which are supplied
as a parameter.
(fhandler_fifo::raw_read): Rewrite to use handle mechanism to detect
client-side disconnect.
(fhandler_fifo::raw_write): Delete.
(fhandler_fifo::close): Remove accommodations for expunged fields.  Close event
handles.
(fhandler_fifo::dup): Remove accommodations for expunged fields.  Duplicate
event handles.
(fhandler_fifo::fixup_after_fork): New function.  Perform fixups on event
handles.
(fhandler_fifo::set_close_on_exec): Remove accommodations for expunged fields.
Set inheritance for new handle fields.
* miscfuncs.cc (CreatePipeOverlapped): Accommodate changes in
fhandler_pipe::create_selectable.
* tty.cc (tty::not_allocated): Ditto.
* pipe.cc (fhandler_pipe::create): Ditto.
(fhandler_pipe::create_selectable): Accept an extra open_mode argument.  Pass
arguments by reference and allow opening one end of the pipe at a time.
* sys/strace.h (debug_only_printf): Define new macro which calls debug_printf
only when DEBUGGING is defined.
2011-10-30 04:50:36 +00:00
Christopher Faylor 23771fa1f7 * cygerrno.h (__set_errno): Modify debugging output to make searching strace
logs easier.  Throughout, change /dev/tty* to /dev/pty*.  Throughout, add flags
argument to fhandler_*::dup methods.
* devices.in: Rename (temporarily?) /dev/ttyN to /dev/ptyN.  Add /dev/ptymN
devices for pty masters.
* devices.cc: Regenerate.
* devices.h (MAX_CONSOLES): Set to max number supported by devices.in.
(fh_devices::FH_PTMX): Rename from FH_PTYM.
(device::operator int): Return by reference.
* dtable.cc (fh_alloc): Take pc as an argument rather than just the device.
This makes debugging easier since more information is available.  Actually
implement handling for already-allocated pty master devices.  Make different
decisions when generating fhandler for not-opened devices.  Add kludge to deal
with opening /dev/tty.
(cnew_no_ctor): New macro.
(build_fh_pc): Make debugging output more verbose.  Use new clone() fhandler
interface to duplicate archetypes.  Reset last term opened.
(dtable::dup_worker): Use Use new clone() fhandler interface to duplicate
archetypes.  Pass flags to child dup handler.
(dtable::dup3): Set O_NOCTTY flag if newfd is not stdin/stdout/stderr.
* fhandler.cc (fhandler_base::reset): Rename from operator =() and reduce
functionality and sense of copy direction.
(fhandler_base::open_with_arch): Use published interface to query io_handle().
Use new copyto() fhandler method to copy from/to found archetype.
* fhandler.h: Throughout, delete size(), add copyout, clone, and fhandler_*
(void *) methods.
(fhandler_base::reset): Rename from operator =().
(fhandler_termios::is_dev_tty): Delete.
(fhandler_termios): change "protected" region to "private".
(fhandler_termios::is_dev_tty): Delete.
(fhandler_termios): Rearrange protected/public.
(fhandler_termios::fhandler_termios): Remember last fhandler_termios "opened".
(fhandler_termios::~fhandler_termios): Forget last fhandler_termios opened.
(ioctl): Rename from ioctl_termios.  Take a void * argument.  Reflect argument
change in pinfo::set_ctty.
(fhandler_console::dup): Declare new function.  Set ctty here if appropriate.
(fhandler_pty_master::from_master): Privatize.
(fhandler_pty_master::to_master): Ditto.
(fhandler_pty_master::dwProcessId): Ditto.
(fhandler_pty_master::fhandler_pty_master): Add an `int' argument.
(fhandler_pty_master::open_setup): Declare new function.
(fhandler_pty_master::~fhandler_pty_master): Declare new method.
(fhandler_nodevice): Remove commented out function declaration.
* fhandler_console.cc: Use get_ttyp() instead of tc() throughout.
(fhandler_console::dup): Define new function to set controlling ctty on dup, as
appropriate.
(fhandler_console::ioctl): Reflect ioctl_termios name change.
(fhandler_console::setup): Rename from get_tty_stuff.
(fhandler_console::open_setup): Reflect argument change in pinfo::set_ctty.
(fhandler_console::fhandler_console): Set _tc here.
* fhandler_termios.cc (handler_termios::ioctl): Rename.  Take a void * arg like
other ioctl functions.
* fhandler_tty.cc (fhandler_pty_slave::dup): Call myself->set_ctty to
potentially reset the controlling terminal.
(fhandler_pty_slave::ioctl): Reflect name/arg change for ioctl_termios.
(fhandler_pty_slave::fhandler_pty_slave): Take a "unit" argument.  Call setup()
here so that we will know the unit number of this fhandler as soon as possible.
Set the unit as appropriate.
(handler_pty_master::open): Move most stuff to constructor and open_setup.
(handler_pty_slave::open_setup): Reflect argument change in pinfo::set_ctty.
(handler_pty_master::open_setup): Define new function.
(fhandler_pty_master::cleanup): Clear handles as a flag that the destructor
does not have to do "close" operations.
(fhandler_pty_master::close): Ditto.
(fhandler_pty_master::~fhandler_pty_master): Define new method.
(fhandler_pty_master::ioctl): Reflect name/arg change for ioctl_termios.
(fhandler_pty_master::setup): Allocate tty here.  Rely on handles being
returned from allocated test rather than opening them here.  Avoid setting
_need_nl here since it is already zeroed in the constructor.  Set up device
information with DEV_TTYM_MAJOR.
* path.h (path_conv &operator =): Take a const argument.
(path_conv::dup): Ditto.
(pathconv_arg::PC_OPEN): New enum.
(pathconv_arg::PC_CTTY): Ditto.
(path_types::PATH_CTTY): Ditto.
(path_types::PATH_OPEN): Ditto.
(path_conv::isopen): New method.
(path_conv::isctty_capable): Ditto.
* path.cc (path_conv::check): Set PATH_OPEN and PATH_CTTY as appropriate.
* pipe.cc (fhandler_pipe::open): Use copyto to copy pipe handle.
* syscall.cc (open): Reinstate fd > 2 check to disallow resetting ctty on
non-std* handles.
* tty.cc (tty_list::allocate): Pass out handles for allocated tty.  use
`not_allocated' to find unallocated ttys.  Avoid keeping the lock since the
allocation of the tty should be sufficient to prevent multiple access.
(tty::not_allocated): Clarify comment.  Rename.  Return handles when an unused
tty is found.  Simply test for existing tty.
(tty::exists): Rewrite to use `not_allocated'.
* tty.h (NTTYS): Reset down to actual number supported by devices.in.
(tty::not_allocated): Declare new function.
(tty_list::allocate): Pass out read/write tty handles.  Zero them when not
found.
* fhandler_proc.cc: Reflect name change from FH_PTYM -> FH_PTMX.
* pinfo.h (pinfo::set_ctty): Reduce/reorder arguments passed in.
* pinfo.cc (pinfo::set_ctty): Ditto.  Just use tc() built into the passed-in
fhandler_termios pointer.  Return true if ctty is assigned.
* syscalls.cc (open): Call build_fh_pc with PC_OPEN flag.  Set PC_CTTY if
appropriate.
(stat_worker): Remove is_dev_tty () stuff.
2011-10-15 22:37:30 +00:00
Christopher Faylor 8ea8474947 * fhandler.cc (fhandler_base_overlapped::raw_read): Rename from
read_overlapped.
(fhandler_base_overlapped::raw_e): Rename from write_overlapped.
* fhandler.h (fhandler_*::raw_read): Add reparm decoration.
(fhandler_*::raw_write): Ditto.
(fhandler_base_overlapped::raw_read): Rename from read_overlapped.
(fhandler_base_overlapped::raw_write): Rename from write_overlapped.
(fhandler_pipe::raw_read): Delete.
(fhandler_pipe::raw_write): Ditto.
(fhandler_mailslot::raw_read): Ditto.
* fhandler_fifo.cc (fhandler_fifo::raw_read): Reflect read_overlapped ->
raw_read rename.
(fhandler_fifo::raw_write): Ditto.
* fhandler_mailslot.cc (fhandler_mailslot::raw_read): Delete.
(fhandler_mailslot::raw_write): Reflect read_overlapped -> raw_read rename.
* pipe.cc (fhandler_pipe::raw_read): Delete.
(fhandler_pipe::raw_write): Ditto.
2011-05-05 17:44:42 +00:00
Corinna Vinschen 183ad8597c * thread.cc (cancelable_wait): Remove test for main thread.
* fhandler_fifo.cc (fhandler_fifo::open_nonserver): Ditto.
2011-05-02 18:48:11 +00:00
Corinna Vinschen bd139e52b4 * ntdll.h (IsEventSignalled): New inline function.
* cygthread.cc (cygthread::terminate_thread): Use IsEventSignalled in
	place of WaitForSingleObject on event with 0 timeout.
	* fhandler.cc (fhandler_base_overlapped::has_ongoing_io): Ditto.
	* fhandler_fifo.cc (fhandler_fifo::open_nonserver): Ditto.
	(fhandler_fifo::wait): Ditto.
	* fhandler_termios.cc (fhandler_termios::bg_check): Ditto.
	* select.cc (verify_tty_slave): Ditto.
	* thread.cc (pthread::testcancel): Ditto.
2011-04-29 08:27:11 +00:00
Christopher Faylor 779ece3ce0 * errno.cc (errmap): Change mapping of NO_SYSTEM_RESOURCES to EFBIG.
* fhandler.cc (MAX_OVERLAPPED_WRITE_LEN): New constant.
(MIN_OVERLAPPED_WRITE_LEN): Ditto.
(fhandler_base_overlapped::close): Accommodate change in arguments to
wait_overlapped.
(fhandler_base_overlapped::setup_overlapped): Add __stdcall and regparm
modifiers.
(fhandler_base_overlapped::destroy_overlapped): Ditto.
(fhandler_base_overlapped::has_ongoing_io): Ditto.
(fhandler_base_overlapped::wait_overlapped): Modify to return an enum returning
various states.  Accept nonblocking parameter.
(fhandler_base_overlapped::read_overlapped): Add __stdcall and regparm
modifiers.  Rework to attempt to be smarter about reacting to states returned
by wait_overlapped.
(fhandler_base_overlapped::write_overlapped): Ditto.  Add fallback option for
when wait_overlapped detects that smaller chunks must be written.
(fhandler_base_overlapped::write_overlapped_fallback): Ditto.
* fhandler.h (DEFAULT_PIPEBUFSIZE): Move definition here from pipe.cc.
(fhandler_base::has_ongoing_io): Define with __stdcall and regparm modifiers.
(fhandler_base_overlapped::wait_return): New enum.
(fhandler_base_overlapped::max_atomic_write): New variable.
(fhandler_base_overlapped:: wait_overlapped): Accommodate changes mentioned
above to arguments and modifiers.
(fhandler_base_overlapped::setup_overlapped): Ditto for modifiers.
(fhandler_base_overlapped::read_overlapped): Ditto.
(fhandler_base_overlapped::write_overlapped): Ditto.
(fhandler_base_overlapped::destroy_overlapped): Ditto.
(fhandler_base_overlapped::has_ongoing_io): Ditto.
(fhandler_base_overlapped::fhandler_base_overlapped): Zero max_atomic_write.
* fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Set max_atomic_write to the
size of the DEFAULT_PIPEBUFSIZE.
(fhandler_fifo::wait): Accommodate change in arguments to wait_overlapped.
* pipe.cc (fhandler_pipe::fhandler_pipe): Set max_atomic_write to the size of
the DEFAULT_PIPEBUFSIZE.
(fhandler_pipe::create_selectable): Allow minimum size of DEFAULT_PIPEBUFSIZE.
(DEFAULT_PIPEBUFSIZE): Delete here, move to fhandler.h.
2011-03-09 16:47:44 +00:00
Christopher Faylor 35297ebe0b * fhandler_fifo.cc (fhandler_fifo::open): Accommodate previous return value
change to setup_overlapped.
2010-04-06 15:09:44 +00:00
Christopher Faylor 5151c80c8a * fhandler.h (fhandler_base::setup_overlapped): Delete virtual declaration.
(fhandler_base::destroy_overlapped): Ditto.
(fhandler_base_overlapped): Remove now-unneeded friend.
(fhandler_base_overlapped::setup_overlapped): Return int, remove parameter.
(fhandler_base_overlapped::get_overlapped): Return reference.
(fhandler_base_overlapped::fhandler_base_overlapped): Be more assertive about
zeroing everything.
(fhandler_base_overlapped::fixup_after_fork): Declare new function.
(fhandler_base_overlapped::fixup_after_exec): Ditto.
(fhandler_base_overlapped::dup): Ditto.
(fhandler_base_overlapped::close): Ditto.
* fhandler_fifo.cc (fhandler_fifo::dup): Call fhandler_base_overlapped::dup
rather than fhandler_base::dup.
* pipe.cc (fhandler_pipe::dup): Ditto.
(fhandler_pipe::init): Accommodate change in setup_overlapped arguments for
"opened_properly" case.
2010-04-02 18:55:02 +00:00
Christopher Faylor 60efdd0c4c * fhandler_fifo.cc (fhandler_fifo::fhandler_fifo): Properly initialize
overlapped part of this class.
2010-04-02 16:43:27 +00:00