2000-02-18 03:38:33 +08:00
|
|
|
/* fhandler_tty.cc
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
|
|
|
|
2008, 2009, 2010, 2011, 2012, 2013 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
2012-03-08 17:36:11 +08:00
|
|
|
#include <sys/param.h>
|
2006-07-03 23:29:10 +08:00
|
|
|
#include <cygwin/kd.h>
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sigproc.h"
|
2000-08-12 13:47:12 +08:00
|
|
|
#include "pinfo.h"
|
2010-04-20 03:52:43 +08:00
|
|
|
#include "ntdll.h"
|
2000-09-03 12:16:35 +08:00
|
|
|
#include "cygheap.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
#include "shared_info.h"
|
2002-08-02 00:20:31 +08:00
|
|
|
#include "cygthread.h"
|
2006-06-02 23:41:34 +08:00
|
|
|
#include "child_info.h"
|
2011-07-23 02:50:42 +08:00
|
|
|
#include <asm/socket.h>
|
2012-06-18 04:50:24 +08:00
|
|
|
#include "cygwait.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2010-04-20 03:52:43 +08:00
|
|
|
#define close_maybe(h) \
|
|
|
|
do { \
|
|
|
|
if (h && h != INVALID_HANDLE_VALUE) \
|
|
|
|
CloseHandle (h); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* pty master control pipe messages */
|
|
|
|
struct pipe_request {
|
|
|
|
DWORD pid;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pipe_reply {
|
|
|
|
HANDLE from_master;
|
|
|
|
HANDLE to_master;
|
|
|
|
DWORD error;
|
|
|
|
};
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::get_unit ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-05-29 02:17:09 +08:00
|
|
|
return dev ().get_minor ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2012-04-05 10:54:51 +08:00
|
|
|
bool
|
|
|
|
bytes_available (DWORD& n, HANDLE h)
|
|
|
|
{
|
2012-05-16 09:56:41 +08:00
|
|
|
DWORD navail, nleft;
|
|
|
|
navail = nleft = 0;
|
|
|
|
bool succeeded = PeekNamedPipe (h, NULL, 0, NULL, &navail, &nleft);
|
|
|
|
if (succeeded)
|
|
|
|
/* nleft should always be the right choice unless something has written 0
|
|
|
|
bytes to the pipe. In that pathological case we return the actual number
|
|
|
|
of bytes available in the pipe. See cgf-000008 for more details. */
|
|
|
|
n = nleft ?: navail;
|
|
|
|
else
|
2012-04-05 10:54:51 +08:00
|
|
|
{
|
|
|
|
termios_printf ("PeekNamedPipe(%p) failed, %E", h);
|
|
|
|
n = 0;
|
|
|
|
}
|
2012-11-09 01:27:00 +08:00
|
|
|
debug_only_printf ("n %u, nleft %u, navail %u", n, nleft, navail);
|
2012-04-05 10:54:51 +08:00
|
|
|
return succeeded;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
fhandler_pty_common::bytes_available (DWORD &n)
|
|
|
|
{
|
|
|
|
return ::bytes_available (n, get_handle ());
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
static class mutex_stack
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const char *fn;
|
|
|
|
int ln;
|
|
|
|
const char *tname;
|
|
|
|
} ostack[100];
|
|
|
|
|
2001-09-06 12:41:59 +08:00
|
|
|
static int osi;
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif /*DEBUGGING*/
|
|
|
|
|
2012-04-05 10:54:51 +08:00
|
|
|
void
|
|
|
|
fhandler_pty_master::flush_to_slave ()
|
2012-08-17 07:34:45 +08:00
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
if (get_readahead_valid () && !(get_ttyp ()->ti.c_lflag & ICANON))
|
|
|
|
accept_input ();
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_common::__acquire_output_mutex (const char *fn, int ln,
|
2012-04-05 10:54:51 +08:00
|
|
|
DWORD ms)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-12-30 04:46:34 +08:00
|
|
|
if (strace.active ())
|
2011-06-15 05:48:43 +08:00
|
|
|
strace.prntf (_STRACE_TERMIOS, fn, "(%d): pty output_mutex (%p): waiting %d ms", ln, output_mutex, ms);
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD res = WaitForSingleObject (output_mutex, ms);
|
|
|
|
if (res == WAIT_OBJECT_0)
|
|
|
|
{
|
2000-03-10 05:04:05 +08:00
|
|
|
#ifndef DEBUGGING
|
2005-12-30 05:10:50 +08:00
|
|
|
if (strace.active ())
|
2011-06-15 05:48:43 +08:00
|
|
|
strace.prntf (_STRACE_TERMIOS, fn, "(%d): pty output_mutex: acquired", ln, res);
|
2000-03-10 05:04:05 +08:00
|
|
|
#else
|
2000-02-18 03:38:33 +08:00
|
|
|
ostack[osi].fn = fn;
|
|
|
|
ostack[osi].ln = ln;
|
2002-08-02 00:20:31 +08:00
|
|
|
ostack[osi].tname = cygthread::name ();
|
2000-02-18 03:38:33 +08:00
|
|
|
termios_printf ("acquired for %s:%d, osi %d", fn, ln, osi);
|
|
|
|
osi++;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_common::__release_output_mutex (const char *fn, int ln)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (ReleaseMutex (output_mutex))
|
|
|
|
{
|
2000-03-10 05:04:05 +08:00
|
|
|
#ifndef DEBUGGING
|
2005-12-30 05:10:50 +08:00
|
|
|
if (strace.active ())
|
2011-06-15 05:48:43 +08:00
|
|
|
strace.prntf (_STRACE_TERMIOS, fn, "(%d): pty output_mutex(%p) released", ln, output_mutex);
|
2000-03-10 05:04:05 +08:00
|
|
|
#else
|
2000-02-18 03:38:33 +08:00
|
|
|
if (osi > 0)
|
|
|
|
osi--;
|
2011-05-06 06:30:53 +08:00
|
|
|
termios_printf ("released(%p) at %s:%d, osi %d", output_mutex, fn, ln, osi);
|
2001-03-11 09:58:23 +08:00
|
|
|
termios_printf (" for %s:%d (%s)", ostack[osi].fn, ostack[osi].ln, ostack[osi].tname);
|
2000-02-18 03:38:33 +08:00
|
|
|
ostack[osi].ln = -ln;
|
|
|
|
#endif
|
|
|
|
}
|
2006-05-22 12:50:54 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
else if (osi > 0)
|
|
|
|
{
|
|
|
|
system_printf ("couldn't release output mutex but we seem to own it, %E");
|
|
|
|
try_to_debug ();
|
|
|
|
}
|
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
/* Process pty input. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_pty_master::doecho (const void *str, DWORD len)
|
|
|
|
{
|
|
|
|
acquire_output_mutex (INFINITE);
|
2006-06-03 14:35:10 +08:00
|
|
|
if (!WriteFile (to_master, str, len, &len, NULL))
|
|
|
|
termios_printf ("Write to %p failed, %E", to_master);
|
2000-02-18 03:38:33 +08:00
|
|
|
release_output_mutex ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_pty_master::accept_input ()
|
|
|
|
{
|
2002-12-17 11:49:34 +08:00
|
|
|
DWORD bytes_left;
|
|
|
|
int ret = 1;
|
2001-03-04 23:34:25 +08:00
|
|
|
|
2005-07-07 04:05:03 +08:00
|
|
|
WaitForSingleObject (input_mutex, INFINITE);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-12-17 11:49:34 +08:00
|
|
|
bytes_left = eat_readahead (-1);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-12-17 11:49:34 +08:00
|
|
|
if (!bytes_left)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-12-17 11:49:34 +08:00
|
|
|
termios_printf ("sending EOF to slave");
|
|
|
|
get_ttyp ()->read_retval = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char *p = rabuf;
|
|
|
|
DWORD rc;
|
|
|
|
DWORD written = 0;
|
2002-12-01 06:23:01 +08:00
|
|
|
|
2012-07-30 11:44:40 +08:00
|
|
|
paranoid_printf ("about to write %d chars to slave", bytes_left);
|
2002-12-17 11:49:34 +08:00
|
|
|
rc = WriteFile (get_output_handle (), p, bytes_left, &written, NULL);
|
|
|
|
if (!rc)
|
|
|
|
{
|
2011-10-12 07:20:38 +08:00
|
|
|
debug_printf ("error writing to pipe %p %E", get_output_handle ());
|
2002-12-17 11:49:34 +08:00
|
|
|
get_ttyp ()->read_retval = -1;
|
2002-12-20 09:38:55 +08:00
|
|
|
ret = -1;
|
2002-12-17 11:49:34 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
get_ttyp ()->read_retval = 1;
|
2001-04-27 14:27:28 +08:00
|
|
|
p += written;
|
|
|
|
bytes_left -= written;
|
|
|
|
if (bytes_left > 0)
|
|
|
|
{
|
|
|
|
debug_printf ("to_slave pipe is full");
|
2002-12-17 11:49:34 +08:00
|
|
|
puts_readahead (p, bytes_left);
|
|
|
|
ret = 0;
|
2001-04-27 14:27:28 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-12-17 11:49:34 +08:00
|
|
|
|
2001-03-04 23:34:25 +08:00
|
|
|
SetEvent (input_available_event);
|
|
|
|
ReleaseMutex (input_mutex);
|
2002-12-17 11:49:34 +08:00
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-09-25 05:50:44 +08:00
|
|
|
bool
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_pty_master::hit_eof ()
|
|
|
|
{
|
|
|
|
if (get_ttyp ()->was_opened && !get_ttyp ()->slave_alive ())
|
|
|
|
{
|
|
|
|
/* We have the only remaining open handle to this pty, and
|
|
|
|
the slave pty has been opened at least once. We treat
|
|
|
|
this as EOF. */
|
|
|
|
termios_printf ("all other handles closed");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
/* Process pty output requests */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2000-03-12 14:29:54 +08:00
|
|
|
fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
size_t rlen;
|
2000-03-12 14:29:54 +08:00
|
|
|
char outbuf[OUT_BUFFER_SIZE + 1];
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD n;
|
|
|
|
int column = 0;
|
2000-03-12 12:44:37 +08:00
|
|
|
int rc = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2012-04-05 10:54:51 +08:00
|
|
|
flush_to_slave ();
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (len == 0)
|
2000-03-12 12:44:37 +08:00
|
|
|
goto out;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-03-12 14:29:54 +08:00
|
|
|
if (need_nl)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-12 14:29:54 +08:00
|
|
|
/* We need to return a left over \n character, resulting from
|
|
|
|
\r\n conversion. Note that we already checked for FLUSHO and
|
2001-04-29 07:48:28 +08:00
|
|
|
output_stopped at the time that we read the character, so we
|
2000-03-12 14:29:54 +08:00
|
|
|
don't check again here. */
|
2003-09-19 02:54:48 +08:00
|
|
|
if (buf)
|
|
|
|
buf[0] = '\n';
|
2000-03-12 14:29:54 +08:00
|
|
|
need_nl = 0;
|
2000-08-03 21:02:09 +08:00
|
|
|
rc = 1;
|
2000-03-12 14:29:54 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-03-12 14:29:54 +08:00
|
|
|
for (;;)
|
|
|
|
{
|
2000-03-12 12:44:37 +08:00
|
|
|
/* Set RLEN to the number of bytes to read from the pipe. */
|
|
|
|
rlen = len;
|
|
|
|
if (get_ttyp ()->ti.c_oflag & OPOST && get_ttyp ()->ti.c_oflag & ONLCR)
|
|
|
|
{
|
|
|
|
/* We are going to expand \n to \r\n, so don't read more than
|
|
|
|
half of the number of bytes requested. */
|
|
|
|
rlen /= 2;
|
|
|
|
if (rlen == 0)
|
|
|
|
rlen = 1;
|
|
|
|
}
|
|
|
|
if (rlen > sizeof outbuf)
|
|
|
|
rlen = sizeof outbuf;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2012-04-05 10:54:51 +08:00
|
|
|
n = 0;
|
|
|
|
for (;;)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
if (!bytes_available (n))
|
|
|
|
goto err;
|
|
|
|
if (n)
|
|
|
|
break;
|
|
|
|
if (hit_eof ())
|
|
|
|
goto out;
|
|
|
|
/* DISCARD (FLUSHO) and tcflush can finish here. */
|
|
|
|
if ((get_ttyp ()->ti.c_lflag & FLUSHO || !buf))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (is_nonblocking ())
|
2000-03-12 14:29:54 +08:00
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
set_errno (EAGAIN);
|
|
|
|
rc = -1;
|
|
|
|
goto out;
|
2000-03-12 14:29:54 +08:00
|
|
|
}
|
2012-04-05 10:54:51 +08:00
|
|
|
pthread_testcancel ();
|
2012-08-16 03:07:42 +08:00
|
|
|
if (cygwait (NULL, 10, cw_sig_eintr) == WAIT_SIGNALED
|
2012-04-05 10:54:51 +08:00
|
|
|
&& !_my_tls.call_signal_handler ())
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
set_errno (EINTR);
|
|
|
|
rc = -1;
|
|
|
|
goto out;
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
2012-04-05 10:54:51 +08:00
|
|
|
flush_to_slave ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ReadFile (get_handle (), outbuf, rlen, &n, NULL))
|
|
|
|
{
|
|
|
|
termios_printf ("ReadFile failed, %E");
|
|
|
|
goto err;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-03-12 14:29:54 +08:00
|
|
|
termios_printf ("bytes read %u", n);
|
2000-09-08 00:23:51 +08:00
|
|
|
get_ttyp ()->write_error = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-09-19 02:54:48 +08:00
|
|
|
if (get_ttyp ()->ti.c_lflag & FLUSHO || !buf)
|
2000-09-08 00:23:51 +08:00
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-03-12 14:29:54 +08:00
|
|
|
char *optr;
|
|
|
|
optr = buf;
|
|
|
|
if (pktmode_on)
|
|
|
|
*optr++ = TIOCPKT_DATA;
|
|
|
|
|
2000-03-12 12:44:37 +08:00
|
|
|
if (!(get_ttyp ()->ti.c_oflag & OPOST)) // post-process output
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-12 14:29:54 +08:00
|
|
|
memcpy (optr, outbuf, n);
|
|
|
|
optr += n;
|
2000-03-12 12:44:37 +08:00
|
|
|
}
|
|
|
|
else // raw output mode
|
|
|
|
{
|
2000-03-12 14:29:54 +08:00
|
|
|
char *iptr = outbuf;
|
2000-03-12 12:44:37 +08:00
|
|
|
|
|
|
|
while (n--)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-12 12:44:37 +08:00
|
|
|
switch (*iptr)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-12 12:44:37 +08:00
|
|
|
case '\r':
|
|
|
|
if ((get_ttyp ()->ti.c_oflag & ONOCR) && column == 0)
|
|
|
|
{
|
|
|
|
iptr++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (get_ttyp ()->ti.c_oflag & OCRNL)
|
|
|
|
*iptr = '\n';
|
|
|
|
else
|
|
|
|
column = 0;
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
if (get_ttyp ()->ti.c_oflag & ONLCR)
|
|
|
|
{
|
|
|
|
*optr++ = '\r';
|
|
|
|
column = 0;
|
|
|
|
}
|
|
|
|
if (get_ttyp ()->ti.c_oflag & ONLRET)
|
|
|
|
column = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
column++;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-03-12 12:44:37 +08:00
|
|
|
|
|
|
|
/* Don't store data past the end of the user's buffer. This
|
|
|
|
can happen if the user requests a read of 1 byte when
|
|
|
|
doing \r\n expansion. */
|
|
|
|
if (optr - buf >= (int) len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-03-12 12:44:37 +08:00
|
|
|
if (*iptr != '\n' || n != 0)
|
|
|
|
system_printf ("internal error: %d unexpected characters", n);
|
2000-03-12 14:29:54 +08:00
|
|
|
need_nl = 1;
|
2000-03-12 12:44:37 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-03-12 12:44:37 +08:00
|
|
|
*optr++ = *iptr++;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-03-12 12:44:37 +08:00
|
|
|
}
|
2000-03-12 14:29:54 +08:00
|
|
|
rc = optr - buf;
|
2000-03-12 12:44:37 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-03-12 12:44:37 +08:00
|
|
|
err:
|
|
|
|
if (GetLastError () == ERROR_BROKEN_PIPE)
|
|
|
|
rc = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
rc = -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-03-12 12:44:37 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-03-12 12:44:37 +08:00
|
|
|
|
|
|
|
out:
|
|
|
|
termios_printf ("returning %d", rc);
|
|
|
|
return rc;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
/* pty slave stuff */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fhandler_pty_slave (int unit)
|
|
|
|
: fhandler_pty_common (), inuse (NULL)
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
2011-06-14 07:49:00 +08:00
|
|
|
if (unit >= 0)
|
2011-10-20 22:02:54 +08:00
|
|
|
dev ().parse (DEV_PTYS_MAJOR, unit);
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::open (int flags, mode_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-06-15 05:48:43 +08:00
|
|
|
HANDLE pty_owner, from_master_local, to_master_local;
|
2010-04-02 23:41:27 +08:00
|
|
|
HANDLE *handles[] =
|
|
|
|
{
|
|
|
|
&from_master_local, &input_available_event, &input_mutex, &inuse,
|
2011-06-15 05:48:43 +08:00
|
|
|
&output_mutex, &to_master_local, &pty_owner,
|
2010-04-02 23:41:27 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
for (HANDLE **h = handles; *h; h++)
|
|
|
|
**h = NULL;
|
|
|
|
|
2011-06-04 08:12:29 +08:00
|
|
|
_tc = cygwin_shared->tty[get_unit ()];
|
|
|
|
|
|
|
|
tcinit (false);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2006-06-04 04:32:07 +08:00
|
|
|
cygwin_shared->tty.attach (get_unit ());
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Create synchronisation events */
|
2007-12-06 00:50:18 +08:00
|
|
|
char buf[MAX_PATH];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
const char *errmsg = NULL;
|
|
|
|
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!(output_mutex = get_ttyp ()->open_output_mutex (MAXIMUM_ALLOWED)))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-04-02 23:41:27 +08:00
|
|
|
errmsg = "open output mutex failed, %E";
|
|
|
|
goto err;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!(input_mutex = get_ttyp ()->open_input_mutex (MAXIMUM_ALLOWED)))
|
2001-03-04 23:34:25 +08:00
|
|
|
{
|
2010-04-02 23:41:27 +08:00
|
|
|
errmsg = "open input mutex failed, %E";
|
|
|
|
goto err;
|
2001-03-04 23:34:25 +08:00
|
|
|
}
|
2004-05-12 09:44:11 +08:00
|
|
|
shared_name (buf, INPUT_AVAILABLE_EVENT, get_unit ());
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!(input_available_event = OpenEvent (MAXIMUM_ALLOWED, TRUE, buf)))
|
2001-03-04 23:34:25 +08:00
|
|
|
{
|
2010-04-02 23:41:27 +08:00
|
|
|
errmsg = "open input event failed, %E";
|
|
|
|
goto err;
|
2001-03-04 23:34:25 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* FIXME: Needs a method to eliminate tty races */
|
|
|
|
{
|
2010-04-20 03:52:43 +08:00
|
|
|
/* Create security attribute. Default permissions are 0620. */
|
|
|
|
security_descriptor sd;
|
|
|
|
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
|
2011-04-28 17:30:36 +08:00
|
|
|
RtlCreateSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
|
2010-04-20 03:52:43 +08:00
|
|
|
SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE };
|
|
|
|
if (!create_object_sd_from_attribute (NULL, myself->uid, myself->gid,
|
|
|
|
S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP,
|
|
|
|
sd))
|
|
|
|
sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR) sd;
|
2000-02-18 03:38:33 +08:00
|
|
|
acquire_output_mutex (500);
|
2010-04-20 03:52:43 +08:00
|
|
|
inuse = get_ttyp ()->create_inuse (&sa);
|
2003-12-08 06:37:12 +08:00
|
|
|
get_ttyp ()->was_opened = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
release_output_mutex ();
|
|
|
|
}
|
|
|
|
|
2006-06-02 23:41:34 +08:00
|
|
|
if (!get_ttyp ()->from_master || !get_ttyp ()->to_master)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-06-15 05:48:43 +08:00
|
|
|
errmsg = "pty handles have been closed";
|
2000-02-18 03:38:33 +08:00
|
|
|
set_errno (EACCES);
|
2010-04-02 23:41:27 +08:00
|
|
|
goto err_no_errno;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2011-12-10 00:02:56 +08:00
|
|
|
if (get_ttyp ()->is_master_closed ())
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
errmsg = "*** master is closed";
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
goto err_no_errno;
|
|
|
|
}
|
|
|
|
/* Three case for duplicating the pipe handles:
|
|
|
|
- Either we're the master. In this case, just duplicate the handles.
|
|
|
|
- Or, we have the right to open the master process for handle duplication.
|
|
|
|
In this case, just duplicate the handles.
|
|
|
|
- Or, we have to ask the master process itself. In this case, send our
|
|
|
|
pid to the master process and check the reply. The reply contains
|
|
|
|
either the handles, or an error code which tells us why we didn't
|
|
|
|
get the handles. */
|
|
|
|
if (myself->pid == get_ttyp ()->master_pid)
|
|
|
|
{
|
|
|
|
/* This is the most common case, just calling openpty. */
|
|
|
|
termios_printf ("dup handles within myself.");
|
2011-06-15 05:48:43 +08:00
|
|
|
pty_owner = GetCurrentProcess ();
|
2010-04-20 03:52:43 +08:00
|
|
|
}
|
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2006-06-02 23:41:34 +08:00
|
|
|
pinfo p (get_ttyp ()->master_pid);
|
|
|
|
if (!p)
|
2011-06-15 05:48:43 +08:00
|
|
|
termios_printf ("*** couldn't find pty master");
|
2010-04-12 21:28:06 +08:00
|
|
|
else
|
|
|
|
{
|
2011-06-15 05:48:43 +08:00
|
|
|
pty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE, p->dwProcessId);
|
|
|
|
if (pty_owner)
|
2011-10-10 12:05:29 +08:00
|
|
|
termios_printf ("dup handles directly since I'm the owner");
|
2002-05-28 09:55:40 +08:00
|
|
|
}
|
2010-04-20 03:52:43 +08:00
|
|
|
}
|
2011-06-15 05:48:43 +08:00
|
|
|
if (pty_owner)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
2011-06-15 05:48:43 +08:00
|
|
|
if (!DuplicateHandle (pty_owner, get_ttyp ()->from_master,
|
2009-12-19 04:32:04 +08:00
|
|
|
GetCurrentProcess (), &from_master_local, 0, TRUE,
|
2002-02-28 22:30:38 +08:00
|
|
|
DUPLICATE_SAME_ACCESS))
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
2009-07-04 02:05:51 +08:00
|
|
|
termios_printf ("can't duplicate input from %u/%p, %E",
|
|
|
|
get_ttyp ()->master_pid, get_ttyp ()->from_master);
|
2002-05-28 09:55:40 +08:00
|
|
|
__seterrno ();
|
2010-04-02 23:41:27 +08:00
|
|
|
goto err_no_msg;
|
2002-05-28 09:55:40 +08:00
|
|
|
}
|
2011-06-15 05:48:43 +08:00
|
|
|
if (!DuplicateHandle (pty_owner, get_ttyp ()->to_master,
|
2009-12-19 04:32:04 +08:00
|
|
|
GetCurrentProcess (), &to_master_local, 0, TRUE,
|
2002-02-28 22:30:38 +08:00
|
|
|
DUPLICATE_SAME_ACCESS))
|
2002-05-28 09:55:40 +08:00
|
|
|
{
|
2010-04-02 23:41:27 +08:00
|
|
|
errmsg = "can't duplicate output, %E";
|
|
|
|
goto err;
|
2002-05-28 09:55:40 +08:00
|
|
|
}
|
2011-06-15 05:48:43 +08:00
|
|
|
if (pty_owner != GetCurrentProcess ())
|
|
|
|
CloseHandle (pty_owner);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2010-04-20 03:52:43 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pipe_request req = { GetCurrentProcessId () };
|
|
|
|
pipe_reply repl;
|
|
|
|
DWORD len;
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
|
2012-02-14 19:27:43 +08:00
|
|
|
&cygheap->installation_key, get_unit ());
|
2010-04-20 03:52:43 +08:00
|
|
|
termios_printf ("dup handles via master control pipe %s", buf);
|
|
|
|
if (!CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl,
|
|
|
|
&len, 500))
|
|
|
|
{
|
|
|
|
errmsg = "can't call master, %E";
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
from_master_local = repl.from_master;
|
|
|
|
to_master_local = repl.to_master;
|
|
|
|
if (!from_master_local || !to_master_local)
|
|
|
|
{
|
|
|
|
SetLastError (repl.error);
|
|
|
|
errmsg = "error duplicating pipes, %E";
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VerifyHandle (from_master_local);
|
|
|
|
VerifyHandle (to_master_local);
|
2002-02-28 22:30:38 +08:00
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
termios_printf ("duplicated from_master %p->%p from pty_owner",
|
2006-06-03 14:35:10 +08:00
|
|
|
get_ttyp ()->from_master, from_master_local);
|
2011-06-15 05:48:43 +08:00
|
|
|
termios_printf ("duplicated to_master %p->%p from pty_owner",
|
2006-06-03 14:35:10 +08:00
|
|
|
get_ttyp ()->to_master, to_master_local);
|
2002-02-28 22:30:38 +08:00
|
|
|
|
|
|
|
set_io_handle (from_master_local);
|
|
|
|
set_output_handle (to_master_local);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2012-02-08 00:54:14 +08:00
|
|
|
fhandler_console::need_invisible ();
|
2001-04-24 10:07:58 +08:00
|
|
|
set_open_status ();
|
2000-02-18 03:38:33 +08:00
|
|
|
return 1;
|
2010-04-02 23:41:27 +08:00
|
|
|
|
|
|
|
err:
|
2011-10-10 12:05:29 +08:00
|
|
|
if (GetLastError () == ERROR_FILE_NOT_FOUND)
|
|
|
|
set_errno (ENXIO);
|
|
|
|
else
|
|
|
|
__seterrno ();
|
2010-04-02 23:41:27 +08:00
|
|
|
err_no_errno:
|
|
|
|
termios_printf (errmsg);
|
|
|
|
err_no_msg:
|
|
|
|
for (HANDLE **h = handles; *h; h++)
|
|
|
|
if (**h && **h != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (**h);
|
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::open_setup (int flags)
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2011-10-16 06:37:30 +08:00
|
|
|
myself->set_ctty (this, flags);
|
2011-05-06 06:30:53 +08:00
|
|
|
report_tty_counts (this, "opened", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::cleanup ()
|
2003-03-04 12:07:34 +08:00
|
|
|
{
|
2011-11-14 09:29:49 +08:00
|
|
|
/* This used to always call fhandler_pty_common::close when we were execing
|
|
|
|
but that caused multiple closes of the handles associated with this pty.
|
|
|
|
Since close_all_files is not called until after the cygwin process has
|
|
|
|
synced or before a non-cygwin process has exited, it should be safe to
|
|
|
|
just close this normally. cgf 2006-05-20 */
|
2006-05-20 12:59:53 +08:00
|
|
|
report_tty_counts (this, "closed", "");
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
2003-12-28 01:41:17 +08:00
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::close ()
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
2003-12-30 09:57:16 +08:00
|
|
|
termios_printf ("closing last open %s handle", ttyname ());
|
2006-06-02 23:41:34 +08:00
|
|
|
if (inuse && !CloseHandle (inuse))
|
|
|
|
termios_printf ("CloseHandle (inuse), %E");
|
2011-12-10 00:02:56 +08:00
|
|
|
if (!ForceCloseHandle (input_available_event))
|
|
|
|
termios_printf ("CloseHandle (input_available_event<%p>), %E", input_available_event);
|
2012-02-08 00:54:14 +08:00
|
|
|
if ((unsigned) myself->ctty == FHDEV (DEV_PTYS_MAJOR, get_unit ()))
|
|
|
|
fhandler_console::free_console (); /* assumes that we are the last pty closer */
|
2011-06-15 05:48:43 +08:00
|
|
|
return fhandler_pty_common::close ();
|
2003-03-04 12:07:34 +08:00
|
|
|
}
|
|
|
|
|
2002-02-28 22:30:38 +08:00
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::init (HANDLE h, DWORD a, mode_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
int flags = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
a &= GENERIC_READ | GENERIC_WRITE;
|
|
|
|
if (a == GENERIC_READ)
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
flags = O_RDONLY;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (a == GENERIC_WRITE)
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
flags = O_WRONLY;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (a == (GENERIC_READ | GENERIC_WRITE))
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
flags = O_RDWR;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
int ret = open_with_arch (flags);
|
2010-09-21 04:25:50 +08:00
|
|
|
|
2010-09-21 06:28:57 +08:00
|
|
|
if (ret && !cygwin_finished_initializing && !being_debugged ())
|
2010-04-22 03:36:40 +08:00
|
|
|
{
|
|
|
|
/* This only occurs when called from dtable::init_std_file_from_handle
|
|
|
|
We have been started from a non-Cygwin process. So we should become
|
2011-06-15 05:48:43 +08:00
|
|
|
pty process group leader.
|
2010-04-22 03:36:40 +08:00
|
|
|
TODO: Investigate how SIGTTIN should be handled with pure-windows
|
|
|
|
programs. */
|
2011-06-04 08:12:29 +08:00
|
|
|
pinfo p (tc ()->getpgid ());
|
2010-09-21 06:28:57 +08:00
|
|
|
/* We should only grab this when the process group owner for this
|
2011-06-15 05:48:43 +08:00
|
|
|
pty is a non-cygwin process or we've been started directly
|
2010-09-21 06:28:57 +08:00
|
|
|
from a non-Cygwin process with no Cygwin ancestry. */
|
|
|
|
if (!p || ISSTATE (p, PID_NOTCYGWIN))
|
2010-09-29 11:57:24 +08:00
|
|
|
{
|
|
|
|
termios_printf ("Setting process group leader to %d since %W(%d) is not a cygwin process",
|
|
|
|
myself->pgid, p->progname, p->pid);
|
2011-06-04 08:12:29 +08:00
|
|
|
tc ()->setpgid (myself->pgid);
|
2010-09-29 11:57:24 +08:00
|
|
|
}
|
2010-04-22 03:36:40 +08:00
|
|
|
}
|
2010-04-20 03:52:43 +08:00
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
if (h != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (h); /* Reopened by open */
|
2010-04-20 03:52:43 +08:00
|
|
|
|
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::write (const void *ptr, size_t len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
DWORD n, towrite = len;
|
|
|
|
|
2011-05-06 03:43:04 +08:00
|
|
|
bg_check_types bg = bg_check (SIGTTOU);
|
|
|
|
if (bg <= bg_eof)
|
|
|
|
return (ssize_t) bg;
|
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
termios_printf ("pty%d, write(%x, %d)", get_unit (), ptr, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-06 03:43:04 +08:00
|
|
|
push_process_state process_state (PID_TTYOU);
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
while (len)
|
|
|
|
{
|
2012-03-08 17:36:11 +08:00
|
|
|
n = MIN (OUT_BUFFER_SIZE, len);
|
2000-02-18 03:38:33 +08:00
|
|
|
char *buf = (char *)ptr;
|
|
|
|
ptr = (char *) ptr + n;
|
|
|
|
len -= n;
|
|
|
|
|
2012-10-12 09:19:04 +08:00
|
|
|
while (tc ()->output_stopped)
|
|
|
|
cygwait (10);
|
|
|
|
acquire_output_mutex (INFINITE);
|
|
|
|
|
2000-09-08 00:23:51 +08:00
|
|
|
/* Previous write may have set write_error to != 0. Check it here.
|
2011-06-15 05:48:43 +08:00
|
|
|
This is less than optimal, but the alternative slows down pty
|
2000-09-08 00:23:51 +08:00
|
|
|
writes enormously. */
|
|
|
|
if (get_ttyp ()->write_error)
|
|
|
|
{
|
|
|
|
set_errno (get_ttyp ()->write_error);
|
|
|
|
towrite = (DWORD) -1;
|
2012-10-16 01:12:17 +08:00
|
|
|
get_ttyp ()->write_error = 0;
|
|
|
|
release_output_mutex ();
|
2000-09-08 00:23:51 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-10-15 22:36:48 +08:00
|
|
|
BOOL res = WriteFile (get_output_handle (), buf, n, &n, NULL);
|
2012-10-12 09:19:04 +08:00
|
|
|
release_output_mutex ();
|
|
|
|
if (!res)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-08-29 10:06:49 +08:00
|
|
|
DWORD err = GetLastError ();
|
2000-02-18 03:38:33 +08:00
|
|
|
termios_printf ("WriteFile failed, %E");
|
2000-08-29 10:06:49 +08:00
|
|
|
switch (err)
|
|
|
|
{
|
|
|
|
case ERROR_NO_DATA:
|
|
|
|
err = ERROR_IO_DEVICE;
|
|
|
|
default:
|
2000-09-19 07:46:10 +08:00
|
|
|
__seterrno_from_win_error (err);
|
2000-08-29 10:06:49 +08:00
|
|
|
}
|
2002-10-20 12:15:50 +08:00
|
|
|
raise (SIGHUP); /* FIXME: Should this be SIGTTOU? */
|
2000-08-29 10:06:49 +08:00
|
|
|
towrite = (DWORD) -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return towrite;
|
|
|
|
}
|
|
|
|
|
2002-12-14 12:01:32 +08:00
|
|
|
void __stdcall
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::read (void *ptr, size_t& len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int totalread = 0;
|
2002-10-16 12:54:08 +08:00
|
|
|
int vmin = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
int vtime = 0; /* Initialized to prevent -Wuninitialized warning */
|
2001-03-04 23:34:25 +08:00
|
|
|
size_t readlen;
|
|
|
|
DWORD bytes_in_pipe;
|
2000-02-18 03:38:33 +08:00
|
|
|
char buf[INP_BUFFER_SIZE];
|
2001-03-04 23:34:25 +08:00
|
|
|
DWORD time_to_wait;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-06 03:43:04 +08:00
|
|
|
bg_check_types bg = bg_check (SIGTTIN);
|
|
|
|
if (bg <= bg_eof)
|
|
|
|
{
|
|
|
|
len = (size_t) bg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-02-28 22:30:38 +08:00
|
|
|
termios_printf ("read(%x, %d) handle %p", ptr, len, get_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-05-06 03:43:04 +08:00
|
|
|
push_process_state process_state (PID_TTYIN);
|
|
|
|
|
2011-05-03 15:58:13 +08:00
|
|
|
if (is_nonblocking () || !ptr) /* Indicating tcflush(). */
|
2003-09-19 02:54:48 +08:00
|
|
|
time_to_wait = 0;
|
|
|
|
else if ((get_ttyp ()->ti.c_lflag & ICANON))
|
2002-10-16 12:54:08 +08:00
|
|
|
time_to_wait = INFINITE;
|
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-05-19 04:27:49 +08:00
|
|
|
vmin = get_ttyp ()->ti.c_cc[VMIN];
|
|
|
|
if (vmin > INP_BUFFER_SIZE)
|
|
|
|
vmin = INP_BUFFER_SIZE;
|
2000-02-18 03:38:33 +08:00
|
|
|
vtime = get_ttyp ()->ti.c_cc[VTIME];
|
2002-08-31 11:35:50 +08:00
|
|
|
if (vmin < 0)
|
|
|
|
vmin = 0;
|
|
|
|
if (vtime < 0)
|
|
|
|
vtime = 0;
|
2002-10-16 12:54:08 +08:00
|
|
|
if (!vmin && !vtime)
|
|
|
|
time_to_wait = 0;
|
|
|
|
else
|
|
|
|
time_to_wait = !vtime ? INFINITE : 100 * vtime;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-03-04 23:34:25 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
while (len)
|
|
|
|
{
|
2011-12-10 00:02:56 +08:00
|
|
|
switch (cygwait (input_available_event, time_to_wait))
|
2004-11-26 12:15:10 +08:00
|
|
|
{
|
2011-05-03 15:58:13 +08:00
|
|
|
case WAIT_OBJECT_0:
|
2011-12-10 00:02:56 +08:00
|
|
|
if (get_ttyp ()->is_master_closed ())
|
|
|
|
{
|
|
|
|
raise (SIGHUP);
|
|
|
|
totalread = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2004-11-26 12:15:10 +08:00
|
|
|
break;
|
2012-06-18 04:50:24 +08:00
|
|
|
case WAIT_SIGNALED:
|
2011-05-03 15:58:13 +08:00
|
|
|
if (totalread > 0)
|
|
|
|
goto out;
|
|
|
|
termios_printf ("wait catched signal");
|
|
|
|
set_sig_errno (EINTR);
|
|
|
|
totalread = -1;
|
|
|
|
goto out;
|
2012-06-18 04:50:24 +08:00
|
|
|
case WAIT_CANCELED:
|
2011-05-06 03:43:04 +08:00
|
|
|
process_state.pop ();
|
2011-05-03 15:58:13 +08:00
|
|
|
pthread::static_cancel_self ();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
termios_printf ("wait timed out, time_to_wait %u", time_to_wait);
|
|
|
|
if (!totalread)
|
|
|
|
{
|
|
|
|
set_sig_errno (EAGAIN);
|
|
|
|
totalread = -1;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
default:
|
2002-10-16 12:54:08 +08:00
|
|
|
termios_printf ("wait for input event failed, %E");
|
2011-05-03 15:58:13 +08:00
|
|
|
if (!totalread)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
totalread = -1;
|
|
|
|
}
|
|
|
|
goto out;
|
2002-10-16 12:54:08 +08:00
|
|
|
}
|
2011-05-03 15:58:13 +08:00
|
|
|
/* Now that we know that input is available we have to grab the
|
|
|
|
input mutex. */
|
2011-12-10 00:02:56 +08:00
|
|
|
switch (cygwait (input_mutex, 1000))
|
2001-03-11 09:58:23 +08:00
|
|
|
{
|
2011-05-03 15:58:13 +08:00
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
case WAIT_ABANDONED_0:
|
|
|
|
break;
|
2012-06-18 04:50:24 +08:00
|
|
|
case WAIT_SIGNALED:
|
2001-03-11 09:58:23 +08:00
|
|
|
if (totalread > 0)
|
2011-05-03 15:58:13 +08:00
|
|
|
goto out;
|
2012-06-18 04:50:24 +08:00
|
|
|
termios_printf ("wait for mutex caught signal");
|
2001-03-11 09:58:23 +08:00
|
|
|
set_sig_errno (EINTR);
|
2011-05-03 15:58:13 +08:00
|
|
|
totalread = -1;
|
|
|
|
goto out;
|
2012-06-18 04:50:24 +08:00
|
|
|
case WAIT_CANCELED:
|
2011-05-06 03:43:04 +08:00
|
|
|
process_state.pop ();
|
2011-05-03 15:58:13 +08:00
|
|
|
pthread::static_cancel_self ();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
termios_printf ("failed to acquire input mutex after input event "
|
|
|
|
"arrived");
|
|
|
|
/* If we have a timeout, we can simply handle this failure to
|
|
|
|
grab the mutex as an EAGAIN situation. Otherwise, if this
|
|
|
|
is an infinitely blocking read, restart the loop. */
|
|
|
|
if (time_to_wait != INFINITE)
|
|
|
|
{
|
|
|
|
if (!totalread)
|
|
|
|
{
|
|
|
|
set_sig_errno (EAGAIN);
|
|
|
|
totalread = -1;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
default:
|
2001-03-11 09:58:23 +08:00
|
|
|
termios_printf ("wait for input mutex failed, %E");
|
2011-05-03 15:58:13 +08:00
|
|
|
if (!totalread)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
totalread = -1;
|
|
|
|
}
|
|
|
|
goto out;
|
2001-03-11 09:58:23 +08:00
|
|
|
}
|
2012-04-05 10:54:51 +08:00
|
|
|
if (!bytes_available (bytes_in_pipe))
|
|
|
|
raise (SIGHUP);
|
2002-10-16 12:54:08 +08:00
|
|
|
|
2003-09-19 02:54:48 +08:00
|
|
|
/* On first peek determine no. of bytes to flush. */
|
|
|
|
if (!ptr && len == UINT_MAX)
|
2004-05-29 03:50:07 +08:00
|
|
|
len = (size_t) bytes_in_pipe;
|
2003-09-19 02:54:48 +08:00
|
|
|
|
2005-05-02 08:17:45 +08:00
|
|
|
if (ptr && !bytes_in_pipe && !vmin && !time_to_wait)
|
2002-10-16 12:54:08 +08:00
|
|
|
{
|
|
|
|
ReleaseMutex (input_mutex);
|
2003-09-08 02:27:54 +08:00
|
|
|
len = (size_t) bytes_in_pipe;
|
2002-12-14 12:01:32 +08:00
|
|
|
return;
|
2002-10-16 12:54:08 +08:00
|
|
|
}
|
|
|
|
|
2012-03-08 17:36:11 +08:00
|
|
|
readlen = MIN (bytes_in_pipe, MIN (len, sizeof (buf)));
|
2002-10-16 12:54:08 +08:00
|
|
|
|
2003-09-19 02:54:48 +08:00
|
|
|
if (ptr && vmin && readlen > (unsigned) vmin)
|
2002-10-16 12:54:08 +08:00
|
|
|
readlen = vmin;
|
|
|
|
|
|
|
|
DWORD n = 0;
|
2001-03-11 09:58:23 +08:00
|
|
|
if (readlen)
|
|
|
|
{
|
|
|
|
termios_printf ("reading %d bytes (vtime %d)", readlen, vtime);
|
2011-10-24 03:01:47 +08:00
|
|
|
if (!ReadFile (get_handle (), buf, readlen, &n, NULL))
|
2001-03-11 09:58:23 +08:00
|
|
|
{
|
2001-03-04 23:34:25 +08:00
|
|
|
termios_printf ("read failed, %E");
|
2002-10-20 12:15:50 +08:00
|
|
|
raise (SIGHUP);
|
2001-03-19 02:05:01 +08:00
|
|
|
bytes_in_pipe = 0;
|
2011-12-10 00:02:56 +08:00
|
|
|
ptr = NULL;
|
2001-03-19 02:05:01 +08:00
|
|
|
}
|
2011-12-10 00:02:56 +08:00
|
|
|
else
|
2001-03-11 09:58:23 +08:00
|
|
|
{
|
2011-12-10 00:02:56 +08:00
|
|
|
/* MSDN states that 5th prameter can be used to determine total
|
|
|
|
number of bytes in pipe, but for some reason this number doesn't
|
|
|
|
change after successful read. So we have to peek into the pipe
|
|
|
|
again to see if input is still available */
|
2012-04-05 10:54:51 +08:00
|
|
|
if (!bytes_available (bytes_in_pipe))
|
|
|
|
raise (SIGHUP);
|
2011-12-10 00:02:56 +08:00
|
|
|
if (n)
|
|
|
|
{
|
|
|
|
len -= n;
|
|
|
|
totalread += n;
|
|
|
|
if (ptr)
|
|
|
|
{
|
|
|
|
memcpy (ptr, buf, n);
|
|
|
|
ptr = (char *) ptr + n;
|
|
|
|
}
|
2003-09-19 02:54:48 +08:00
|
|
|
}
|
2001-03-11 09:58:23 +08:00
|
|
|
}
|
|
|
|
}
|
2001-03-04 23:34:25 +08:00
|
|
|
|
2001-03-19 02:05:01 +08:00
|
|
|
if (!bytes_in_pipe)
|
|
|
|
ResetEvent (input_available_event);
|
2001-03-04 23:34:25 +08:00
|
|
|
|
|
|
|
ReleaseMutex (input_mutex);
|
2000-03-12 14:29:54 +08:00
|
|
|
|
2003-09-19 02:54:48 +08:00
|
|
|
if (!ptr)
|
|
|
|
{
|
|
|
|
if (!bytes_in_pipe)
|
|
|
|
break;
|
|
|
|
continue;
|
2004-05-29 03:50:07 +08:00
|
|
|
}
|
2003-09-19 02:54:48 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (get_ttyp ()->read_retval < 0) // read error
|
|
|
|
{
|
|
|
|
set_errno (-get_ttyp ()->read_retval);
|
|
|
|
totalread = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (get_ttyp ()->read_retval == 0) //EOF
|
|
|
|
{
|
|
|
|
termios_printf ("saw EOF");
|
|
|
|
break;
|
|
|
|
}
|
2001-08-15 15:49:15 +08:00
|
|
|
if (get_ttyp ()->ti.c_lflag & ICANON || is_nonblocking ())
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2002-10-16 12:54:08 +08:00
|
|
|
if (vmin && totalread >= vmin)
|
2001-03-11 09:58:23 +08:00
|
|
|
break;
|
2001-03-04 23:34:25 +08:00
|
|
|
|
2001-03-11 09:58:23 +08:00
|
|
|
/* vmin == 0 && vtime == 0:
|
2001-03-04 23:34:25 +08:00
|
|
|
* we've already read all input, if any, so return immediately
|
|
|
|
* vmin == 0 && vtime > 0:
|
|
|
|
* we've waited for input 10*vtime ms in WFSO(input_available_event),
|
|
|
|
* no matter whether any input arrived, we shouldn't wait any longer,
|
2001-03-11 09:58:23 +08:00
|
|
|
* so return immediately
|
2001-03-04 23:34:25 +08:00
|
|
|
* vmin > 0 && vtime == 0:
|
|
|
|
* here, totalread < vmin, so continue waiting until more data
|
|
|
|
* arrive
|
|
|
|
* vmin > 0 && vtime > 0:
|
|
|
|
* similar to the previous here, totalread < vmin, and timer
|
|
|
|
* hadn't expired -- WFSO(input_available_event) != WAIT_TIMEOUT,
|
|
|
|
* so "restart timer" and wait until more data arrive
|
|
|
|
*/
|
|
|
|
|
2001-03-11 09:58:23 +08:00
|
|
|
if (vmin == 0)
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2011-05-03 15:58:13 +08:00
|
|
|
out:
|
2000-02-18 03:38:33 +08:00
|
|
|
termios_printf ("%d=read(%x, %d)", totalread, ptr, len);
|
2003-09-08 02:27:54 +08:00
|
|
|
len = (size_t) totalread;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-03-04 12:07:34 +08:00
|
|
|
int
|
2011-10-16 06:37:30 +08:00
|
|
|
fhandler_pty_slave::dup (fhandler_base *child, int flags)
|
2003-03-04 12:07:34 +08:00
|
|
|
{
|
2012-03-04 05:35:30 +08:00
|
|
|
/* This code was added in Oct 2001 for some undisclosed reason.
|
|
|
|
However, setting the controlling tty on a dup causes rxvt to
|
|
|
|
hang when the parent does a dup since the controlling pgid changes.
|
|
|
|
Specifically testing for -2 (ctty has been setsid'ed) works around
|
|
|
|
this problem. However, it's difficult to see scenarios in which you
|
|
|
|
have a dup'able fd, no controlling tty, and not having run setsid.
|
|
|
|
So, we might want to consider getting rid of the set_ctty in tty-like dup
|
|
|
|
methods entirely at some point */
|
|
|
|
if (myself->ctty != -2)
|
|
|
|
myself->set_ctty (this, flags);
|
2011-05-06 06:30:53 +08:00
|
|
|
report_tty_counts (child, "duped slave", "");
|
2003-12-11 14:12:41 +08:00
|
|
|
return 0;
|
2003-03-04 12:07:34 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2011-10-16 06:37:30 +08:00
|
|
|
fhandler_pty_master::dup (fhandler_base *child, int)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2006-06-02 23:41:34 +08:00
|
|
|
report_tty_counts (child, "duped master", "");
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::tcgetattr (struct termios *t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
*t = get_ttyp ()->ti;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::tcsetattr (int, const struct termios *t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
acquire_output_mutex (INFINITE);
|
|
|
|
get_ttyp ()->ti = *t;
|
|
|
|
release_output_mutex ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::tcflush (int queue)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-09-19 02:54:48 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
termios_printf ("tcflush(%d) handle %p", queue, get_handle ());
|
|
|
|
|
|
|
|
if (queue == TCIFLUSH || queue == TCIOFLUSH)
|
|
|
|
{
|
|
|
|
size_t len = UINT_MAX;
|
|
|
|
read (NULL, len);
|
2005-08-06 00:11:21 +08:00
|
|
|
ret = ((int) len) >= 0 ? 0 : -1;
|
2003-09-19 02:54:48 +08:00
|
|
|
}
|
|
|
|
if (queue == TCOFLUSH || queue == TCIOFLUSH)
|
|
|
|
{
|
|
|
|
/* do nothing for now. */
|
|
|
|
}
|
|
|
|
|
|
|
|
termios_printf ("%d=tcflush(%d)", ret, queue);
|
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::ioctl (unsigned int cmd, void *arg)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
termios_printf ("ioctl (%x)", cmd);
|
2011-10-16 06:37:30 +08:00
|
|
|
int res = fhandler_termios::ioctl (cmd, arg);
|
2011-10-12 07:20:38 +08:00
|
|
|
if (res <= 0)
|
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-08-31 11:35:50 +08:00
|
|
|
if (myself->pgid && get_ttyp ()->getpgid () != myself->pgid
|
2011-10-20 22:02:54 +08:00
|
|
|
&& (unsigned) myself->ctty == FHDEV (DEV_PTYS_MAJOR, get_unit ())
|
2011-05-29 02:17:09 +08:00
|
|
|
&& (get_ttyp ()->ti.c_lflag & TOSTOP))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* background process */
|
2005-11-14 12:28:45 +08:00
|
|
|
termios_printf ("bg ioctl pgid %d, tpgid %d, %s", myself->pgid,
|
|
|
|
get_ttyp ()->getpgid (), myctty ());
|
2002-10-20 12:15:50 +08:00
|
|
|
raise (SIGTTOU);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-05-12 13:06:43 +08:00
|
|
|
|
2003-10-24 09:13:22 +08:00
|
|
|
int retval;
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case TIOCGWINSZ:
|
|
|
|
case TIOCSWINSZ:
|
|
|
|
break;
|
2010-10-24 02:07:08 +08:00
|
|
|
case TIOCGPGRP:
|
|
|
|
{
|
|
|
|
pid_t pid = this->tcgetpgrp ();
|
|
|
|
if (pid < 0)
|
|
|
|
retval = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*((pid_t *) arg) = pid;
|
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
case TIOCSPGRP:
|
|
|
|
retval = this->tcsetpgrp ((pid_t) arg);
|
|
|
|
goto out;
|
2011-07-23 02:50:42 +08:00
|
|
|
case FIONREAD:
|
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
DWORD n;
|
|
|
|
if (!bytes_available (n))
|
2011-07-23 02:50:42 +08:00
|
|
|
{
|
2011-07-25 23:19:35 +08:00
|
|
|
set_errno (EINVAL);
|
2011-07-23 02:50:42 +08:00
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
*(int *) arg = (int) n;
|
2011-07-23 02:50:42 +08:00
|
|
|
retval = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto out;
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
2011-07-22 04:21:46 +08:00
|
|
|
return fhandler_base::ioctl (cmd, arg);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-05-12 13:06:43 +08:00
|
|
|
|
|
|
|
acquire_output_mutex (INFINITE);
|
|
|
|
|
|
|
|
get_ttyp ()->cmd = cmd;
|
|
|
|
get_ttyp ()->ioctl_retval = 0;
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case TIOCGWINSZ:
|
|
|
|
get_ttyp ()->arg.winsize = get_ttyp ()->winsize;
|
2002-11-04 09:10:38 +08:00
|
|
|
*(struct winsize *) arg = get_ttyp ()->arg.winsize;
|
2000-05-12 13:06:43 +08:00
|
|
|
get_ttyp ()->winsize = get_ttyp ()->arg.winsize;
|
|
|
|
break;
|
|
|
|
case TIOCSWINSZ:
|
2002-11-04 09:10:38 +08:00
|
|
|
if (get_ttyp ()->winsize.ws_row != ((struct winsize *) arg)->ws_row
|
|
|
|
|| get_ttyp ()->winsize.ws_col != ((struct winsize *) arg)->ws_col)
|
|
|
|
{
|
2004-01-21 14:28:35 +08:00
|
|
|
get_ttyp ()->arg.winsize = *(struct winsize *) arg;
|
2011-06-15 05:48:43 +08:00
|
|
|
get_ttyp ()->winsize = *(struct winsize *) arg;
|
|
|
|
killsys (-get_ttyp ()->getpgid (), SIGWINCH);
|
2002-11-04 09:10:38 +08:00
|
|
|
}
|
2000-05-12 13:06:43 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
release_output_mutex ();
|
2003-10-24 09:13:22 +08:00
|
|
|
retval = get_ttyp ()->ioctl_retval;
|
2003-09-27 11:14:07 +08:00
|
|
|
if (retval < 0)
|
|
|
|
{
|
|
|
|
set_errno (-retval);
|
|
|
|
retval = -1;
|
|
|
|
}
|
2003-10-24 09:13:22 +08:00
|
|
|
|
|
|
|
out:
|
2011-12-04 05:43:27 +08:00
|
|
|
termios_printf ("%d = ioctl(%x)", retval, cmd);
|
2003-09-27 11:14:07 +08:00
|
|
|
return retval;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
int __reg2
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fstat (struct __stat64 *st)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
fhandler_base::fstat (st);
|
|
|
|
|
|
|
|
bool to_close = false;
|
|
|
|
if (!input_available_event)
|
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
shared_name (buf, INPUT_AVAILABLE_EVENT, get_unit ());
|
|
|
|
input_available_event = OpenEvent (READ_CONTROL, TRUE, buf);
|
|
|
|
if (input_available_event)
|
|
|
|
to_close = true;
|
|
|
|
}
|
|
|
|
if (!input_available_event
|
|
|
|
|| get_object_attribute (input_available_event, &st->st_uid, &st->st_gid,
|
|
|
|
&st->st_mode))
|
|
|
|
{
|
|
|
|
/* If we can't access the ACL, or if the tty doesn't actually exist,
|
2011-06-06 13:02:13 +08:00
|
|
|
then fake uid and gid to strict, system-like values. */
|
2010-04-20 03:52:43 +08:00
|
|
|
st->st_mode = S_IFCHR | S_IRUSR | S_IWUSR;
|
|
|
|
st->st_uid = 18;
|
|
|
|
st->st_gid = 544;
|
|
|
|
}
|
|
|
|
if (to_close)
|
|
|
|
CloseHandle (input_available_event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function for fchmod and fchown, which just opens all handles
|
|
|
|
and signals success via bool return. */
|
|
|
|
bool
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fch_open_handles ()
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
|
2011-06-04 08:12:29 +08:00
|
|
|
_tc = cygwin_shared->tty[get_unit ()];
|
2010-04-20 03:52:43 +08:00
|
|
|
shared_name (buf, INPUT_AVAILABLE_EVENT, get_unit ());
|
|
|
|
input_available_event = OpenEvent (READ_CONTROL | WRITE_DAC | WRITE_OWNER,
|
|
|
|
TRUE, buf);
|
|
|
|
output_mutex = get_ttyp ()->open_output_mutex (WRITE_DAC | WRITE_OWNER);
|
|
|
|
input_mutex = get_ttyp ()->open_input_mutex (WRITE_DAC | WRITE_OWNER);
|
|
|
|
inuse = get_ttyp ()->open_inuse (WRITE_DAC | WRITE_OWNER);
|
|
|
|
if (!input_available_event || !output_mutex || !input_mutex || !inuse)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function for fchmod and fchown, which sets the new security
|
2011-06-15 05:48:43 +08:00
|
|
|
descriptor on all objects representing the pty. */
|
2010-04-20 03:52:43 +08:00
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fch_set_sd (security_descriptor &sd, bool chown)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
security_descriptor sd_old;
|
|
|
|
|
|
|
|
get_object_sd (input_available_event, sd_old);
|
2010-04-20 04:00:18 +08:00
|
|
|
if (!set_object_sd (input_available_event, sd, chown)
|
2010-04-20 03:52:43 +08:00
|
|
|
&& !set_object_sd (output_mutex, sd, chown)
|
|
|
|
&& !set_object_sd (input_mutex, sd, chown)
|
2011-06-15 05:48:43 +08:00
|
|
|
&& !set_object_sd (inuse, sd, chown))
|
2010-04-20 03:52:43 +08:00
|
|
|
return 0;
|
|
|
|
set_object_sd (input_available_event, sd_old, chown);
|
|
|
|
set_object_sd (output_mutex, sd_old, chown);
|
|
|
|
set_object_sd (input_mutex, sd_old, chown);
|
|
|
|
set_object_sd (inuse, sd_old, chown);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Helper function for fchmod and fchown, which closes all object handles in
|
2011-06-15 05:48:43 +08:00
|
|
|
the pty. */
|
2010-04-20 03:52:43 +08:00
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fch_close_handles ()
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
close_maybe (get_io_handle ());
|
|
|
|
close_maybe (get_output_handle ());
|
|
|
|
close_maybe (input_available_event);
|
|
|
|
close_maybe (output_mutex);
|
|
|
|
close_maybe (input_mutex);
|
|
|
|
close_maybe (inuse);
|
|
|
|
}
|
|
|
|
|
|
|
|
int __stdcall
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fchmod (mode_t mode)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
bool to_close = false;
|
|
|
|
security_descriptor sd;
|
|
|
|
__uid32_t uid;
|
|
|
|
__gid32_t gid;
|
|
|
|
|
|
|
|
if (!input_available_event)
|
|
|
|
{
|
|
|
|
to_close = true;
|
|
|
|
if (!fch_open_handles ())
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
|
2011-04-28 17:30:36 +08:00
|
|
|
RtlCreateSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!get_object_attribute (input_available_event, &uid, &gid, NULL)
|
|
|
|
&& !create_object_sd_from_attribute (NULL, uid, gid, S_IFCHR | mode, sd))
|
|
|
|
ret = fch_set_sd (sd, false);
|
|
|
|
errout:
|
|
|
|
if (to_close)
|
|
|
|
fch_close_handles ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int __stdcall
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fchown (__uid32_t uid, __gid32_t gid)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
bool to_close = false;
|
2010-11-19 02:55:10 +08:00
|
|
|
mode_t mode = 0;
|
2010-04-20 03:52:43 +08:00
|
|
|
__uid32_t o_uid;
|
|
|
|
__gid32_t o_gid;
|
|
|
|
security_descriptor sd;
|
|
|
|
|
|
|
|
if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
|
|
|
|
return 0;
|
|
|
|
if (!input_available_event)
|
|
|
|
{
|
|
|
|
to_close = true;
|
|
|
|
if (!fch_open_handles ())
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
|
2011-04-28 17:30:36 +08:00
|
|
|
RtlCreateSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!get_object_attribute (input_available_event, &o_uid, &o_gid, &mode))
|
|
|
|
{
|
|
|
|
if ((uid == ILLEGAL_UID || uid == o_uid)
|
|
|
|
&& (gid == ILLEGAL_GID || gid == o_gid))
|
|
|
|
ret = 0;
|
|
|
|
else if (!create_object_sd_from_attribute (input_available_event,
|
|
|
|
uid, gid, S_IFCHR | mode, sd))
|
|
|
|
ret = fch_set_sd (sd, true);
|
|
|
|
}
|
|
|
|
errout:
|
|
|
|
if (to_close)
|
|
|
|
fch_close_handles ();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/*******************************************************
|
|
|
|
fhandler_pty_master
|
|
|
|
*/
|
2011-10-16 06:37:30 +08:00
|
|
|
fhandler_pty_master::fhandler_pty_master (int unit)
|
|
|
|
: fhandler_pty_common (), pktmode (0), master_ctl (NULL),
|
|
|
|
master_thread (NULL), from_master (NULL), to_master (NULL),
|
|
|
|
dwProcessId (0), need_nl (0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
if (unit >= 0)
|
2011-10-20 22:02:54 +08:00
|
|
|
dev ().parse (DEV_PTYM_MAJOR, unit);
|
2011-10-16 06:37:30 +08:00
|
|
|
else if (!setup ())
|
2011-10-20 22:02:54 +08:00
|
|
|
{
|
|
|
|
dev ().parse (FH_ERROR);
|
2011-12-18 07:39:47 +08:00
|
|
|
return;
|
2011-10-20 22:02:54 +08:00
|
|
|
}
|
|
|
|
set_name ("/dev/ptmx");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_pty_master::open (int flags, mode_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-24 10:07:58 +08:00
|
|
|
set_open_status ();
|
2011-05-06 06:30:53 +08:00
|
|
|
dwProcessId = GetCurrentProcessId ();
|
2011-10-16 06:37:30 +08:00
|
|
|
return 1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
void
|
|
|
|
fhandler_pty_master::open_setup (int flags)
|
|
|
|
{
|
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
|
|
|
char buf[sizeof ("opened pty master for ptyNNNNNNNNNNN")];
|
|
|
|
__small_sprintf (buf, "opened pty master for pty%d", get_unit ());
|
2006-06-04 04:32:07 +08:00
|
|
|
report_tty_counts (this, buf, "");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2005-08-19 04:17:10 +08:00
|
|
|
_off64_t
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_common::lseek (_off64_t, int)
|
2005-08-19 04:17:10 +08:00
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_common::close ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
termios_printf ("pty%d <%p,%p> closing", get_unit (), get_handle (), get_output_handle ());
|
2001-03-04 23:34:25 +08:00
|
|
|
if (!ForceCloseHandle (input_mutex))
|
|
|
|
termios_printf ("CloseHandle (input_mutex<%p>), %E", input_mutex);
|
2002-02-23 03:33:41 +08:00
|
|
|
if (!ForceCloseHandle (output_mutex))
|
|
|
|
termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex);
|
2005-08-18 00:10:48 +08:00
|
|
|
if (!ForceCloseHandle1 (get_handle (), from_pty))
|
|
|
|
termios_printf ("CloseHandle (get_handle ()<%p>), %E", get_handle ());
|
|
|
|
if (!ForceCloseHandle1 (get_output_handle (), to_pty))
|
|
|
|
termios_printf ("CloseHandle (get_output_handle ()<%p>), %E", get_output_handle ());
|
2001-03-20 02:27:37 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
void
|
|
|
|
fhandler_pty_master::cleanup ()
|
|
|
|
{
|
|
|
|
report_tty_counts (this, "closing master", "");
|
2011-10-16 06:37:30 +08:00
|
|
|
if (archetype)
|
|
|
|
from_master = to_master = NULL;
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
|
|
|
fhandler_pty_master::close ()
|
|
|
|
{
|
2006-06-12 22:56:31 +08:00
|
|
|
termios_printf ("closing from_master(%p)/to_master(%p) since we own them(%d)",
|
2011-05-06 06:30:53 +08:00
|
|
|
from_master, to_master, dwProcessId);
|
2009-06-15 07:42:09 +08:00
|
|
|
if (cygwin_finished_initializing)
|
|
|
|
{
|
2011-05-06 06:30:53 +08:00
|
|
|
if (master_ctl && get_ttyp ()->master_pid == myself->pid)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
pipe_request req = { (DWORD) -1 };
|
|
|
|
pipe_reply repl;
|
|
|
|
DWORD len;
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
|
2012-02-14 19:27:43 +08:00
|
|
|
&cygheap->installation_key, get_unit ());
|
2010-04-20 03:52:43 +08:00
|
|
|
CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl, &len, 500);
|
2011-05-06 06:30:53 +08:00
|
|
|
CloseHandle (master_ctl);
|
|
|
|
master_thread->detach ();
|
2010-04-20 03:52:43 +08:00
|
|
|
}
|
2009-06-15 07:42:09 +08:00
|
|
|
}
|
2011-10-16 06:37:30 +08:00
|
|
|
|
|
|
|
if (!ForceCloseHandle (from_master))
|
|
|
|
termios_printf ("error closing from_master %p, %E", from_master);
|
|
|
|
if (!ForceCloseHandle (to_master))
|
|
|
|
termios_printf ("error closing from_master %p, %E", to_master);
|
|
|
|
from_master = to_master = NULL;
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_common::close ();
|
2005-08-18 00:10:48 +08:00
|
|
|
|
2011-11-14 09:29:49 +08:00
|
|
|
if (have_execed || get_ttyp ()->master_pid != myself->pid)
|
|
|
|
termios_printf ("not clearing: %d, master_pid %d", have_execed, get_ttyp ()->master_pid);
|
2006-06-04 04:32:07 +08:00
|
|
|
else
|
2011-12-10 00:02:56 +08:00
|
|
|
{
|
|
|
|
get_ttyp ()->set_master_closed ();
|
|
|
|
SetEvent (input_available_event);
|
|
|
|
}
|
|
|
|
if (!ForceCloseHandle (input_available_event))
|
|
|
|
termios_printf ("CloseHandle (input_available_event<%p>), %E", input_available_event);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-18 07:39:47 +08:00
|
|
|
/* This is just to catch error conditions. Since the constructor
|
|
|
|
actually opens some handles, and stat() does not open an fd, they need
|
2011-10-16 06:37:30 +08:00
|
|
|
to be closed when the fhandler goes away. */
|
|
|
|
fhandler_pty_master::~fhandler_pty_master ()
|
|
|
|
{
|
|
|
|
if (from_master && to_master)
|
|
|
|
close_with_arch ();
|
|
|
|
}
|
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_pty_master::write (const void *ptr, size_t len)
|
|
|
|
{
|
2002-12-20 09:38:55 +08:00
|
|
|
int i;
|
2002-12-06 00:24:52 +08:00
|
|
|
char *p = (char *) ptr;
|
2011-06-04 08:12:29 +08:00
|
|
|
termios ti = tc ()->ti;
|
2002-12-27 11:50:29 +08:00
|
|
|
|
2011-05-06 03:43:04 +08:00
|
|
|
bg_check_types bg = bg_check (SIGTTOU);
|
|
|
|
if (bg <= bg_eof)
|
|
|
|
return (ssize_t) bg;
|
|
|
|
|
|
|
|
push_process_state process_state (PID_TTYOU);
|
|
|
|
|
2002-12-27 11:50:29 +08:00
|
|
|
for (i = 0; i < (int) len; i++)
|
2002-12-20 09:38:55 +08:00
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
line_edit_status status = line_edit (p++, 1, ti);
|
2002-12-21 12:38:12 +08:00
|
|
|
if (status > line_edit_signalled)
|
|
|
|
{
|
|
|
|
if (status != line_edit_pipe_full)
|
|
|
|
i = -1;
|
|
|
|
break;
|
|
|
|
}
|
2002-12-20 09:38:55 +08:00
|
|
|
}
|
2002-12-06 00:24:52 +08:00
|
|
|
return i;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-12-14 12:01:32 +08:00
|
|
|
void __stdcall
|
|
|
|
fhandler_pty_master::read (void *ptr, size_t& len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-05-06 03:43:04 +08:00
|
|
|
bg_check_types bg = bg_check (SIGTTIN);
|
|
|
|
if (bg <= bg_eof)
|
|
|
|
{
|
|
|
|
len = (size_t) bg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
push_process_state process_state (PID_TTYIN);
|
2003-09-08 02:27:54 +08:00
|
|
|
len = (size_t) process_slave_output ((char *) ptr, len, pktmode);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_pty_master::tcgetattr (struct termios *t)
|
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
*t = cygwin_shared->tty[get_unit ()]->ti;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_pty_master::tcsetattr (int, const struct termios *t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
cygwin_shared->tty[get_unit ()]->ti = *t;
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-09-19 02:54:48 +08:00
|
|
|
fhandler_pty_master::tcflush (int queue)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-09-19 02:54:48 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
termios_printf ("tcflush(%d) handle %p", queue, get_handle ());
|
|
|
|
|
|
|
|
if (queue == TCIFLUSH || queue == TCIOFLUSH)
|
|
|
|
ret = process_slave_output (NULL, OUT_BUFFER_SIZE, 0);
|
|
|
|
else if (queue == TCIFLUSH || queue == TCIOFLUSH)
|
|
|
|
{
|
|
|
|
/* do nothing for now. */
|
|
|
|
}
|
|
|
|
|
|
|
|
termios_printf ("%d=tcflush(%d)", ret, queue);
|
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
|
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
int res = fhandler_termios::ioctl (cmd, arg);
|
2011-10-12 07:20:38 +08:00
|
|
|
if (res <= 0)
|
|
|
|
return res;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (cmd)
|
|
|
|
{
|
2010-10-24 02:07:08 +08:00
|
|
|
case TIOCPKT:
|
|
|
|
pktmode = *(int *) arg;
|
|
|
|
break;
|
|
|
|
case TIOCGWINSZ:
|
|
|
|
*(struct winsize *) arg = get_ttyp ()->winsize;
|
|
|
|
break;
|
|
|
|
case TIOCSWINSZ:
|
|
|
|
if (get_ttyp ()->winsize.ws_row != ((struct winsize *) arg)->ws_row
|
|
|
|
|| get_ttyp ()->winsize.ws_col != ((struct winsize *) arg)->ws_col)
|
|
|
|
{
|
|
|
|
get_ttyp ()->winsize = *(struct winsize *) arg;
|
|
|
|
killsys (-get_ttyp ()->getpgid (), SIGWINCH);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TIOCGPGRP:
|
|
|
|
*((pid_t *) arg) = this->tcgetpgrp ();
|
|
|
|
break;
|
|
|
|
case TIOCSPGRP:
|
|
|
|
return this->tcsetpgrp ((pid_t) arg);
|
2011-07-23 02:50:42 +08:00
|
|
|
case FIONREAD:
|
|
|
|
{
|
2012-04-05 10:54:51 +08:00
|
|
|
DWORD n;
|
|
|
|
if (!::bytes_available (n, to_master))
|
2011-07-23 02:50:42 +08:00
|
|
|
{
|
2011-07-25 23:19:35 +08:00
|
|
|
set_errno (EINVAL);
|
2011-07-23 02:50:42 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2012-05-04 11:00:43 +08:00
|
|
|
*(int *) arg = (int) n;
|
2011-07-23 02:50:42 +08:00
|
|
|
}
|
2010-10-24 02:07:08 +08:00
|
|
|
break;
|
|
|
|
default:
|
2011-07-23 02:50:42 +08:00
|
|
|
return fhandler_base::ioctl (cmd, arg);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-08 04:05:49 +08:00
|
|
|
int
|
|
|
|
fhandler_pty_master::ptsname_r (char *buf, size_t buflen)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-11-08 04:05:49 +08:00
|
|
|
char tmpbuf[TTY_NAME_MAX];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-11-08 14:26:15 +08:00
|
|
|
__ptsname (tmpbuf, get_unit ());
|
2011-11-08 04:05:49 +08:00
|
|
|
if (buflen <= strlen (tmpbuf))
|
|
|
|
{
|
|
|
|
set_errno (ERANGE);
|
|
|
|
return ERANGE;
|
|
|
|
}
|
|
|
|
strcpy (buf, tmpbuf);
|
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_common::set_close_on_exec (bool val)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2006-06-02 23:41:34 +08:00
|
|
|
// Cygwin processes will handle this specially on exec.
|
|
|
|
close_on_exec (val);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-03-04 12:07:34 +08:00
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fixup_after_fork (HANDLE parent)
|
2003-03-04 12:07:34 +08:00
|
|
|
{
|
2006-06-02 23:41:34 +08:00
|
|
|
// fork_fixup (parent, inuse, "inuse");
|
2011-06-15 05:48:43 +08:00
|
|
|
// fhandler_pty_common::fixup_after_fork (parent);
|
2005-11-14 12:28:45 +08:00
|
|
|
report_tty_counts (this, "inherited", "");
|
2003-03-04 12:07:34 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
void
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_slave::fixup_after_exec ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2006-06-03 14:35:10 +08:00
|
|
|
if (!close_on_exec ())
|
2006-06-02 23:41:34 +08:00
|
|
|
fixup_after_fork (NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2010-04-20 03:52:43 +08:00
|
|
|
/* This thread function handles the master control pipe. It waits for a
|
|
|
|
client to connect. Then it checks if the client process has permissions
|
|
|
|
to access the tty handles. If so, it opens the client process and
|
|
|
|
duplicates the handles into that process. If that fails, it sends a reply
|
|
|
|
with at least one handle set to NULL and an error code. Last but not
|
|
|
|
least, the client is disconnected and the thread waits for the next client.
|
|
|
|
|
|
|
|
A special case is when the master side of the tty is about to be closed.
|
|
|
|
The client side is the fhandler_pty_master::close function and it sends
|
|
|
|
a PID -1 in that case. On Vista and later a check is performed that the
|
|
|
|
request to leave really comes from the master process itself. On earlier
|
|
|
|
OSes there's no function to check for the PID of the client process so
|
|
|
|
we have to trust the client side.
|
|
|
|
|
2010-10-25 02:50:57 +08:00
|
|
|
Since there's always only one pipe instance, there's a chance that clients
|
|
|
|
have to wait to connect to the master control pipe. Therefore the client
|
|
|
|
calls to CallNamedPipe should have a big enough timeout value. For now this
|
2010-04-20 03:52:43 +08:00
|
|
|
is 500ms. Hope that's enough. */
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
fhandler_pty_master::pty_master_thread ()
|
|
|
|
{
|
|
|
|
bool exit = false;
|
|
|
|
GENERIC_MAPPING map = { EVENT_QUERY_STATE, EVENT_MODIFY_STATE, 0,
|
|
|
|
EVENT_QUERY_STATE | EVENT_MODIFY_STATE };
|
|
|
|
pipe_request req;
|
|
|
|
DWORD len;
|
|
|
|
security_descriptor sd;
|
|
|
|
HANDLE token;
|
|
|
|
PRIVILEGE_SET ps;
|
|
|
|
DWORD pid;
|
2011-04-29 17:48:25 +08:00
|
|
|
NTSTATUS status;
|
2010-04-20 03:52:43 +08:00
|
|
|
|
|
|
|
termios_printf ("Entered");
|
2011-04-29 17:48:25 +08:00
|
|
|
while (!exit && (ConnectNamedPipe (master_ctl, NULL)
|
|
|
|
|| GetLastError () == ERROR_PIPE_CONNECTED))
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
pipe_reply repl = { NULL, NULL, 0 };
|
|
|
|
bool deimp = false;
|
2011-04-29 17:48:25 +08:00
|
|
|
NTSTATUS allow = STATUS_ACCESS_DENIED;
|
2010-04-20 03:52:43 +08:00
|
|
|
ACCESS_MASK access = EVENT_MODIFY_STATE;
|
|
|
|
HANDLE client = NULL;
|
|
|
|
|
|
|
|
if (!ReadFile (master_ctl, &req, sizeof req, &len, NULL))
|
2011-06-06 13:02:13 +08:00
|
|
|
{
|
2010-04-20 03:52:43 +08:00
|
|
|
termios_printf ("ReadFile, %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
/* This function is only available since Vista, unfortunately.
|
|
|
|
In earlier OSes we simply have to believe that the client
|
|
|
|
has no malicious intent (== sends arbitrary PIDs). */
|
|
|
|
if (!GetNamedPipeClientProcessId (master_ctl, &pid))
|
|
|
|
pid = req.pid;
|
|
|
|
if (get_object_sd (input_available_event, sd))
|
|
|
|
{
|
|
|
|
termios_printf ("get_object_sd, %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
cygheap->user.deimpersonate ();
|
|
|
|
deimp = true;
|
|
|
|
if (!ImpersonateNamedPipeClient (master_ctl))
|
|
|
|
{
|
|
|
|
termios_printf ("ImpersonateNamedPipeClient, %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
2011-04-29 17:48:25 +08:00
|
|
|
status = NtOpenThreadToken (GetCurrentThread (), TOKEN_QUERY, TRUE,
|
|
|
|
&token);
|
|
|
|
if (!NT_SUCCESS (status))
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
2011-04-29 17:48:25 +08:00
|
|
|
termios_printf ("NtOpenThreadToken, %p", status);
|
|
|
|
SetLastError (RtlNtStatusToDosError (status));
|
2010-04-20 03:52:43 +08:00
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
len = sizeof ps;
|
2011-04-29 17:48:25 +08:00
|
|
|
status = NtAccessCheck (sd, token, access, &map, &ps, &len, &access,
|
|
|
|
&allow);
|
|
|
|
NtClose (token);
|
|
|
|
if (!NT_SUCCESS (status))
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
2011-04-29 17:48:25 +08:00
|
|
|
termios_printf ("NtAccessCheck, %p", status);
|
|
|
|
SetLastError (RtlNtStatusToDosError (status));
|
2010-04-20 03:52:43 +08:00
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
if (!RevertToSelf ())
|
|
|
|
{
|
|
|
|
termios_printf ("RevertToSelf, %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
if (req.pid == (DWORD) -1) /* Request to finish thread. */
|
|
|
|
{
|
|
|
|
/* Pre-Vista: Just believe in the good of the client process.
|
|
|
|
Post-Vista: Check if the requesting process is the master
|
|
|
|
process itself. */
|
|
|
|
if (pid == (DWORD) -1 || pid == GetCurrentProcessId ())
|
|
|
|
exit = true;
|
|
|
|
goto reply;
|
|
|
|
}
|
2011-04-29 17:48:25 +08:00
|
|
|
if (NT_SUCCESS (allow))
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
|
|
|
client = OpenProcess (PROCESS_DUP_HANDLE, FALSE, pid);
|
|
|
|
if (!client)
|
|
|
|
{
|
|
|
|
termios_printf ("OpenProcess, %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
if (!DuplicateHandle (GetCurrentProcess (), from_master,
|
|
|
|
client, &repl.from_master,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
{
|
|
|
|
termios_printf ("DuplicateHandle (from_master), %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
if (!DuplicateHandle (GetCurrentProcess (), to_master,
|
|
|
|
client, &repl.to_master,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
{
|
|
|
|
termios_printf ("DuplicateHandle (to_master), %E");
|
|
|
|
goto reply;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
reply:
|
|
|
|
repl.error = GetLastError ();
|
|
|
|
if (client)
|
|
|
|
CloseHandle (client);
|
|
|
|
if (deimp)
|
|
|
|
cygheap->user.reimpersonate ();
|
|
|
|
sd.free ();
|
|
|
|
termios_printf ("Reply: from %p, to %p, error %lu",
|
|
|
|
repl.from_master, repl.to_master, repl.error );
|
|
|
|
if (!WriteFile (master_ctl, &repl, sizeof repl, &len, NULL))
|
|
|
|
termios_printf ("WriteFile, %E");
|
|
|
|
if (!DisconnectNamedPipe (master_ctl))
|
|
|
|
termios_printf ("DisconnectNamedPipe, %E");
|
|
|
|
}
|
|
|
|
termios_printf ("Leaving");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI
|
2011-05-06 06:30:53 +08:00
|
|
|
pty_master_thread (VOID *arg)
|
|
|
|
{
|
2010-04-20 03:52:43 +08:00
|
|
|
return ((fhandler_pty_master *) arg)->pty_master_thread ();
|
2011-05-06 06:30:53 +08:00
|
|
|
}
|
2006-06-02 23:41:34 +08:00
|
|
|
|
|
|
|
bool
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_master::setup ()
|
2006-06-02 23:41:34 +08:00
|
|
|
{
|
2008-03-23 05:04:16 +08:00
|
|
|
int res;
|
2010-04-20 03:52:43 +08:00
|
|
|
security_descriptor sd;
|
|
|
|
SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE };
|
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
/* Find an unallocated pty to use. */
|
|
|
|
int unit = cygwin_shared->tty.allocate (from_master, get_output_handle ());
|
|
|
|
if (unit < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ProtectHandle1 (get_output_handle (), to_pty);
|
|
|
|
|
|
|
|
tty& t = *cygwin_shared->tty[unit];
|
|
|
|
_tc = (tty_min *) &t;
|
2006-06-04 05:44:01 +08:00
|
|
|
|
2011-06-04 08:12:29 +08:00
|
|
|
tcinit (true); /* Set termios information. Force initialization. */
|
2006-06-02 23:41:34 +08:00
|
|
|
|
|
|
|
const char *errstr = NULL;
|
|
|
|
DWORD pipe_mode = PIPE_NOWAIT;
|
|
|
|
|
2008-07-27 03:35:21 +08:00
|
|
|
if (!SetNamedPipeHandleState (get_output_handle (), &pipe_mode, NULL, NULL))
|
|
|
|
termios_printf ("can't set output_handle(%p) to non-blocking mode",
|
|
|
|
get_output_handle ());
|
2006-06-02 23:41:34 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
char pipename[sizeof("ptyNNNN-from-master")];
|
|
|
|
__small_sprintf (pipename, "pty%d-to-master", unit);
|
2011-11-24 02:56:57 +08:00
|
|
|
res = fhandler_pipe::create (&sec_none, &get_io_handle (), &to_master,
|
|
|
|
fhandler_pty_common::pipesize, pipename, 0);
|
2008-03-23 05:04:16 +08:00
|
|
|
if (res)
|
2006-06-02 23:41:34 +08:00
|
|
|
{
|
|
|
|
errstr = "output pipe";
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2011-07-04 13:08:28 +08:00
|
|
|
ProtectHandle1 (get_io_handle (), from_pty);
|
2006-06-02 23:41:34 +08:00
|
|
|
|
2010-04-20 03:52:43 +08:00
|
|
|
/* Create security attribute. Default permissions are 0620. */
|
|
|
|
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
|
2011-04-28 17:30:36 +08:00
|
|
|
RtlCreateSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!create_object_sd_from_attribute (NULL, myself->uid, myself->gid,
|
|
|
|
S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP,
|
|
|
|
sd))
|
|
|
|
sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR) sd;
|
2006-06-02 23:41:34 +08:00
|
|
|
|
2010-04-20 03:52:43 +08:00
|
|
|
/* Carefully check that the input_available_event didn't already exist.
|
|
|
|
This is a measure to make sure that the event security descriptor
|
|
|
|
isn't occupied by a malicious process. We must make sure that the
|
|
|
|
event's security descriptor is what we expect it to be. */
|
|
|
|
if (!(input_available_event = t.get_event (errstr = INPUT_AVAILABLE_EVENT,
|
|
|
|
&sa, TRUE))
|
|
|
|
|| GetLastError () == ERROR_ALREADY_EXISTS)
|
2006-06-02 23:41:34 +08:00
|
|
|
goto err;
|
|
|
|
|
2007-12-06 00:50:18 +08:00
|
|
|
char buf[MAX_PATH];
|
2011-10-16 06:37:30 +08:00
|
|
|
errstr = shared_name (buf, OUTPUT_MUTEX, unit);
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!(output_mutex = CreateMutex (&sa, FALSE, buf)))
|
2006-06-02 23:41:34 +08:00
|
|
|
goto err;
|
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
errstr = shared_name (buf, INPUT_MUTEX, unit);
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!(input_mutex = CreateMutex (&sa, FALSE, buf)))
|
2006-06-02 23:41:34 +08:00
|
|
|
goto err;
|
|
|
|
|
2010-09-28 18:13:19 +08:00
|
|
|
/* Create master control pipe which allows the master to duplicate
|
|
|
|
the pty pipe handles to processes which deserve it. */
|
2011-06-15 05:48:43 +08:00
|
|
|
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-pty%d-master-ctl",
|
2012-02-14 19:27:43 +08:00
|
|
|
&cygheap->installation_key, unit);
|
2010-09-28 18:13:19 +08:00
|
|
|
master_ctl = CreateNamedPipe (buf, PIPE_ACCESS_DUPLEX,
|
|
|
|
PIPE_WAIT | PIPE_TYPE_MESSAGE
|
|
|
|
| PIPE_READMODE_MESSAGE, 1, 4096, 4096,
|
|
|
|
0, &sec_all_nih);
|
|
|
|
if (master_ctl == INVALID_HANDLE_VALUE)
|
2010-04-20 03:52:43 +08:00
|
|
|
{
|
2010-09-28 18:13:19 +08:00
|
|
|
errstr = "pty master control pipe";
|
|
|
|
goto err;
|
|
|
|
}
|
2011-12-04 05:43:27 +08:00
|
|
|
master_thread = new cygthread (::pty_master_thread, this, "ptym");
|
2010-09-28 18:13:19 +08:00
|
|
|
if (!master_thread)
|
|
|
|
{
|
|
|
|
errstr = "pty master control thread";
|
|
|
|
goto err;
|
2010-04-20 03:52:43 +08:00
|
|
|
}
|
|
|
|
|
2006-06-02 23:41:34 +08:00
|
|
|
t.from_master = from_master;
|
|
|
|
t.to_master = to_master;
|
|
|
|
t.winsize.ws_col = 80;
|
|
|
|
t.winsize.ws_row = 25;
|
|
|
|
t.master_pid = myself->pid;
|
|
|
|
|
2011-10-20 22:02:54 +08:00
|
|
|
dev ().parse (DEV_PTYM_MAJOR, unit);
|
2011-10-16 06:37:30 +08:00
|
|
|
|
|
|
|
termios_printf ("this %p, pty%d opened - from_pty %p, to_pty %p", this, unit,
|
2006-06-02 23:41:34 +08:00
|
|
|
get_io_handle (), get_output_handle ());
|
|
|
|
return true;
|
|
|
|
|
|
|
|
err:
|
|
|
|
__seterrno ();
|
|
|
|
close_maybe (get_io_handle ());
|
|
|
|
close_maybe (get_output_handle ());
|
|
|
|
close_maybe (input_available_event);
|
|
|
|
close_maybe (output_mutex);
|
|
|
|
close_maybe (input_mutex);
|
2006-06-03 14:35:10 +08:00
|
|
|
close_maybe (from_master);
|
|
|
|
close_maybe (to_master);
|
2010-04-20 03:52:43 +08:00
|
|
|
close_maybe (master_ctl);
|
2011-10-16 06:37:30 +08:00
|
|
|
termios_printf ("pty%d open failed - failed to create %s", unit, errstr);
|
2006-06-02 23:41:34 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_pty_master::fixup_after_fork (HANDLE parent)
|
|
|
|
{
|
|
|
|
DWORD wpid = GetCurrentProcessId ();
|
2011-06-15 05:48:43 +08:00
|
|
|
fhandler_pty_master *arch = (fhandler_pty_master *) archetype;
|
2006-06-02 23:41:34 +08:00
|
|
|
if (arch->dwProcessId != wpid)
|
|
|
|
{
|
|
|
|
tty& t = *get_ttyp ();
|
|
|
|
if (myself->pid == t.master_pid)
|
|
|
|
{
|
|
|
|
t.from_master = arch->from_master;
|
|
|
|
t.to_master = arch->to_master;
|
|
|
|
}
|
|
|
|
arch->dwProcessId = wpid;
|
|
|
|
}
|
2006-06-03 15:17:53 +08:00
|
|
|
from_master = arch->from_master;
|
|
|
|
to_master = arch->to_master;
|
2006-06-02 23:41:34 +08:00
|
|
|
report_tty_counts (this, "inherited master", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_pty_master::fixup_after_exec ()
|
|
|
|
{
|
2006-06-03 14:35:10 +08:00
|
|
|
if (!close_on_exec ())
|
2006-06-02 23:41:34 +08:00
|
|
|
fixup_after_fork (spawn_info->parent);
|
2006-06-03 15:17:53 +08:00
|
|
|
else
|
|
|
|
from_master = to_master = NULL;
|
2006-06-02 23:41:34 +08:00
|
|
|
}
|