2000-02-18 03:38:33 +08:00
|
|
|
/* tty.cc
|
|
|
|
|
|
|
|
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"
|
2008-04-08 00:15:45 +08:00
|
|
|
#include "miscfuncs.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <utmp.h>
|
2000-09-08 10:56:55 +08:00
|
|
|
#include <sys/cygwin.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"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "cygheap.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
#include "shared_info.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
HANDLE NO_COPY tty_list::mutex = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-12-31 04:22:28 +08:00
|
|
|
extern "C" int
|
|
|
|
getpt (void)
|
|
|
|
{
|
|
|
|
return open ("/dev/ptmx", O_RDWR | O_NOCTTY);
|
|
|
|
}
|
|
|
|
|
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/version.h: Bump DLL version to 1.7.0.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* select.h: Remove.
* fhandler_socket.cc: Don't include select.h.
* select.cc: Ditto.
2006-07-25 Corinna Vinschen <corinna@vinschen.de>
* cygtls.h: Drop socket related includes.
(struct _local_storage): Remove exitsock and exitsock_sin. Add
select_sockevt.
* cygtls.cc: Accomodate above change throughout.
* fhandler.h (class fhandler_socket): Make wsock_evt public.
* fhandler_socket.cc (fhandler_socket::fhandler_socket): Accomodate
reordering members.
(fhandler_socket::evaluate_events): Drop FD_CONNECT event as soon as
it gets read once. Never remove FD_WRITE event here.
(fhandler_socket::wait_for_events): Wait 50 ms instead of INFINITE for
socket events.
(fhandler_socket::accept): Fix conditional. Set wsock_events members
of accepted socket to useful start values.
(fhandler_socket::recv_internal): Always drop FD_READ/FD_OOB events from
wsock_events after the call to WSARecvFrom.
(fhandler_socket::send_internal): Drop FD_WRITE event from wsock_events
if the call to WSASendTo fails with WSAEWOULDBLOCK. Fix return value
condition.
* select.cc (struct socketinf): Change to accomodate using socket event
handling.
(peek_socket): Use event handling for peeking socket.
(thread_socket): Ditto.
(start_thread_socket): Ditto.
(socket_cleanup): Same here.
* tlsoffsets.h: Regenerate.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Rearrange slightly to keep
event handling methods and members together. Drop owner status flag.
Split wait method. Rename event handling methods for readability.
* fhandler_socket.cc (struct wsa_event): Add owner field.
(LOCK_EVENTS): New macro.
(UNLOCK_EVENTS): Ditto.
(fhandler_socket::init_events): rename from prepare.
(fhandler_socket::evaluate_events): First half of former wait method.
Do everything but wait. Allow specifiying whether or not events from
event_mask should be erased from wsock_events->events. Simplify
OOB handling. Allow sending SIGURG to any process (group).
(fhandler_socket::wait_for_events): Second half of former wait method.
Call evaluate_events and wait in a loop if socket is blocking.
(fhandler_socket::release_events): Rename from release.
(fhandler_socket::connect): Accomodate above name changes.
(fhandler_socket::accept): Ditto.
(fhandler_socket::recv_internal): Ditto.
(fhandler_socket::send_internal): Ditto.
(fhandler_socket::close): Ditto.
(fhandler_socket::fcntl): Always set owner to given input value on
F_SETOWN. Handle F_GETOWN.
* net.cc (fdsock): Accomodate above name changes.
2006-07-20 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Set Winsock errno to
WSAEWOULDBLOCK instead of WSAEINPROGRESS.
2006-07-18 Brian Ford <Brian.Ford@FlightSafety.com>
Corinna Vinschen <corinna@vinschen.de>
* winsup.h (mmap_region_status): New enum.
(mmap_is_attached_or_noreserve_page): Adjust prototype and rename
as below.
* mmap.cc (mmap_is_attached_or_noreserve_page): Rename
mmap_is_attached_or_noreserve. Add region length parameter.
Return enum above.
* exceptions.cc (_cygtls::handle_exceptions): Accomodate above.
* fhandler.cc (fhandler_base::raw_read): Call above for NOACCESS
errors and retry on success to allow reads into untouched
MAP_NORESERVE buffers.
2006-07-18 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din (posix_openpt): Export.
* tty.cc (posix_openpt): New function.
* include/cygwin/stdlib.h (posix_openpt): Declare.
* include/cygwin/version.h: Bump API minor number.
2006-07-14 Corinna Vinschen <corinna@vinschen.de>
* security.cc (get_token_group_sidlist): Always add the interactive
group to the token. Add comment. Create logon_id group SID by
copying it from incoming group list.
(create_token): Add subauth_token parameter. Use information in
subauth_token if present. Tweak SourceIdentifier if subauth_token
is present for debugging purposes.
* security.h (create_token): Add subauth_token parameter in declaration.
* syscalls.cc (seteuid32): Call subauth first. Call create_token
regardless. Use subauth token in call to create_token if subauth
succeeded.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* include/netinet/in.h: Update copyright.
2006-07-13 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::wait): Rework function so that
WaitForMultipleObjects is really only called when necessary.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* include/netdb.h: Declare rcmd, rcmd_af, rexec, rresvport,
rresvport_af, iruserok, iruserok_sa, ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* Makefile.in (DLL_OFILES): Drop iruserok.o. Add rcmd.o.
* autoload.cc (rcmd): Drop definition.
* cygwin.din: Export bindresvport, bindresvport_sa, iruserok_sa,
rcmd_af, rresvport_af.
* net.cc (cygwin_rcmd): Remove.
(last_used_bindresvport): Rename from last_used_rrecvport.
(cygwin_bindresvport_sa): New function implementing bindresvport_sa.
(cygwin_bindresvport): New function implementing bindresvport.
(cygwin_rresvport): Remove.
* include/cygwin/version.h: Bump API minor number.
* include/netinet/in.h: Declare bindresvport and bindresvport_sa.
* libc/iruserok.c: Remove file.
* libc/rcmd.cc: New file implementing rcmd, rcmd_af, rresvport,
rresvport_af, iruserok_sa, iruserok and ruserok.
2006-07-12 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::getsockname): Return valid
result for unbound sockets.
2006-07-11 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (fhandler_socket::fixup_after_fork): Handle
wsock_mtx and wsock_evt on fork, thus handling close_on_exec correctly.
(fhandler_socket::fixup_after_exec): Drop misguided attempt to handle
close_on_exec here.
(fhandler_socket::dup): Call fixup_after_fork with NULL parent.
Add comment.
(fhandler_socket::set_close_on_exec): Handle wsock_mtx and wsock_evt.
2006-07-10 Corinna Vinschen <corinna@vinschen.de>
* fhandler.h (class fhandler_socket): Add wsock_mtx, wsock_evt
and wsock_events members. Remove closed status flag, add listener
status flag. Accomodate new implementation of socket event handling
methods. Declare recv* and send* functions ssize_t as the POSIX
equivalents.
(fhandler_socket::recv_internal): Declare.
(fhandler_socket::send_internal): Ditto.
* fhandler_socket.cc (EVENT_MASK): Define mask of selected events.
(fhandler_socket::fhandler_socket): Initialize new members.
(fhandler_socket::af_local_setblocking): Don't actually set the
socket to blocking mode. Keep sane event selection.
(fhandler_socket::af_local_unsetblocking): Don't actually set the
socket to previous blocking setting, just remember it.
(struct wsa_event): New structure to keep event data per shared
socket.
(NUM_SOCKS): Define number of shared sockets concurrently handled by
all active Cygwin processes.
(wsa_events): New shared datastructure keeping all wsa_event records.
(socket_serial_number): New shared variable to identify shared sockets.
(wsa_slot_mtx): Global mutex to serialize wsa_events access.
(search_wsa_event_slot): New static function to select a new wsa_event
slot for a new socket.
(fhandler_socket::prepare): Rewrite. Prepare event selection
per new socket.
(fhandler_socket::wait): Rewrite. Wait for socket events in thread
safe and multiple process safe.
(fhandler_socket::release): Rewrite. Close per-socket descriptor
mutex handle and event handle.
(fhandler_socket::dup): Duplicate wsock_mtx and wsock_evt. Fix
copy-paste error in debug output.
(fhandler_socket::connect): Accomodate new event handling.
(fhandler_socket::listen): Set listener flag on successful listen.
(fhandler_socket::accept): Accomodate new event handling.
(fhandler_socket::recv_internal): New inline method centralizing
common recv code.
(fhandler_socket::recvfrom): Call recv_internal now.
(fhandler_socket::recvmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::send_internal): New inline method centralizing
common send code.
(fhandler_socket::sendto): Call send_internal now.
(fhandler_socket::sendmsg): Ditto. Streamline copying from iovec
to WSABUF.
(fhandler_socket::close): Call release now.
(fhandler_socket::ioctl): Never actually switch to blocking mode.
Just keep track of the setting.
* net.cc (fdsock): Call prepare now.
(cygwin_connect): Revert again to event driven technique.
(cygwin_accept): Ditto.
* poll.cc (poll): Don't call recvfrom on a listening socket.
Remove special case for failing recvfrom.
* include/sys/socket.h: Declare recv* and send* functions ssize_t as
requested by POSIX.
2006-07-07 Corinna Vinschen <corinna@vinschen.de>
* net.cc (cygwin_inet_ntop): Fix data type of forth parameter.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* include/cygwin/in6.h (struct in6_addr): Fix typo.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* cygwin.din: Export in6addr_any, in6addr_loopback, freeaddrinfo,
gai_strerror, getaddrinfo, getnameinfo.
* fhandler_socket.cc: Include cygwin/in6.h.
(get_inet_addr): Accomodate AF_INET6 usage.
(fhandler_socket::connect): Ditto.
(fhandler_socket::listen): Ditto.
(fhandler_socket::sendto): Ditto.
* net.cc: Include cygwin/in6.h.
(in6addr_any): Define.
(in6addr_loopback): Define.
(cygwin_socket): Accomodate AF_INET6 usage.
(socketpair): Bind socketpairs only to loopback for security.
(inet_pton4): New static function.
(inet_pton6): Ditto.
(cygwin_inet_pton): New AF_INET6 aware inet_pton implementation.
(inet_ntop4): New static function.
(inet_ntop6): Ditto.
(cygwin_inet_ntop): New AF_INET6 aware inet_ntop implementation.
(ga_aistruct): New static function.
(ga_clone): Ditto.
(ga_echeck): Ditto.
(ga_nsearch): Ditto.
(ga_port): Ditto.
(ga_serv): Ditto.
(ga_unix): Ditto.
(gn_ipv46): Ditto.
(ipv4_freeaddrinfo): Ditto.
(ipv4_getaddrinfo): Ditto.
(ipv4_getnameinfo): Ditto.
(gai_errmap_t): New structure holding error code - error string mapping.
(cygwin_gai_strerror): New function implementing gai_strerror.
(w32_to_gai_err): New static function.
(get_ipv6_funcs): Ditto.
(load_ipv6_funcs): Ditto.
(cygwin_freeaddrinfo): New function implementing freeaddrinfo.
(cygwin_getaddrinfo): New function implementing getaddrinfo.
(cygwin_getnameinfo): New function implementing getnameinfo.
* include/netdb.h: Include stdint.h and cygwin/socket.h. Define
data types and macros used by getaddrinfo and friends. Declare
freeaddrinfo, gai_strerror, getaddrinfo and getnameinfo.
* include/cygwin/in.h: Add IPv6 related IPPROTOs. Remove definition
of struct sockaddr_in6. Include cygwin/in6.h instead.
* include/cygwin/in6.h: New header file defining IPv6 releated
data types and macros.
* include/cygwin/socket.h: Enable AF_INET6 and PF_INET6. Add
IPv6 related socket options.
* include/cygwin/version.h: Bump API minor number.
2006-07-06 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (DsGetDcNameA): Define.
(NetGetAnyDCName): Define.
* security.cc: Include dsgetdc.h.
(DsGetDcNameA): Declare.
(DS_FORCE_REDISCOVERY): Define.
(get_logon_server): Add bool parameter to control rediscovery of DC.
Use DsGetDcNameA function if supported, NetGetDCName/NetGetAnyDCName
otherwise.
(get_server_groups): Rediscover DC if get_user_groups fails and
try again.
(get_reg_security): Use correct error code macro when testing
RegGetKeySecurity return value.
* security.h (get_logon_server): Remove default vaue from wserver
parameter. Add rediscovery parameter.
* uinfo.cc (cygheap_user::env_logsrv): Accomodate rediscovery parameter
in call to get_logon_server.
2006-07-26 03:23:23 +08:00
|
|
|
extern "C" int
|
|
|
|
posix_openpt (int oflags)
|
|
|
|
{
|
|
|
|
return open ("/dev/ptmx", oflags);
|
|
|
|
}
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" int
|
2001-04-24 23:25:31 +08:00
|
|
|
grantpt (int fd)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-09-21 12:33:57 +08:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
return cfd < 0 ? -1 : 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" int
|
2001-04-24 23:25:31 +08:00
|
|
|
unlockpt (int fd)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-09-21 12:33:57 +08:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
return cfd < 0 ? -1 : 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-09-10 23:51:59 +08:00
|
|
|
extern "C" int
|
|
|
|
revoke (char *ttyname)
|
|
|
|
{
|
|
|
|
set_errno (ENOSYS);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-03-10 04:10:25 +08:00
|
|
|
extern "C" int
|
2000-02-18 03:38:33 +08:00
|
|
|
ttyslot (void)
|
|
|
|
{
|
2011-06-15 05:48:43 +08:00
|
|
|
if (myself->ctty <= 0 || iscons_dev (myself->ctty))
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
2011-05-29 02:17:09 +08:00
|
|
|
return device::minor (myself->ctty);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __stdcall
|
2006-06-04 04:32:07 +08:00
|
|
|
tty_list::init_session ()
|
|
|
|
{
|
2008-03-13 00:55:42 +08:00
|
|
|
char mutex_name[MAX_PATH];
|
2006-06-04 04:32:07 +08:00
|
|
|
char *name = shared_name (mutex_name, "tty_list::mutex", 0);
|
2011-06-15 05:48:43 +08:00
|
|
|
|
|
|
|
/* tty_list::mutex is used while searching for a tty slot */
|
2006-06-04 04:32:07 +08:00
|
|
|
if (!(mutex = CreateMutex (&sec_all_nih, FALSE, name)))
|
|
|
|
api_fatal ("can't create tty_list::mutex '%s', %E", name);
|
|
|
|
ProtectHandle (mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __stdcall
|
|
|
|
tty::init_session ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-11-26 12:15:10 +08:00
|
|
|
if (!myself->cygstarted && NOTSTATE (myself, PID_CYGPARENT))
|
2002-02-23 03:33:41 +08:00
|
|
|
cygheap->fdtab.get_debugger_info ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2013-05-01 09:20:37 +08:00
|
|
|
int __reg2
|
2011-05-29 02:17:09 +08:00
|
|
|
tty_list::attach (int n)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-05-29 02:17:09 +08:00
|
|
|
int res;
|
|
|
|
if (iscons_dev (n))
|
|
|
|
res = -1;
|
|
|
|
else if (n != -1)
|
|
|
|
res = connect (device::minor (n));
|
|
|
|
else
|
|
|
|
res = -1;
|
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2006-06-04 04:32:07 +08:00
|
|
|
tty_list::connect (int ttynum)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (ttynum < 0 || ttynum >= NTTYS)
|
|
|
|
{
|
|
|
|
termios_printf ("ttynum (%d) out of range", ttynum);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!ttys[ttynum].exists ())
|
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
termios_printf ("pty %d was not allocated", ttynum);
|
2011-10-11 06:01:06 +08:00
|
|
|
set_errno (ENXIO);
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ttynum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
tty_list::init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
for (int i = 0; i < NTTYS; i++)
|
|
|
|
{
|
|
|
|
ttys[i].init ();
|
2011-10-20 22:02:54 +08:00
|
|
|
ttys[i].setntty (DEV_PTYS_MAJOR, i);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
/* Search for a free tty and allocate it.
|
2000-02-18 03:38:33 +08:00
|
|
|
Return tty number or -1 if error.
|
|
|
|
*/
|
|
|
|
int
|
2011-10-16 06:37:30 +08:00
|
|
|
tty_list::allocate (HANDLE& r, HANDLE& w)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2006-06-04 04:32:07 +08:00
|
|
|
lock_ttys here;
|
2011-06-15 05:48:43 +08:00
|
|
|
int freetty = -1;
|
2004-05-17 23:27:56 +08:00
|
|
|
|
2011-06-15 05:48:43 +08:00
|
|
|
tty *t = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
for (int i = 0; i < NTTYS; i++)
|
2011-10-16 06:37:30 +08:00
|
|
|
if (ttys[i].not_allocated (r, w))
|
2011-06-15 05:48:43 +08:00
|
|
|
{
|
|
|
|
t = ttys + i;
|
|
|
|
t->init ();
|
2013-10-19 04:07:35 +08:00
|
|
|
t->setsid (0);
|
2011-06-15 05:48:43 +08:00
|
|
|
freetty = i;
|
|
|
|
break;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
if (freetty >= 0)
|
|
|
|
termios_printf ("pty%d allocated", freetty);
|
2011-06-15 05:48:43 +08:00
|
|
|
else
|
2004-05-21 01:32:12 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
system_printf ("No pty allocated");
|
|
|
|
r = w = NULL;
|
2004-05-21 01:32:12 +08:00
|
|
|
}
|
2011-10-16 06:37:30 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
return freetty;
|
|
|
|
}
|
|
|
|
|
2009-07-04 02:05:51 +08:00
|
|
|
bool
|
2011-10-16 06:37:30 +08:00
|
|
|
tty::not_allocated (HANDLE& r, HANDLE& w)
|
2009-07-04 02:05:51 +08:00
|
|
|
{
|
|
|
|
/* Attempt to open the from-master side of the tty. If it is accessible
|
2011-10-16 06:37:30 +08:00
|
|
|
then it exists although we may not have privileges to actually use it. */
|
|
|
|
char pipename[sizeof("ptyNNNN-from-master")];
|
2013-04-23 17:44:36 +08:00
|
|
|
__small_sprintf (pipename, "pty%d-from-master", get_minor ());
|
2011-11-24 02:56:57 +08:00
|
|
|
/* fhandler_pipe::create returns 0 when creation succeeds */
|
|
|
|
return fhandler_pipe::create (&sec_none, &r, &w,
|
|
|
|
fhandler_pty_common::pipesize, pipename,
|
|
|
|
0) == 0;
|
2011-10-16 06:37:30 +08:00
|
|
|
}
|
2009-07-04 02:05:51 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
bool
|
|
|
|
tty::exists ()
|
|
|
|
{
|
|
|
|
HANDLE r, w;
|
|
|
|
bool res;
|
|
|
|
if (!not_allocated (r, w))
|
|
|
|
res = true;
|
2009-07-04 02:05:51 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
else
|
2009-07-04 02:05:51 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
/* Handles are left open when not_allocated finds a non-open "tty" */
|
|
|
|
CloseHandle (r);
|
|
|
|
CloseHandle (w);
|
|
|
|
res = false;
|
2009-07-04 02:05:51 +08:00
|
|
|
}
|
2011-10-16 06:37:30 +08:00
|
|
|
debug_printf ("exists %d", res);
|
|
|
|
return res;
|
2009-07-04 02:05:51 +08:00
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2010-04-20 03:52:43 +08:00
|
|
|
tty::slave_alive ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE ev;
|
2010-04-20 03:52:43 +08:00
|
|
|
if ((ev = open_inuse (READ_CONTROL)))
|
2000-02-18 03:38:33 +08:00
|
|
|
CloseHandle (ev);
|
|
|
|
return ev != NULL;
|
|
|
|
}
|
|
|
|
|
2004-05-29 03:50:07 +08:00
|
|
|
HANDLE
|
2010-04-20 03:52:43 +08:00
|
|
|
tty::open_mutex (const char *mutex, ACCESS_MASK access)
|
2004-05-12 09:44:11 +08:00
|
|
|
{
|
2010-04-20 03:52:43 +08:00
|
|
|
char buf[MAX_PATH];
|
2013-04-23 17:44:36 +08:00
|
|
|
shared_name (buf, mutex, get_minor ());
|
2010-04-20 03:52:43 +08:00
|
|
|
return OpenMutex (access, TRUE, buf);
|
2004-05-29 03:50:07 +08:00
|
|
|
}
|
2004-05-12 09:44:11 +08:00
|
|
|
|
2004-05-29 03:50:07 +08:00
|
|
|
HANDLE
|
2010-04-20 03:52:43 +08:00
|
|
|
tty::open_inuse (ACCESS_MASK access)
|
2004-05-12 09:44:11 +08:00
|
|
|
{
|
2008-03-13 00:55:42 +08:00
|
|
|
char buf[MAX_PATH];
|
2013-04-23 17:44:36 +08:00
|
|
|
shared_name (buf, TTY_SLAVE_ALIVE, get_minor ());
|
2010-04-20 03:52:43 +08:00
|
|
|
return OpenEvent (access, FALSE, buf);
|
2004-05-12 09:44:11 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
HANDLE
|
2010-04-20 03:52:43 +08:00
|
|
|
tty::create_inuse (PSECURITY_ATTRIBUTES sa)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE h;
|
2008-03-13 00:55:42 +08:00
|
|
|
char buf[MAX_PATH];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
shared_name (buf, TTY_SLAVE_ALIVE, get_minor ());
|
2010-04-20 03:52:43 +08:00
|
|
|
h = CreateEvent (sa, TRUE, FALSE, buf);
|
2004-09-03 09:53:12 +08:00
|
|
|
termios_printf ("%s %p", buf, h);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (!h)
|
2013-04-23 17:44:36 +08:00
|
|
|
termios_printf ("couldn't open inuse event %s, %E", buf);
|
2000-02-18 03:38:33 +08:00
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
tty::init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-29 07:48:28 +08:00
|
|
|
output_stopped = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
setsid (0);
|
|
|
|
pgid = 0;
|
2011-06-15 05:48:43 +08:00
|
|
|
was_opened = false;
|
2004-12-15 01:19:22 +08:00
|
|
|
master_pid = 0;
|
2011-06-15 05:48:43 +08:00
|
|
|
is_console = false;
|
2015-03-25 19:42:38 +08:00
|
|
|
column = 0;
|
2021-01-28 11:26:14 +08:00
|
|
|
pcon_activated = false;
|
2019-09-14 05:48:14 +08:00
|
|
|
switch_to_pcon_in = false;
|
2019-08-28 02:04:02 +08:00
|
|
|
pcon_pid = 0;
|
2019-09-15 12:05:52 +08:00
|
|
|
term_code_page = 0;
|
2020-01-27 19:22:24 +08:00
|
|
|
pcon_last_time = 0;
|
2020-08-19 19:25:21 +08:00
|
|
|
pcon_start = false;
|
2020-08-31 17:48:54 +08:00
|
|
|
pcon_cap_checked = false;
|
|
|
|
has_csi6n = false;
|
2021-01-18 21:10:57 +08:00
|
|
|
need_invisible_console = false;
|
|
|
|
invisible_console_pid = 0;
|
2021-01-28 11:26:12 +08:00
|
|
|
previous_code_page = 0;
|
|
|
|
previous_output_code_page = 0;
|
2021-01-28 11:26:13 +08:00
|
|
|
master_is_running_as_service = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE
|
2010-04-20 03:52:43 +08:00
|
|
|
tty::get_event (const char *fmt, PSECURITY_ATTRIBUTES sa, BOOL manual_reset)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE hev;
|
2008-03-13 00:55:42 +08:00
|
|
|
char buf[MAX_PATH];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2013-04-23 17:44:36 +08:00
|
|
|
shared_name (buf, fmt, get_minor ());
|
2010-04-20 03:52:43 +08:00
|
|
|
if (!sa)
|
|
|
|
sa = &sec_all;
|
|
|
|
if (!(hev = CreateEvent (sa, manual_reset, FALSE, buf)))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
termios_printf ("couldn't create %s", buf);
|
|
|
|
set_errno (ENOENT); /* FIXME this can't be the right errno */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
termios_printf ("created event %s", buf);
|
|
|
|
return hev;
|
|
|
|
}
|
2006-06-04 04:32:07 +08:00
|
|
|
|
|
|
|
lock_ttys::lock_ttys (DWORD howlong): release_me (true)
|
|
|
|
{
|
|
|
|
if (WaitForSingleObject (tty_list::mutex, howlong) == WAIT_FAILED)
|
|
|
|
{
|
|
|
|
termios_printf ("WFSO for mutex %p failed, %E", tty_list::mutex);
|
|
|
|
release_me = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lock_ttys::release ()
|
|
|
|
{
|
|
|
|
ReleaseMutex (tty_list::mutex);
|
|
|
|
}
|
2011-05-29 02:17:09 +08:00
|
|
|
|
|
|
|
const char *
|
|
|
|
tty_min::ttyname ()
|
|
|
|
{
|
|
|
|
device d;
|
|
|
|
d.parse (ntty);
|
2016-06-23 22:56:41 +08:00
|
|
|
return d.name ();
|
2011-05-29 02:17:09 +08:00
|
|
|
}
|
2020-05-21 16:25:01 +08:00
|
|
|
|
|
|
|
void
|
2021-01-28 11:26:13 +08:00
|
|
|
tty::wait_pcon_fwd (bool init)
|
2020-05-21 16:25:01 +08:00
|
|
|
{
|
2020-06-04 09:43:19 +08:00
|
|
|
/* The forwarding in pseudo console sometimes stops for
|
|
|
|
16-32 msec even if it already has data to transfer.
|
|
|
|
If the time without transfer exceeds 32 msec, the
|
|
|
|
forwarding is supposed to be finished. pcon_last_time
|
|
|
|
is reset to GetTickCount() in pty master forwarding
|
|
|
|
thread when the last data is transfered. */
|
2020-05-21 16:25:01 +08:00
|
|
|
const int sleep_in_pcon = 16;
|
|
|
|
const int time_to_wait = sleep_in_pcon * 2 + 1/* margine */;
|
2021-01-28 11:26:13 +08:00
|
|
|
if (init)
|
|
|
|
pcon_last_time = GetTickCount ();
|
2020-05-21 16:25:01 +08:00
|
|
|
while (GetTickCount () - pcon_last_time < time_to_wait)
|
|
|
|
{
|
|
|
|
int tw = time_to_wait - (GetTickCount () - pcon_last_time);
|
|
|
|
cygwait (tw);
|
|
|
|
}
|
|
|
|
}
|