2000-02-18 03:38:33 +08:00
|
|
|
/* tty.cc
|
|
|
|
|
2008-01-02 03:07:36 +08:00
|
|
|
Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008
|
|
|
|
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"
|
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
|
|
|
|
|
|
|
extern fhandler_tty_master *tty_master;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (NOTSTATE (myself, PID_USETTY))
|
|
|
|
return -1;
|
|
|
|
return myself->ctty;
|
|
|
|
}
|
|
|
|
|
2006-06-04 04:32:07 +08:00
|
|
|
HANDLE NO_COPY tty_list::mutex = NULL;
|
|
|
|
|
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
|
|
|
/* tty_list::mutex is used while searching for a tty slot. It's necessary
|
|
|
|
while finding console window handle */
|
|
|
|
|
|
|
|
char *name = shared_name (mutex_name, "tty_list::mutex", 0);
|
|
|
|
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
|
|
|
if (NOTSTATE (myself, PID_USETTY))
|
|
|
|
return;
|
|
|
|
if (myself->ctty == -1)
|
|
|
|
if (NOTSTATE (myself, PID_CYGPARENT))
|
2006-06-04 04:32:07 +08:00
|
|
|
myself->ctty = cygwin_shared->tty.attach (myself->ctty);
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
return;
|
|
|
|
if (myself->ctty == -1)
|
|
|
|
termios_printf ("Can't attach to tty");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create session's master tty */
|
|
|
|
|
|
|
|
void __stdcall
|
2006-06-04 04:32:07 +08:00
|
|
|
tty::create_master (int ttynum)
|
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
|
|
|
device ttym = *ttym_dev;
|
|
|
|
ttym.setunit (ttynum); /* CGF FIXME device */
|
|
|
|
tty_master = (fhandler_tty_master *) build_fh_dev (ttym);
|
|
|
|
if (tty_master->init ())
|
2000-02-18 03:38:33 +08:00
|
|
|
api_fatal ("Can't create master tty");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Log utmp entry */
|
|
|
|
struct utmp our_utmp;
|
2003-03-08 11:36:39 +08:00
|
|
|
DWORD len = sizeof our_utmp.ut_host;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
bzero ((char *) &our_utmp, sizeof (utmp));
|
2005-07-07 04:05:03 +08:00
|
|
|
time (&our_utmp.ut_time);
|
2000-02-18 03:38:33 +08:00
|
|
|
strncpy (our_utmp.ut_name, getlogin (), sizeof (our_utmp.ut_name));
|
2003-03-08 11:36:39 +08:00
|
|
|
GetComputerName (our_utmp.ut_host, &len);
|
2000-02-18 03:38:33 +08:00
|
|
|
__small_sprintf (our_utmp.ut_line, "tty%d", ttynum);
|
2003-03-08 11:36:39 +08:00
|
|
|
if ((len = strlen (our_utmp.ut_line)) >= UT_IDLEN)
|
|
|
|
len -= UT_IDLEN;
|
|
|
|
else
|
|
|
|
len = 0;
|
|
|
|
strncpy (our_utmp.ut_id, our_utmp.ut_line + len, UT_IDLEN);
|
2000-02-18 03:38:33 +08:00
|
|
|
our_utmp.ut_type = USER_PROCESS;
|
2002-11-07 10:19:52 +08:00
|
|
|
our_utmp.ut_pid = myself->pid;
|
2000-02-18 03:38:33 +08:00
|
|
|
myself->ctty = ttynum;
|
|
|
|
login (&our_utmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int __stdcall
|
2006-06-04 04:32:07 +08:00
|
|
|
tty_list::attach (int num)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (num != -1)
|
|
|
|
{
|
2006-06-04 04:32:07 +08:00
|
|
|
return connect (num);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
if (NOTSTATE (myself, PID_USETTY))
|
|
|
|
return -1;
|
2006-06-04 04:32:07 +08:00
|
|
|
return allocate (true);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-05 11:16:46 +08:00
|
|
|
tty_list::terminate ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2006-06-04 04:32:07 +08:00
|
|
|
if (NOTSTATE (myself, PID_USETTY))
|
|
|
|
return;
|
2000-02-18 03:38:33 +08:00
|
|
|
int ttynum = myself->ctty;
|
|
|
|
|
|
|
|
/* Keep master running till there are connected clients */
|
2006-07-18 23:09:11 +08:00
|
|
|
if (ttynum != -1 && tty_master && ttys[ttynum].master_pid == myself->pid)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
tty *t = ttys + ttynum;
|
2006-06-02 23:41:34 +08:00
|
|
|
CloseHandle (tty_master->from_master);
|
|
|
|
CloseHandle (tty_master->to_master);
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Wait for children which rely on tty handling in this process to
|
|
|
|
go away */
|
|
|
|
for (int i = 0; ; i++)
|
|
|
|
{
|
|
|
|
if (!t->slave_alive ())
|
|
|
|
break;
|
|
|
|
if (i >= 100)
|
|
|
|
{
|
|
|
|
small_printf ("waiting for children using tty%d to terminate\n",
|
|
|
|
ttynum);
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
2002-11-14 03:36:12 +08:00
|
|
|
low_priority_sleep (200);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2006-06-04 04:32:07 +08:00
|
|
|
lock_ttys here ();
|
2004-12-15 01:19:22 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
termios_printf ("tty %d master about to finish", ttynum);
|
2006-06-02 23:41:34 +08:00
|
|
|
CloseHandle (tty_master->get_io_handle ());
|
|
|
|
CloseHandle (tty_master->get_output_handle ());
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
t->init ();
|
|
|
|
|
|
|
|
char buf[20];
|
|
|
|
__small_sprintf (buf, "tty%d", ttynum);
|
|
|
|
logout (buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 ())
|
|
|
|
{
|
|
|
|
termios_printf ("tty %d was not allocated", ttynum);
|
|
|
|
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 ();
|
|
|
|
ttys[i].setntty (i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for tty class for our console. Allocate new tty if our process is
|
|
|
|
the only cygwin process in the current console.
|
|
|
|
Return tty number or -1 if error.
|
|
|
|
If flag == 0, just find a free tty.
|
|
|
|
*/
|
|
|
|
int
|
2006-06-04 04:32:07 +08:00
|
|
|
tty_list::allocate (bool with_console)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HWND console;
|
2004-05-17 23:27:56 +08:00
|
|
|
int freetty = -1;
|
2004-05-17 23:55:42 +08:00
|
|
|
HANDLE hmaster = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* FIXME: This whole function needs a protective mutex. */
|
|
|
|
|
2006-06-04 04:32:07 +08:00
|
|
|
lock_ttys here;
|
2004-05-17 23:27:56 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (!with_console)
|
|
|
|
console = NULL;
|
2002-08-31 00:03:52 +08:00
|
|
|
else if (!(console = GetConsoleWindow ()))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2008-01-02 02:51:23 +08:00
|
|
|
termios_printf ("Can't find console window");
|
|
|
|
goto out;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-05-17 23:27:56 +08:00
|
|
|
/* Is a tty allocated for console? */
|
2000-02-18 03:38:33 +08:00
|
|
|
for (int i = 0; i < NTTYS; i++)
|
|
|
|
{
|
|
|
|
if (!ttys[i].exists ())
|
|
|
|
{
|
|
|
|
if (freetty < 0) /* Scanning? */
|
|
|
|
freetty = i; /* Yes. */
|
|
|
|
if (!with_console) /* Do we want to attach this to a console? */
|
|
|
|
break; /* No. We've got one. */
|
|
|
|
}
|
|
|
|
|
2004-05-17 23:27:56 +08:00
|
|
|
/* FIXME: Is this right? We can potentially query a "nonexistent"
|
|
|
|
tty slot after falling through from the above? */
|
2000-02-18 03:38:33 +08:00
|
|
|
if (with_console && ttys[i].gethwnd () == console)
|
|
|
|
{
|
|
|
|
termios_printf ("console %x already associated with tty%d",
|
|
|
|
console, i);
|
|
|
|
/* Is the master alive? */
|
2004-05-17 23:27:56 +08:00
|
|
|
hmaster = OpenProcess (PROCESS_DUP_HANDLE, FALSE, ttys[i].master_pid);
|
|
|
|
if (hmaster)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-05-17 23:27:56 +08:00
|
|
|
CloseHandle (hmaster);
|
|
|
|
freetty = i;
|
|
|
|
goto out;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
/* Master is dead */
|
|
|
|
freetty = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There is no tty allocated to console, allocate the first free found */
|
|
|
|
if (freetty == -1)
|
2004-05-17 23:27:56 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
tty *t;
|
|
|
|
t = ttys + freetty;
|
2000-02-18 03:38:33 +08:00
|
|
|
t->init ();
|
|
|
|
t->setsid (-1);
|
|
|
|
t->sethwnd (console);
|
|
|
|
|
2004-05-17 23:27:56 +08:00
|
|
|
out:
|
|
|
|
if (freetty < 0)
|
2006-06-04 04:32:07 +08:00
|
|
|
system_printf ("No tty allocated");
|
2004-05-17 23:27:56 +08:00
|
|
|
else if (!with_console)
|
2004-05-21 01:32:12 +08:00
|
|
|
{
|
|
|
|
termios_printf ("tty%d allocated", freetty);
|
2006-06-04 04:32:07 +08:00
|
|
|
here.dont_release (); /* exit with mutex still held -- caller has more work to do */
|
2004-05-21 01:32:12 +08:00
|
|
|
}
|
2004-05-17 23:27:56 +08:00
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-05-17 23:27:56 +08:00
|
|
|
termios_printf ("console %p associated with tty%d", console, freetty);
|
|
|
|
if (!hmaster)
|
2006-06-04 04:32:07 +08:00
|
|
|
tty::create_master (freetty);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
return freetty;
|
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2000-02-18 03:38:33 +08:00
|
|
|
tty::slave_alive ()
|
|
|
|
{
|
|
|
|
return alive (TTY_SLAVE_ALIVE);
|
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2000-02-18 03:38:33 +08:00
|
|
|
tty::alive (const char *fmt)
|
|
|
|
{
|
|
|
|
HANDLE ev;
|
2008-03-13 00:55:42 +08:00
|
|
|
char buf[MAX_PATH];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-05-12 09:44:11 +08:00
|
|
|
shared_name (buf, fmt, ntty);
|
2001-09-06 12:41:59 +08:00
|
|
|
if ((ev = OpenEvent (EVENT_ALL_ACCESS, FALSE, buf)))
|
2000-02-18 03:38:33 +08:00
|
|
|
CloseHandle (ev);
|
|
|
|
return ev != NULL;
|
|
|
|
}
|
|
|
|
|
2004-05-29 03:50:07 +08:00
|
|
|
HANDLE
|
2004-05-12 09:44:11 +08:00
|
|
|
tty::open_output_mutex ()
|
|
|
|
{
|
|
|
|
return open_mutex (OUTPUT_MUTEX);
|
2004-05-29 03:50:07 +08:00
|
|
|
}
|
2004-05-12 09:44:11 +08:00
|
|
|
|
|
|
|
HANDLE
|
|
|
|
tty::open_input_mutex ()
|
|
|
|
{
|
|
|
|
return open_mutex (INPUT_MUTEX);
|
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
|
2004-05-12 09:44:11 +08:00
|
|
|
tty::open_mutex (const char *mutex)
|
|
|
|
{
|
2008-03-13 00:55:42 +08:00
|
|
|
char buf[MAX_PATH];
|
2004-05-12 09:44:11 +08:00
|
|
|
shared_name (buf, mutex, ntty);
|
|
|
|
return OpenMutex (MUTEX_ALL_ACCESS, TRUE, buf);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
HANDLE
|
2001-09-01 13:38:46 +08:00
|
|
|
tty::create_inuse (const char *fmt)
|
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
|
|
|
|
2004-05-12 09:44:11 +08:00
|
|
|
shared_name (buf, fmt, ntty);
|
2001-09-01 13:38:46 +08:00
|
|
|
h = CreateEvent (&sec_all, 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)
|
|
|
|
termios_printf ("couldn't open inuse event, %E", buf);
|
|
|
|
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;
|
|
|
|
hwnd = NULL;
|
|
|
|
was_opened = 0;
|
2004-12-15 01:19:22 +08:00
|
|
|
master_pid = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE
|
2001-09-01 13:17:34 +08:00
|
|
|
tty::get_event (const char *fmt, 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
|
|
|
|
2004-05-12 09:44:11 +08:00
|
|
|
shared_name (buf, fmt, ntty);
|
2001-09-01 13:17:34 +08:00
|
|
|
if (!(hev = CreateEvent (&sec_all, 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);
|
|
|
|
}
|