newlib-cygwin/winsup/cygwin/fhandler_tty.cc

1919 lines
51 KiB
C++
Raw Normal View History

2000-02-18 03:38:33 +08:00
/* fhandler_tty.cc
2006-01-12 12:41:06 +08:00
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010 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. */
#include "winsup.h"
2000-02-18 03:38:33 +08:00
#include <stdlib.h>
#include <cygwin/kd.h>
#include "cygerrno.h"
#include "security.h"
Add "path.h" include throughout, where needed. Use new path_conv methods and operators to simplify testing for directory and attributes, throughout. * path.h (path_conv::exists): New method. (path_conv::has_attribute): Ditto. (path_conv::isdir): Ditto. (path_conv::DWORD &): New operator. (path_conv::int &): Ditto. * dir.cc (rmdir): Eliminate a goto. * dtable.cc (dtable::build_fhandler): Accept opt and suffix info for path_conv.check. Return fh == NULL on path_conv error. Pass unit to set_name as appropriate. (dtable::reset_unix_path_name): New method. * dtable.h (dtable): Declare new method. Reflect arg changes to build_fhandler. * fhandler.cc (fhandler_disk_dummy_name): Eliminate. (fhandler_base::set_name): Expect paths to be NULL. Build unix_path_name from win32_path_name when it is a device. (fhandler_base::reset_unix_path_name): New method. (fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER and reading a directory. (fhandler_disk_file::fstat): Don't call stat_dev since we should now never be calling fhandler_disk_file methods with devices. (fhandler_base::fhandler_base): Clear {unix,win32}_path_name. (fhandler_base::~fhandler_base): Always free {unix,win32}_path_name. (fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge. (fhandler_disk_file::open): Ditto. * fhandler.h (fhandler_base::no_free_names): Eliminate. (fhandler_base::set_no_free_names): Ditto. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set unix_path_name here. * path.cc (fchdir): Lock fd table throughout. Use new dtable::reset_unix_path_name method to reset path. * syscalls.cc (stat_worker): Reorganize to always call fstat method. Pass path_conv method to fhandler_*::open. (chroot): Elminate a goto.
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"
#include "dtable.h"
#include "sigproc.h"
2000-08-12 13:47:12 +08:00
#include "pinfo.h"
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
#include "ntdll.h"
* Makefile.in: Add cygheap.o. * child_info.h: Add specific exec class. * cygheap.h: New file. Contains declarations for cygwin heap. * cygheap.cc: New file. Implements cygwin heap functions. * dcrt0.cc (quoted): Simplify due to new method for passing arguments between cygwin programs. (alloc_stack_hard_way): Attempt to handle overlapped stack. (dll_crt0_1): Move child_info processing here. Accomodate new method for passing arguments between cygwin programs. Initialize cygwin heap. Establish __argc and __argv variables. (_dll_crt0): Move most of child_info processing to dll_crt0_1. (cygwin_dll_init): Remove duplication. * dtable.cc (dtable::extend): Allocate dtable using cygwin heap. (dtable::build_fhandler): Ditto for fhandler type being constructed. (dtable::dup_worker): Free new fhandler from cygwin heap on error. (dtable::select_*): Don't assume that this == fdtab. (dtable::linearize_fd_array): Delete. (dtable::delinearize_fd_array): Delete. (dtable::fixup_after_exec): New file. (dtable::vfork_child_dup): Use cygwin heap. (dtable::vfork_parent_restore): Ditto. * dtable.h: Remove obsolete methods. Add new method. * environ.cc (posify): Eliminate already_posix parameter and logic. (envsize): New function. (_addenv): Use envsize. (environ_init): Accept an argument pointing to an existing environment list. If supplied, allocate space for this in the the program's heap. * fhandler.cc (fhandler_base::operator =): Move here from fhandler.h. Use cygwin heap to allocate filenames. (fhandler_base::set_name): Allocate/free names from cygwin heap. (fhandler_base::linearize): Delete. (fhandler_base::de_linearize): Delete. (fhandler_base::operator delete): Free from cygwin heap. (fhandler_base::~fhandler_base): Ditto. * fhandler.h: Accomodate elimination of *linearize and other changes above. * fhandler_console.cc (fhandler_console::fixup_after_exec): Rename from de_linearize. * heap.h: New file. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Use cygwin heap for name. fhandler_tty::fixup_after_exec): Rename from de_linearize. * fork.cc (fork): Call cygheap_fixup_in_child. * heap.cc: Use declarations in heap.h. * malloc.cc: Sprinkle assertions throughout to catch attempts to free/realloc something from the cygwin heap. * path.cc: Throughout, eliminate use of per-thread cache for cwd. Use cwd_* functions rather than cwd_* variables to access cwd_win32 and cwd_posix. (cwd_win32): New function. (cwd_posix): New function. (cwd_hash): New function. (cwd_fixup_after_exec): New function. * path.h: Accomodate path.cc changes. * pinfo.cc (pinfo_init): Accept a pointer to an environment table. Pass this to environ_init. Eliminate old 'title' tests. * pinfo.h: Accomodate above change in argument. * spawn.cc (struct av): New method for building argv list. (av::unshift): New method. (spawn_guts): Allocate everything that the child process needs in the cygwin heap and pass a pointer to this to the child. Build argv list using new method. Eliminate delinearize stuff. * thread.h: Eliminate _cwd_win32 and _cwd_posix buffers. * winsup.h: Eliminate obsolete functions. Add envsize() declaration.
2000-09-03 12:16:35 +08:00
#include "cygheap.h"
#include "shared_info.h"
#include "cygthread.h"
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
#include "child_info.h"
2000-02-18 03:38:33 +08:00
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
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;
};
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
/* tty master stuff */
2000-02-18 03:38:33 +08:00
fhandler_tty_master NO_COPY *tty_master;
static void WINAPI process_input (void *) __attribute__((noreturn)); // Input queue thread
static void WINAPI process_output (void *) __attribute__((noreturn)); // Output queue thread
static void WINAPI process_ioctl (void *) __attribute__((noreturn)); // Ioctl requests thread
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
fhandler_tty_master::fhandler_tty_master ()
: fhandler_pty_master (), console (NULL)
{
}
int
fhandler_tty_slave::get_unit ()
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
return dev () == FH_TTY ? myself->ctty : dev ().minor;
2000-02-18 03:38:33 +08:00
}
void
fhandler_tty_master::set_winsize (bool sendSIGWINCH)
{
winsize w;
console->ioctl (TIOCGWINSZ, &w);
get_ttyp ()->winsize = w;
if (sendSIGWINCH)
tc->kill_pgrp (SIGWINCH);
}
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_tty_master::init ()
2000-02-18 03:38:33 +08:00
{
termios_printf ("Creating master for tty%d", get_unit ());
2000-02-18 03:38:33 +08:00
if (init_console ())
{
termios_printf ("can't create fhandler");
return -1;
}
if (!setup (false))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
return 1;
2000-02-18 03:38:33 +08:00
set_winsize (false);
set_close_on_exec (true);
new cygthread (process_input, cygself, "ttyin");
new cygthread (process_ioctl, cygself, "ttyioctl");
new cygthread (process_output, cygself, "ttyout");
2000-02-18 03:38:33 +08:00
return 0;
}
#ifdef DEBUGGING
static class mutex_stack
{
public:
const char *fn;
int ln;
const char *tname;
} ostack[100];
static int osi;
2000-02-18 03:38:33 +08:00
#endif /*DEBUGGING*/
DWORD
fhandler_tty_common::__acquire_output_mutex (const char *fn, int ln,
DWORD ms)
{
*** cygwin DLL Changes: * child_info.h (CURR_CHILD_INFO_MAGIC): Reset. (child_info::dwProcessId): Delete. (child_info::straced): New variable. (child_info::handle_fork): New member function. * dcrt0.cc (in_forkee): New global variable. (__cygwin_user_data::forkee): Mark as obsolete. (do_global_ctors): Use in_forkee rather than user_data->forkee. (get_cygwin_startup_info): Ditto. Deal with new straced field to allow strace to deal with children of attached processes. (initial_env): Accommodate changes to strace::hello. (child_info_fork::handle_fork): Rename from plain old 'handle_fork'. Move alloc_stack() call elsewhere. (dll_crt0_0): Fill out more of user_data. Reference handle_fork via fork_info. Add some debugging output. (_dll_crt0): Don't wait for sync thread if sync_startup is invalid. Zero sync_startup here. Call alloc_stack() here, if appropriate. (dll_crt0_1): Use in_forkee rather than user_data->forkee. (dll_crt0): Ditto. * malloc_wrapper.cc (malloc_init): Ditto. * dll_init.cc (in_forkee): Remove local static version of this variable. (dll_list::load_after_fork): Don't set in_forkee here. * external.cc (cygwin_internal): Use strace method rather than accessing field directly. * fhandler.cc (fhandler_base::read): Ditto. * fhandler_tty.cc (fhandler_tty_common::__acquire_output_mutex): Ditto. * fork.cc (frok::parent): Invoke strace write_childpid to communicate with potential strace. (child_copy): Add more detail to debugging output. * init.cc (calibration_id): New static variable. (prime_threads): Set sync_startup to invalid handle if we already know about thread_func_ix. Use static calibration_id to hold calibration thread id. * munge_threadfunc (munge_threadfunc): Don't try to debug if we don't find threadfunc_ix. (dll_entry): Avoid calling munge_threadfunc and _cygtls::remove on non-cygwin threads invoked during process startup. * pinfo.cc (set_myself): Always call strace.hello here regardless of DEBUGGING. * sigproc.cc (child_info::child_info): Remove spurious handling of dwProcessId. Set straced as appropriate. * spawn.cc (spawn_guts): Rename ciresrv to ch. Invoke strace write_childpid to communicate with potential strace. * strace.cc: Include child_info.h. (strace::hello): Remove inited test. Use active() method to test if strace has been activated. Handle case where we are started before (mypid): New function. (strace::vsprntf): Try to deal more intelligently with case where progname may not be filled out. Put pid in parentheses if it is a windows pid rather than a cygwin pid. myself has been filled out. (strace::write_childpid): New function for notifying strace about the creation of children. (strace::vprntf): Use strace method rather than accessing field directly. (strace_printf): Ditto. (strace::wm): Ditto. * winsup.h (in_forkee): Declare. * include/sys/strace.h (strace::write_childpid): Declare new function. (strace::attached): Define new function. (strace::active): Ditto. (strace::active_val): Ditto. (_STRACE_ON): Delete. (_STRACE_OFF): Ditto. (define_strace0): Use strace method rather than accessing field directly. (strace_printf_wrap): Ditto. (strace_printf_wrap1): Ditto. *** cygwin utils changes: * strace.cc (nprocesses): Make static global. (quiet): New variable. (strace_active): Ditto. (add_child): Increment nprocesses here. Don't add a child if it is already added (windows bug?). Report on child if not quiet. (get_child): Just return NULL if child not found. (remove_child): Report on child if not quiet. (attach_process): Don't complain if given a windows process. Use windows pid in error. (handle_output_debug_string): Issue error if trying to manipulate a process that we don't know about. Handle _STRACE_CHILD_PID - attach to reported child when we get this. (proc_child): Move nprocesses to file scope. Report on exceptions. (longopts): Implement "--quiet". (opts): Implement "-q". (main): Manipulate quiet flag. * utils.sgml (strace): Add words describing '-q'.
2005-12-30 04:46:34 +08:00
if (strace.active ())
strace.prntf (_STRACE_TERMIOS, fn, "(%d): tty output_mutex: waiting %d ms", ln, ms);
2000-02-18 03:38:33 +08:00
DWORD res = WaitForSingleObject (output_mutex, ms);
if (res == WAIT_OBJECT_0)
{
#ifndef DEBUGGING
if (strace.active ())
strace.prntf (_STRACE_TERMIOS, fn, "(%d): tty output_mutex: acquired", ln, res);
#else
2000-02-18 03:38:33 +08:00
ostack[osi].fn = fn;
ostack[osi].ln = ln;
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
fhandler_tty_common::__release_output_mutex (const char *fn, int ln)
{
if (ReleaseMutex (output_mutex))
{
#ifndef DEBUGGING
if (strace.active ())
strace.prntf (_STRACE_TERMIOS, fn, "(%d): tty output_mutex released", ln);
#else
2000-02-18 03:38:33 +08:00
if (osi > 0)
osi--;
termios_printf ("released at %s:%d, osi %d", fn, ln, osi);
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
}
#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
}
/* Process tty input. */
void
fhandler_pty_master::doecho (const void *str, DWORD len)
{
acquire_output_mutex (INFINITE);
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
// WaitForSingleObject (output_done_event, INFINITE);
release_output_mutex ();
}
int
fhandler_pty_master::accept_input ()
{
DWORD bytes_left;
int ret = 1;
WaitForSingleObject (input_mutex, INFINITE);
2000-02-18 03:38:33 +08:00
bytes_left = eat_readahead (-1);
2000-02-18 03:38:33 +08:00
if (!bytes_left)
2000-02-18 03:38:33 +08:00
{
termios_printf ("sending EOF to slave");
get_ttyp ()->read_retval = 0;
}
else
{
char *p = rabuf;
DWORD rc;
DWORD written = 0;
termios_printf ("about to write %d chars to slave", bytes_left);
rc = WriteFile (get_output_handle (), p, bytes_left, &written, NULL);
if (!rc)
{
debug_printf ("error writing to pipe %E");
get_ttyp ()->read_retval = -1;
ret = -1;
}
else
{
get_ttyp ()->read_retval = 1;
p += written;
bytes_left -= written;
if (bytes_left > 0)
{
debug_printf ("to_slave pipe is full");
puts_readahead (p, bytes_left);
ret = 0;
}
}
2000-02-18 03:38:33 +08:00
}
SetEvent (input_available_event);
ReleaseMutex (input_mutex);
return ret;
2000-02-18 03:38:33 +08:00
}
static void WINAPI
process_input (void *)
2000-02-18 03:38:33 +08:00
{
char rawbuf[INP_BUFFER_SIZE];
while (1)
{
size_t nraw = INP_BUFFER_SIZE;
tty_master->console->read ((void *) rawbuf, nraw);
if (tty_master->line_edit (rawbuf, nraw, tty_master->get_ttyp ()->ti)
== line_edit_signalled)
tty_master->console->eat_readahead (-1);
2000-02-18 03:38:33 +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;
}
/* Process tty output requests */
int
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;
char outbuf[OUT_BUFFER_SIZE + 1];
2000-02-18 03:38:33 +08:00
DWORD n;
int column = 0;
int rc = 0;
2000-02-18 03:38:33 +08:00
if (len == 0)
goto out;
2000-02-18 03:38:33 +08:00
if (need_nl)
2000-02-18 03:38:33 +08:00
{
/* We need to return a left over \n character, resulting from
\r\n conversion. Note that we already checked for FLUSHO and
output_stopped at the time that we read the character, so we
don't check again here. */
if (buf)
buf[0] = '\n';
need_nl = 0;
rc = 1;
goto out;
}
2000-02-18 03:38:33 +08:00
for (;;)
{
/* 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
HANDLE handle = get_io_handle ();
2000-02-18 03:38:33 +08:00
n = 0; // get_readahead_into_buffer (outbuf, len);
if (!n)
2000-02-18 03:38:33 +08:00
{
/* Doing a busy wait like this is quite inefficient, but nothing
else seems to work completely. Windows should provide some sort
of overlapped I/O for pipes, or something, but it doesn't. */
while (1)
{
if (!PeekNamedPipe (handle, NULL, 0, NULL, &n, NULL))
goto err;
if (n > 0)
break;
if (hit_eof ())
goto out;
/* DISCARD (FLUSHO) and tcflush can finish here. */
if (n == 0 && (get_ttyp ()->ti.c_lflag & FLUSHO || !buf))
goto out;
if (n == 0 && is_nonblocking ())
{
set_errno (EAGAIN);
rc = -1;
break;
}
Sleep (10);
}
if (ReadFile (handle, outbuf, rlen, &n, NULL) == FALSE)
goto err;
2000-02-18 03:38:33 +08:00
}
termios_printf ("bytes read %u", n);
get_ttyp ()->write_error = 0;
if (output_done_event != NULL)
SetEvent (output_done_event);
2000-02-18 03:38:33 +08:00
if (get_ttyp ()->ti.c_lflag & FLUSHO || !buf)
continue;
2000-02-18 03:38:33 +08:00
char *optr;
optr = buf;
if (pktmode_on)
*optr++ = TIOCPKT_DATA;
if (!(get_ttyp ()->ti.c_oflag & OPOST)) // post-process output
2000-02-18 03:38:33 +08:00
{
memcpy (optr, outbuf, n);
optr += n;
}
else // raw output mode
{
char *iptr = outbuf;
while (n--)
2000-02-18 03:38:33 +08:00
{
switch (*iptr)
2000-02-18 03:38:33 +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
}
/* 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
{
if (*iptr != '\n' || n != 0)
system_printf ("internal error: %d unexpected characters", n);
need_nl = 1;
break;
2000-02-18 03:38:33 +08:00
}
*optr++ = *iptr++;
2000-02-18 03:38:33 +08:00
}
}
rc = optr - buf;
break;
2000-02-18 03:38:33 +08:00
err:
if (GetLastError () == ERROR_BROKEN_PIPE)
rc = 0;
else
{
__seterrno ();
rc = -1;
2000-02-18 03:38:33 +08:00
}
break;
2000-02-18 03:38:33 +08:00
}
out:
termios_printf ("returning %d", rc);
return rc;
2000-02-18 03:38:33 +08:00
}
static void WINAPI
process_output (void *)
2000-02-18 03:38:33 +08:00
{
char buf[OUT_BUFFER_SIZE * 2];
2000-02-18 03:38:33 +08:00
for (;;)
2000-02-18 03:38:33 +08:00
{
int n = tty_master->process_slave_output (buf, OUT_BUFFER_SIZE, 0);
if (n <= 0)
2000-02-18 03:38:33 +08:00
{
if (n < 0)
termios_printf ("ReadFile %E");
ExitThread (0);
2000-02-18 03:38:33 +08:00
}
n = tty_master->console->write ((void *) buf, (size_t) n);
tty_master->get_ttyp ()->write_error = n == -1 ? get_errno () : 0;
2000-02-18 03:38:33 +08:00
}
}
/* Process tty ioctl requests */
static void WINAPI
process_ioctl (void *)
2000-02-18 03:38:33 +08:00
{
while (1)
{
WaitForSingleObject (tty_master->ioctl_request_event, INFINITE);
termios_printf ("ioctl() request");
tty *ttyp = tty_master->get_ttyp ();
ttyp->ioctl_retval =
tty_master->console->ioctl (ttyp->cmd,
(ttyp->cmd == KDSKBMETA)
? (void *) ttyp->arg.value
: (void *) &ttyp->arg);
2000-02-18 03:38:33 +08:00
SetEvent (tty_master->ioctl_done_event);
}
}
/**********************************************************************/
/* Tty slave stuff */
fhandler_tty_slave::fhandler_tty_slave ()
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
: fhandler_tty_common (), inuse (NULL)
2000-02-18 03:38:33 +08:00
{
* Use new unified status_flag accessor methods from classes fhandler_*, tty_min, mtinfo and fs_info thoroughout. * fhandler.h: Redefine all set_close_on_exec methods to take a bool argument. (enum conn_state): Rename from connect_state. (class fhandler_base): Rename some status flags to align with accessor method names. Drop encoded flag entirely. Unify status accessor methods. Const'ify all read accessor methods. (class fhandler_socket): Ditto. (class fhandler_dev_raw): Ditto. * fhandler_disk_file.cc (fhandler_base::fstat_fs): Use fs.fs_is_fat() instead of evaluating FATness of file system here. (fhandler_disk_file::opendir): Drop call to set_encoded(). (fhandler_disk_file::readdir): Use pc.isencoded() directly. * mtinfo.h (class mtinfo_drive): Const'ify all read accessor methods. * path.cc (fsinfo_cnt): Add. (fs_info::update): Accomodate class changes. Evaluate file system name specific flags right here. Add thread safety for reading and writing global fsinfo array. * path.h (enum path_types): Drop values for flags kept in fs already. (struct fs_info): Move status informatin into private struct type status_flags. Add accessor methods. Remove path and file system name string arrays in favor of status bits. (class path_conv): Use new fs_info status information where appropriate. (path_conf::fs_has_ea): Rename from fs_fast_ea. (path_conf::fs_has_acls): New method. (path_conf::root_dir): Remove. (path_conf::volname): Remove. * syscalls (statfs): Evaluate root dir locally. * tty.h (class tty_min): Unify status accessor methods. Const'ify all read accessor methods.
2004-04-10 21:45:10 +08:00
uninterruptible_io (true);
2000-02-18 03:38:33 +08:00
}
/* FIXME: This function needs to close handles when it has
a failing condition. */
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_tty_slave::open (int flags, mode_t)
2000-02-18 03:38:33 +08:00
{
HANDLE tty_owner, from_master_local, to_master_local;
HANDLE *handles[] =
{
&from_master_local, &input_available_event, &input_mutex, &inuse,
&ioctl_done_event, &ioctl_request_event, &output_done_event,
&output_mutex, &to_master_local, &tty_owner,
NULL
};
const char *errmsg = NULL;
for (HANDLE **h = handles; *h; h++)
**h = NULL;
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
if (get_device () == FH_TTY)
dev().tty_to_real_device ();
fhandler_tty_slave *arch = (fhandler_tty_slave *) cygheap->fdtab.find_archetype (pc.dev);
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
if (arch)
{
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
*this = *(fhandler_tty_slave *) arch;
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
termios_printf ("copied fhandler_tty_slave archetype");
set_flags ((flags & ~O_TEXT) | O_BINARY);
* cygheap.h (init_cygheap::manage_console_count): Declare new function. (init_cygheap::console_count): Renamed from open_fhs. Make private. * cygheap.cc (init_cygheap::manage_console_count): Define new function. * dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on elements of fd even when they are about to be closed. * fhandler.h (report_tty_counts): Remove open_fhs from debugging output. * fhandler_console.cc (fhandler_console::open): Use manage_console_count rather than manipulating count directly. (fhandler_console::close): Ditto. (fhandler_console::fixup_after_fork): Ditto. (fhandler_console::fixup_after_exec): Ditto. Don't close handles if close_on_exec. * fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather than manipulating count directly. Reflect change in arguments to report_tty_counts(). (fhandler_tty_slave::close): Ditto for both. (fhandler_tty_slave::dup): Ditto for both. (fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #. (fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to report_tty_counts(). (fhandler_tty_master::init_console): Use manage_console_count() rather than manipulating count directly. * fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't perform any operations if close_on_exec. * fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto. * fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto. * fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto. * pinfo.h (_pinfo::_ctty): Declare new function. (myctty): Declare new macro. (__ctty): Declare new macro. * pinfo.cc (_pinfo::_ctty): Define new function. (_pinfo::set_ctty): Use manage_console_count() rather than manipulating count directly. * signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty #. * syscalls.cc (setsid): Ditto. Use manage_console_count() rather than manipulating count directly.
2005-11-14 12:28:45 +08:00
cygheap->manage_console_count ("fhandler_tty_slave::open<arch>", 1);
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
goto out;
}
tcinit (cygwin_shared->tty[get_unit ()], false);
2000-02-18 03:38:33 +08:00
* dcrt0.cc (dll_crt0_0): Call tty_list::init_session here. (dll_crt0_1): Reflect renaming from tty_init to tty::init_session. (do_exit): Reflect moving of tty_terminate into tty_list. * exceptions.cc (events_init): Move tty_mutex stuff elsewhere. * fhandler_console.cc (set_console_title): Use lock_ttys class. * fhandler_termios.cc (fhandler_termios::bg_check): Make debug output more accurate. * fhandler_tty.cc (fhandler_tty_slave::open): Reflect move of attach_tty into tty_list class. Don't attempt to grab master end of pty if master doesn't exist. (fhandler_pty_master::open): Reflect move of allocate_tty into tty_list class. Use lock_ttys::release to release mutex. Improve debugging output. (fhandler_pty_master::setup): Remove if 0'ed block. Fix argument to SetNamedPipeHandleState. * pinfo.cc (_pinfo::set_ctty): Lock ttys before setting sid/pgid. Improve debugging. Add temporary debugging. * tty.cc (tty_list::init_session): New function. (tty::init_session): Rename from tty_init. Reflect move of attach_tty to tty_list class. (tty::create_master): Rename from create_tty_master. (tty_list::attach): Rename from attach_tty. Reflect renaming of connect_tty to connect. Ditto for allocate_tty. (tty_terminate): Delete. (tty_list::terminate): Subsume tty_terminate. Use lock_ttys rather than manipulating mutex directly. (tty_list::allocate): Rename from allocate_tty. Use lock_ttys rather than manipulating mutex directly. Don't set sid here since linux apparently doesn't do this. Reflect move of create_tty_master into tty. (lock_ttys::lock_ttys): Define new constructor. (lock_ttys::release): New function. * tty.h (tty::exists): Return false immediately if !master_pid. (tty::set_master_closed): Define new function. (tty::create_master): Ditto. (tty::init_session): Ditto. (tty_list::mutex): New field. (tty_list::allocate): Define new function. (tty_list::connect): Ditto. (tty_list::attach): Ditto. (tty_list::init_session): Ditto. (lock_ttys): New class. (tty_init): Delete declaration. (tty_terminate): Ditto. (attach_tty): Ditto. (create_tty_master): Ditto.
2006-06-04 04:32:07 +08:00
cygwin_shared->tty.attach (get_unit ());
2000-02-18 03:38:33 +08:00
set_flags ((flags & ~O_TEXT) | O_BINARY);
2000-02-18 03:38:33 +08:00
/* Create synchronisation events */
char buf[MAX_PATH];
2000-02-18 03:38:33 +08:00
/* output_done_event may or may not exist. It will exist if the tty
was opened by fhandler_tty_master::init, normally called at
startup if use_tty is non-zero. It will not exist if this is a
pty opened by fhandler_pty_master::open. In the former case, tty
output is handled by a separate thread which controls output. */
shared_name (buf, OUTPUT_DONE_EVENT, get_unit ());
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
output_done_event = OpenEvent (MAXIMUM_ALLOWED, TRUE, buf);
2000-02-18 03:38:33 +08:00
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
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
{
errmsg = "open output mutex failed, %E";
goto err;
2000-02-18 03:38:33 +08:00
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(input_mutex = get_ttyp ()->open_input_mutex (MAXIMUM_ALLOWED)))
{
errmsg = "open input mutex failed, %E";
goto err;
}
shared_name (buf, INPUT_AVAILABLE_EVENT, get_unit ());
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(input_available_event = OpenEvent (MAXIMUM_ALLOWED, TRUE, buf)))
{
errmsg = "open input event failed, %E";
goto err;
}
2000-02-18 03:38:33 +08:00
/* The ioctl events may or may not exist. See output_done_event,
above. */
shared_name (buf, IOCTL_REQUEST_EVENT, get_unit ());
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
ioctl_request_event = OpenEvent (MAXIMUM_ALLOWED, TRUE, buf);
shared_name (buf, IOCTL_DONE_EVENT, get_unit ());
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
ioctl_done_event = OpenEvent (MAXIMUM_ALLOWED, TRUE, buf);
2000-02-18 03:38:33 +08:00
/* FIXME: Needs a method to eliminate tty races */
{
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
/* Create security attribute. Default permissions are 0620. */
security_descriptor sd;
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
InitializeSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
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);
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
inuse = get_ttyp ()->create_inuse (&sa);
get_ttyp ()->was_opened = true;
2000-02-18 03:38:33 +08:00
release_output_mutex ();
}
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
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
{
errmsg = "tty handles have been closed";
2000-02-18 03:38:33 +08:00
set_errno (EACCES);
goto err_no_errno;
2000-02-18 03:38:33 +08:00
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (get_ttyp ()->master_pid < 0)
{
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.");
tty_owner = GetCurrentProcess ();
}
else
2000-02-18 03:38:33 +08:00
{
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
pinfo p (get_ttyp ()->master_pid);
if (!p)
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
termios_printf ("*** couldn't find tty master");
else
{
tty_owner = OpenProcess (PROCESS_DUP_HANDLE, FALSE, p->dwProcessId);
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (tty_owner)
termios_printf ("dup handles directly since I'm allmighty.");
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
}
if (tty_owner)
{
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
if (!DuplicateHandle (tty_owner, get_ttyp ()->from_master,
GetCurrentProcess (), &from_master_local, 0, TRUE,
2002-02-28 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
2002-02-28 22:30:38 +08:00
DUPLICATE_SAME_ACCESS))
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
{
termios_printf ("can't duplicate input from %u/%p, %E",
get_ttyp ()->master_pid, get_ttyp ()->from_master);
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
__seterrno ();
goto err_no_msg;
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
}
if (!DuplicateHandle (tty_owner, get_ttyp ()->to_master,
GetCurrentProcess (), &to_master_local, 0, TRUE,
2002-02-28 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
2002-02-28 22:30:38 +08:00
DUPLICATE_SAME_ACCESS))
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
{
errmsg = "can't duplicate output, %E";
goto err;
* autoload.cc (LoadFuncEx): Define via new LoadFuncEx2 macro. (LoadFuncEx2): Adapted from LoadFuncEx. Provides control of return value for nonexistent function. (NtQueryObject): Declare. (IsDebuggerPresent): Declare via LoadFuncEx2 and always return true if not available. * debug.h (being_debugged): Just rely on IsDebuggerPresent return value. * dtable.cc (handle_to_fn): New function. (dtable::init_std_file_from_handle): Attempt to derive std handle's name via handle_to_fn. (dtable::build_fhandler_from_name): Fill in what we can in path_conv structure when given a handle and path doesn't exist. * fhandler.cc (fhandler_base::open): Don't set the file pointer here. Use pc->exists () to determine if file exists rather than calling GetFileAttributes again. * fhandler.h (fhandler_base::exec_state_isknown): New method. (fhandler_base::fstat_helper): Add extra arguments to declaration. (fhandler_base::fstat_by_handle): Declare new method. (fhandler_base::fstat_by_name): Declare new method. * fhandler_disk_file (num_entries): Make __stdcall. (fhandler_base::fstat_by_handle): Define new method. (fhandler_base::fstat_by_name): Define new method. (fhandler_base:fstat): Call fstat_by_{handle,name} as appropriate. (fhandler_disk_file::fstat_helper): Accept extra arguments for filling out stat structure. Move handle or name specific stuff to new methods above. (fhandler_disk_file::open): Use real_path->exists rather than calling GetFileAttributes again. * ntdll.h (FILE_NAME_INFORMATION): Define new structure. (OBJECT_INFORMATION_CLASS): Partially define new enum. (OBJECT_NAME_INFORMATION): Define new structure. (NtQueryInformationFile): New declaration. (NtQueryObject): New declaration. * path.cc (path_conv::fillin): Define new method. * path.h (path_conv::fillin): Declare new method. (path_conv::drive_thpe): Rename from 'get_drive_type'. (path_conv::volser): Declare new method. (path_conv::volname): Declare new method. (path_conv::root_dir): Declare new method. * syscalls.cc (fstat64): Send real path_conv to fstat as second argument.
2002-05-28 09:55:40 +08:00
}
if (tty_owner != GetCurrentProcess ())
CloseHandle (tty_owner);
2000-02-18 03:38:33 +08:00
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
else
{
pipe_request req = { GetCurrentProcessId () };
pipe_reply repl;
DWORD len;
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-tty%d-master-ctl",
&installation_key, get_unit ());
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 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
2002-02-28 22:30:38 +08:00
termios_printf ("duplicated from_master %p->%p from tty_owner",
get_ttyp ()->from_master, from_master_local);
2002-02-28 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
2002-02-28 22:30:38 +08:00
termios_printf ("duplicated to_master %p->%p from tty_owner",
get_ttyp ()->to_master, to_master_local);
2002-02-28 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
2002-02-28 22:30:38 +08:00
set_io_handle (from_master_local);
set_output_handle (to_master_local);
* cygwin.din (dup3): Export. (pipe2): Export. * dtable.cc (dtable::dup_worker): Take additional flags parameter. Handle O_CLOEXEC flag. (dtable::dup3): Rename from dup2. Take additional flags parameter. Check for valid flags. Drop check for newfd == oldfd. * dtable.h (dtable::dup_worker): Add flags parameter. (dtable::dup3): Rename from dup2. * fcntl.cc (fcntl64): Add F_DUPFD_CLOEXEC case. * fhandler.h (fhandler_mailslot::get_object_attr): Add flags parameter. * fhandler.cc (fhandler_base::open): Use security attribute with inheritance according to setting of O_CLOEXEC flag. * fhandler_console.cc (fhandler_console::open): Ditto. * fhandler_fifo.cc (sec_user_cloexec): New inline function to create security attribute with inheritance according to setting of O_CLOEXEC flag. (fhandler_fifo::open): Call sec_user_cloexec to fetch security attribute. (fhandler_fifo::wait): Ditto. * fhandler_mem.cc (fhandler_dev_mem::open): Ditto. * fhandler_mailslot.cc (fhandler_mailslot::get_object_attr): Take additional flags parameter. Use security attribute with inheritance according to setting of O_CLOEXEC flag. (fhandler_mailslot::open): Call get_object_attr with flags parameter. * fhandler_registry.cc (fhandler_registry::open): Call set_close_on_exec on real handles to accommodate O_CLOEXEC flag. * fhandler_tty.cc (fhandler_tty_slave::open): Ditto. * fhandler_tape.cc: Create mutex with inheritance according to setting of O_CLOEXEC flag. * pipe.cc: Replace usage of O_NOINHERIT with O_CLOEXEC. (fhandler_pipe::init): Simplify setting close_on_exec flag. (fhandler_pipe::open): Remove setting close_on_exec flag. (fhandler_pipe::create): Use security attribute with inheritance according to setting of O_CLOEXEC flag. (pipe2): New exported function. * posix_ipc.cc: Throughout, open backing files with O_CLOEXEC flag to follow POSIX semantics. * security.h (sec_none_cloexec): New define. * syscalls.cc (dup): Add missing extern "C" qualifier. Accommodate renaming of dtable::dup2 to dtable::dup3. (dup2): Ditto. Check newfd == oldfd here. (dup3): New function. Check newfd == oldfd here. (open): Set close_on_exec flag according to O_CLOEXEC flag before calling fhandler->open. * include/cygwin/version.h (CYGWIN_VERSION_API_MINOR): Bump.
2010-01-15 02:46:02 +08:00
set_close_on_exec (!!(flags & O_CLOEXEC));
2000-02-18 03:38:33 +08:00
set_open_status ();
if (cygheap->manage_console_count ("fhandler_tty_slave::open", 1) == 1
&& !output_done_event)
fhandler_console::need_invisible ();
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
// FIXME: Do this better someday
arch = (fhandler_tty_slave *) cmalloc_abort (HEAP_ARCHETYPES, sizeof (*this));
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
*((fhandler_tty_slave **) cygheap->fdtab.add_archetype ()) = arch;
archetype = arch;
*arch = *this;
out:
usecount = 0;
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
arch->usecount++;
* cygheap.h (init_cygheap::manage_console_count): Declare new function. (init_cygheap::console_count): Renamed from open_fhs. Make private. * cygheap.cc (init_cygheap::manage_console_count): Define new function. * dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on elements of fd even when they are about to be closed. * fhandler.h (report_tty_counts): Remove open_fhs from debugging output. * fhandler_console.cc (fhandler_console::open): Use manage_console_count rather than manipulating count directly. (fhandler_console::close): Ditto. (fhandler_console::fixup_after_fork): Ditto. (fhandler_console::fixup_after_exec): Ditto. Don't close handles if close_on_exec. * fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather than manipulating count directly. Reflect change in arguments to report_tty_counts(). (fhandler_tty_slave::close): Ditto for both. (fhandler_tty_slave::dup): Ditto for both. (fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #. (fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to report_tty_counts(). (fhandler_tty_master::init_console): Use manage_console_count() rather than manipulating count directly. * fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't perform any operations if close_on_exec. * fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto. * fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto. * fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto. * pinfo.h (_pinfo::_ctty): Declare new function. (myctty): Declare new macro. (__ctty): Declare new macro. * pinfo.cc (_pinfo::_ctty): Define new function. (_pinfo::set_ctty): Use manage_console_count() rather than manipulating count directly. * signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty #. * syscalls.cc (setsid): Ditto. Use manage_console_count() rather than manipulating count directly.
2005-11-14 12:28:45 +08:00
report_tty_counts (this, "opened", "");
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
myself->set_ctty (get_ttyp (), flags, arch);
2000-02-18 03:38:33 +08:00
return 1;
err:
__seterrno ();
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
}
int
fhandler_tty_slave::close ()
{
/* This used to always call fhandler_tty_common::close when hExeced but that
caused multiple closes of the handles associated with this tty. 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 */
cygheap->manage_console_count ("fhandler_tty_slave::close", -1);
archetype->usecount--;
report_tty_counts (this, "closed", "");
if (archetype->usecount)
{
#ifdef DEBUGGING
if (archetype->usecount < 0)
system_printf ("error: usecount %d", archetype->usecount);
#endif
termios_printf ("just returning because archetype usecount is != 0");
return 0;
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
}
termios_printf ("closing last open %s handle", ttyname ());
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
if (inuse && !CloseHandle (inuse))
termios_printf ("CloseHandle (inuse), %E");
return fhandler_tty_common::close ();
}
2002-02-28 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
2002-02-28 22:30:38 +08:00
int
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
fhandler_tty_slave::init (HANDLE f, 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
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
int ret = open (flags);
if (ret && !cygwin_finished_initializing && !being_debugged ())
{
/* 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
tty process group leader.
TODO: Investigate how SIGTTIN should be handled with pure-windows
programs. */
pinfo p (tc->getpgid ());
/* We should only grab this when the process group owner for this
tty is a non-cygwin process or we've been started directly
from a non-Cygwin process with no Cygwin ancestry. */
if (!p || ISSTATE (p, PID_NOTCYGWIN))
{
termios_printf ("Setting process group leader to %d since %W(%d) is not a cygwin process",
myself->pgid, p->progname, p->pid);
tc->setpgid (myself->pgid);
}
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (f != INVALID_HANDLE_VALUE)
CloseHandle (f); /* Reopened by open */
return ret;
2000-02-18 03:38:33 +08:00
}
* sigproc.h (wait_for_sigthread): Eliminate parameter. * sigproc.cc (wait_for_sigthread): Ditto. Don't synchronize with wait_sig after receiving an event that it is ready to go. (init_sig_pipe): New function. (wait_sig): Call init_sig_pipe to create pipes for communicating signals to this process. Don't send sigCONT signal when initializing. * fork.cc (frok::child): Accommodate wait_for_sigpipe parameter change. * fhandler.h (fhandler_*::write): Make ssize_t/__stdcall. (fhandler_*::write_overlapped): Ditto. (fhandler_*::raw_write): Ditto. (fhandler_*::readv): Ditto. (fhandler_*::writev): Ditto. (fhandler_*::raw_read): Make __stdcall. * fhandler: Accommodate changes to read/write functions throughout. * fhandler_clipboard.cc: Ditto. * fhandler_console.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_fifo.cc: Ditto. * fhandler_mailslot.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_tty.cc: Ditto. * fhandler_virtual.cc: Ditto. * fhandler_windows.cc: Ditto. * fhandler_zero.cc: Ditto. * syscalls.cc (readv): Use ssize_t as temp variable. * fhandler.cc (fhandler_base::read): Coerce returned len to signed or it will never be treated as < 0. (fhandler_base::wait_overlapped): Minimize calls to GetLastError. Remove duplicate debugging test. Fix error return. * fhandler.h (fhandler_fifo::fifo_name): Declare new function. (fhandler_fifo::close): Ditto. (fhandler_fifo::dup): Ditto. (fhandler_fifo::close_on_exec): Ditto. * fhandler.cc (fhandler_fifo::fifo_name): Define new function. (FIFO_BUF_SIZE): New define. (cnp): Ditto. (fhandler_fifo::open): Rework. Use cnp to open named pipe. Always open write side as a client. Open dummy client when writing and can't connect. (wait): Rework. Implement fifo_wait_for_next_client. Handle signals during connect better. Add new fifo_wait_for_server code which polls (sigh) waiting for server. (fhandler_fifo::raw_read): Handle transition states when one client closes and another is available. (fhandler_fifo::close): Define. (fhandler_fifo::dup): Ditto. (fhandler_fifo::close_on_exec): Ditto.
2009-07-25 04:54:33 +08:00
ssize_t __stdcall
2000-02-18 03:38:33 +08:00
fhandler_tty_slave::write (const void *ptr, size_t len)
{
DWORD n, towrite = len;
* 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
termios_printf ("tty%d, write(%x, %d)", get_unit (), ptr, len);
2000-02-18 03:38:33 +08:00
acquire_output_mutex (INFINITE);
while (len)
{
n = min (OUT_BUFFER_SIZE, len);
char *buf = (char *)ptr;
ptr = (char *) ptr + n;
len -= n;
/* Previous write may have set write_error to != 0. Check it here.
This is less than optimal, but the alternative slows down tty
writes enormously. */
if (get_ttyp ()->write_error)
{
set_errno (get_ttyp ()->write_error);
towrite = (DWORD) -1;
break;
}
2000-02-18 03:38:33 +08:00
if (WriteFile (get_output_handle (), buf, n, &n, NULL) == FALSE)
{
DWORD err = GetLastError ();
2000-02-18 03:38:33 +08:00
termios_printf ("WriteFile failed, %E");
switch (err)
{
case ERROR_NO_DATA:
err = ERROR_IO_DEVICE;
default:
__seterrno_from_win_error (err);
}
raise (SIGHUP); /* FIXME: Should this be SIGTTOU? */
towrite = (DWORD) -1;
2000-02-18 03:38:33 +08:00
break;
}
if (output_done_event != NULL)
{
DWORD rc;
DWORD x = n * 1000;
rc = WaitForSingleObject (output_done_event, x);
termios_printf ("waited %d ms for output_done_event, WFSO %d", x, rc);
2000-02-18 03:38:33 +08:00
}
}
release_output_mutex ();
return towrite;
}
void __stdcall
fhandler_tty_slave::read (void *ptr, size_t& len)
2000-02-18 03:38:33 +08:00
{
int totalread = 0;
int vmin = 0;
2000-02-18 03:38:33 +08:00
int vtime = 0; /* Initialized to prevent -Wuninitialized warning */
size_t readlen;
DWORD bytes_in_pipe;
2000-02-18 03:38:33 +08:00
char buf[INP_BUFFER_SIZE];
char peek_buf[INP_BUFFER_SIZE];
DWORD time_to_wait;
DWORD rc;
HANDLE w4[2];
2000-02-18 03:38:33 +08:00
2002-02-28 Robert Collins <rbtcollins@hotmail.com> * Merged cygwin_daemon into head minus the new shm and ipc exports. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * fhandler_tty.cc (fhandler_tty_slave::open): More debugging. (fhandler_tty_slave::read): Fix printf type for the handle. * tty.cc (tty::common_init): Add a FIXME for security. 2002-01-29 Robert Collins <rbtcollins@hotmail.com> * Makefile.in (OBJS): Remove duplicate localtime.o. 2002-01-17 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (check_and_dup_handle): Consolidate the two variants for simplicity. Add Some basic debug output. (client_request_attach_tty::serve): Use the new debug_printf for clarity. Mark the duplicated handles as inheritable - fixup_after_fork() doesn't reopen tty's. 2002-01-16 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (transport): Correct scope. (client_request_attach_tty::serve): Add more debug information. Fix erroneous use of transport instead of conn. * cygserver_transport_pipes.cc (transport_layer_pipes::close): More debug. (transport_layer_pipes::read): Ditto. (transport_layer_pipes::write): Ditto. (transport_layer_pipes::impersonate_client): Ditto. Mon Oct 8 7:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (server_request::process): Rename client_request_shm_get to client_request_shm. * cygserver_process.cc (process_cache::add): Rename to add_task. Use process_cleanup instead of process_request. (process_cache::remove_process): New method. (process::process): Initialize new members. (process::~process): New member. (process::cleanup): New method. (process::add_cleanup_routine): New method. (process_request::process): Rename to process_cleanup. Call the process object's cleanup method and then delete it. (process_process_param::request_loop): Remove the signalling process. * cygserver_shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm_get::serve): Handle attach request counting. * cygserver_shm.h: Globally rename client_request_shm_get to client_request_shm. (class shm_cleanup): New class. * shm.cc: Globally rename client_request_shm_get to client_request_shm. (client_request_shm::client_request_shm): New constructor for attach requests. (shmat): Use it. * include/cygwin/cygserver_process.h (class process_request): Rename to process_cleanup. (class cleanup_routine): New class. (class process): New members and methods to allow calling back when the process terminates. Thu Oct 4 14:12:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (request_loop): Make static. (main): Use new cache constructor syntax. Start cache worker threads. Cleanup the cache at shutdown. * cygserver_process.cc: Run indent. (process_cache::process_cache): Add a trigger to use when adding a process. (process_cache::process): Move process_entry to process. Insert at the end of the list. Trigger the request loop when new process's inserted. (process_cache::process_requests): Do it. (process_cache::add): New method. (process_cache::handle_snapshot): New method. (process::process): Merge in the process_entry fields. (process::handle): Make a stub function. (process::exit_code): New method. (process_request::process): New method. (process_process_param::request_loop): New method. * cygserver_shm.cc: New header dependency - threaded_queue.h. * threaded_queue.cc (threaded_queue::cleanup): Clearer messages. (queue_process_param::stop): Short spinlock on interruptible threads. * threaded_queue.h (class threaded_queue): New constructor. * include/cygwin/cygserver_process.h (process_request): New class. (process_entry): Remove. (process): Merge in process_entry. (process_cache): Inherit from threaded_queue. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (class server_process_param): Use new constructor syntax. * cygserver_process.cc (process_cache::~process_cache): New function. * threaded_queue.cc: Define condition debug_printf. Run indent. (threaded_queue::cleanup): Move queue_process_param guts to a method. (threaded_queue::process_requests): Ditto. (queue_process_param::queue_process_param): New method. (queue_process_param::~queue_process_param): Ditto. (queue_process_param::start): Ditto. (queue_process_param::stop): Ditto. * threaded_queue.h (class queue_process_param): Add support for interruptible request loops. * cygwin/include/cygwin/cygserver_process.h (class process_cache): Add destructor. Tue Oct 2 23:24:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver_client.cc: New flag allow_daemon to disable the daemon completely. (cygserver_request): Check it. (cygserver_init): Ditto. * environ.cc (parse_thing): Add (no)daemon option. Tue Oct 2 23:00:00 2001 Robert Collins <rbtcollins@hotmail.com> * shm.cc: Update to handle include changes from HEAD. Tue Oct 2 16:06:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Remove cygserver_shm.o from cygwin1.dll. Rename cygserver_shm_outside.o to cygserver_shm.o. * cygserver.cc (server_request::process): Use the new client_request constructor. * cygserver_client.cc: Remove the #ifdef's stubs for the server method within cygwin. (client_request_attach_tty::client_request_attach_tty): Use the new client_request constructor. (client_request_shutdown::client_request_shutdown): Ditto. (client_request::client_request): Ditto. * cygserver_shm.cc (client_request_shm_get::serve): Remove the #ifdef'd stub for in-cygwin builds. (client_request_shm_get::client_request_shm_get): Use the new client_request constructor, and remove the in-cygwin variants. * cygserver_shm.h (class client_request_shm_get): #ifndef test the serve method - it's only used in cygserver. * shm.cc (client_request_shm_get::client_request_shm_get): New function. * include/cygwin/cygserver.h (request_header): New constructor. (class client_request): Use it. New constructor accepting the header size. #ifndef test the server method - it's only used within cygserver. (client_request_get_version): #ifdef test the server method. (client_request_shutdown): Ditto. (client_request_attach_tty): Ditto. Tue Oct 2 9:57:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: add threaded_queue.o to cygserver.exe. * cygserver.cc: Include threaded_queue.h (class server_request): Inherit from queue_request. (class server_process_param): Inherit from queue_process_param. (class server_request_queue): Inherit from threaded_queue. (request_loop): Adjust for new types. (server_request_queue::process_requests): Remove guts to threaded_queue::process_requests. (server_request::server_request): Adjust for new types. (worker_function): Delete. (server_request_queue::create_workers): Delete. (server_request_queue::cleanup): Delete. (server_request_queue::add): Move guts to threaded_queue::add. * threaded_queue.cc: New file. * threaded_queue.h: New file. Mon Oct 1 12:38:00 2001 Robert Collins <rbtcollins@hotmail.com> * cygserver.cc (client_request::serve): New function. * cygserver_process.cc: Inlude <pthread.h> for pthread_once. (process_cache::process_cache): Initialise a crtiical section for write access. (process_cache::process): Use the critical section. Also add missing entries to the cache. (do_process_init): New function to initalise class process static variables. (process::process): Ensure that the process access critical section is initialised. (process::handle): Close the handle of old process's when they have terminated and we are returning the handle for a process with the same pid. * cygserver_shm.cc: Run indent. Include cygserver_process.h to allow process cache functionality. (client_request_shm_get::serve): New parameter for process cache support. Use the process cache, not OpenProcess to get a handle to the originating process. Fix a handle leak with token_handle. * cygserver_shm.h (class client_request_shm_get): Update ::serve for process cache support. * cygserver_transport_pipes.cc: Redefine debug_printf to be conditional on DEBUG. * include/cygwin/cygserver.h: Do not implement client_request::serve in the header. * include/cygwin/cygserver_process.h (class process_cache): Add a write access critical section to prevent races when requests from a multithreaded application arrive. Sun Sep 30 23:41:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_process.o to cygserver.exe. * cygserver.cc: Include signal.h and cygwin_version.h. Define debug_printf as a macro. Define DEBUG to a value. (client_request_attach_tty::serve): Add beginning of process cache support. Change from #ifdef DEBUG to work with new DEBUG style. (client_request_get_version::serve): Add beginning of process cache support. (class server_request): New prototype for support of process cache. (class queue_process_param): New class to allow request loop threading. (class server_request_queue): Add beginning of process cache support. Allow request loop threading. (request_loop): Thread function for request loops. (server_request_queue::process_requests): Initiator for threaded request loops. (client_request_shutdown::serve): Add beginning of process cache support. (server_request::server_request): Ditto. (server_request::process): Use debug_printf. Add beginning of process cache support. (server_request_queue::cleanup): Kill off any request loop threads. (server_request_queue::add): Add beginning of process cache support. (handle_signal): Trigger a shutdown. (main): Print out some useful info at startup - version, date time. Add process cache support. Spawn a separate thread for the transport request loop, thus allowing concurrent support for multiple transports. * cygserver_client.cc (client_request_get_version::serve): Add process cache support. (client_request_attach_tty::serve): Add process cache support. (client_request_shutdown::serve): Add process cache support. * cygsserver_process.cc: New file with the process cache support. * cygserver_shm.cc: Redefine debug_printf to allow conditional output. * cygwin.din: Export shmdt(). * shm.cc: Run indent. Update FIXME's. (shmdt): New function. * include/cygwin/cygserver.h (class client_request): Add process cache support. (class client_request_get_version): Ditto. (class client_request_shutdown): Ditto. (class client_request_attach_tty): Ditto. * include/cygwin/cygserver_process.h: New header for process cache support. Sun Sep 30 8:52:00 2001 Robert Collins <rbtcollins@hotmail.com> * include/cygwin/cygserver_transport.h: Add copyright header. * include/cygwin/cygserver_transport_pipes.h: Ditto. * include/cygwin/cygserver_transport_sockets.h: Ditto. Sat Sep 29 20:40:00 2001 Robert Collins <rbtcollins@hotmail.com> * Makefile.in: Add cygserver_transport_sockets.o to DLL_OFILES. Add cygserver_transport_sockets_outside.o to cygserver.exe. * cygserver.cc: Include new include files. * cygserver_client.cc: Ditto. * cygserver_shm.h: No need to include <sys/socket.h> now. * cygerver_transport.cc: Include new include files. (transport_layer_base::transport_layer_base): Strip back to a stub. (transport_layer_base::listen): Ditto. (transport_layer_base::accept): Ditto. (transport_layer_base::close): Ditto. (transport_layer_base::read): Ditto. (transport_layer_base::write): Ditto. (transport_layer_base::connect): Ditto. * cygserver_transport_pipes.cc: Include new header "cygwin/cygserver_transport_pipes.h". * cygserver_transport_sockets.cc: New file. * dcrt0.cc: No need to include <sys/socket.h> now. * fhandler_tty.cc: Ditto. * tty.cc: Ditto. * include/cygwin/cygserver_transport.h: Strip the base class to a stub. Remove the cygserver_transport_pipes class. * include/cygwin/cygserver_transport_pipes.h: New file. * include/cygwin/cygserver_transport_sockets.h: New file. Tue Sep 25 16:22:00 2001 Robert Collins <rbtcollins@hotmail.com> * autoload.cc: Add dynamic load statement for 'ImpersonateNamedPipeClient'. * Makefile.in: Add new object files, and build instructions for cygserver.exe. * cygwin.din: Export ftok, shmat, shmctl and shmget. * dcrt0.cc: Additional includes for cygserver support. (dll_crt0_1): Initialise the cygserver client. * fhandler.h (fhandler_tty): New method cygserver_attach_tty. * fhandler_tty.cc: Additional includes for cygserver support. (fhandler_tty_slave::open): Attempt to use the cygserver when obtaining handles from the parent process. On failure or 9x use the current method. (fhandler_tty_slave::cygserver_attach_tty): New function. * fork.cc (fork_child): Fixup shm memory mapped areas. * pinfo.h: Declare fixup_shms_after_fork(). * security.h: Declare alloc_sd(). * tty.cc: Additonal includes to support cygserver. (tty::common_init): Don't allow others to open us if the cygserver is running. * winsup.h: Declare cygserver_running. * cygserver.cc: New file. * cygserver_client.cc: New file. * cygserver_shm.cc: New file. * cygserver_shm.h: New file. * cygserver_transport.cc: New file. * cygserver_transport_pipes.cc: New file. * ipc.cc: New file. * shm.cc: New file. * include/cygwin/cygserver.h: New file. * include/cygwin/cygserver_transport.h: New file. * include/sys/ipc.h: New file. * include/sys/shm.h: New file. 2002-02-28 Robert Collins <rbtcollins@hotmail.com> * thread.cc (semaphore::TryWait): Set errno as required by posix 1003.1. (__sem_wait): Ditto. (__sem_trywait): Ditto.
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
if (!ptr) /* Indicating tcflush(). */
time_to_wait = 0;
else if ((get_ttyp ()->ti.c_lflag & ICANON))
time_to_wait = INFINITE;
else
2000-02-18 03:38:33 +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];
if (vmin < 0)
vmin = 0;
if (vtime < 0)
vtime = 0;
if (!vmin && !vtime)
time_to_wait = 0;
else
time_to_wait = !vtime ? INFINITE : 100 * vtime;
2000-02-18 03:38:33 +08:00
}
w4[0] = signal_arrived;
w4[1] = input_available_event;
2000-02-18 03:38:33 +08:00
DWORD waiter = time_to_wait;
2000-02-18 03:38:33 +08:00
while (len)
{
rc = WaitForMultipleObjects (2, w4, FALSE, waiter);
if (rc == WAIT_TIMEOUT)
* child_info.h (child_info_spawn::hexec_proc): Eliminate. * dcrt0.cc (dll_crt0_0): Remove hexec_proc stuff. * fork.cc (fork_child): Remove call to pinfo_fixup_after_fork. * pinfo.cc (set_myself): Close and zero pid_handle if set. (pinfo_fixup_after_fork): Delete. (proc_waiter): Don't close vchild.hProcess here. Do that when we are remove the vchild from procs. Save hProcess as pid_handle only on first reparent operation. (pinfo::wait): Don't set pid_handle here. (pinfo::alert_parent): Always try to send signal. If unsuccessful then close and zero wr_proc_pipe. * pinfo.h (pinfo::pinfo): Make sure that appropriate parts of the class are zeroed on construction. (pinfo::alert_parent): Take char argument. (pinfo_fixup_after_fork): Delete declaration. (hexec_proc): Ditto. * sigproc.cc (remove_proc): Close pid_handle and hProcess if appropriate. * spawn.cc (spawn_guts): Set cygheap->pid_handle on first exec. * cygheap.h (init_cygheap::pid_handle): New element. * pinfo.cc (set_myself): Clear previously existing cygheap->pid_handle when a new process has been started. (pinfo::wait): Make sure that a handle to the newly forked/spawned process is kept around so that the pid will not be reused. * pinfo.h (_pinfo::pid_handle): Move. (pinfo::pid_handle): to here. * spawn.cc (spawn_guts): Create a pid_handle in cygheap prior to spawning to ensure that the pid does not get reused during the lifetime of the "cygwin pid". * pinfo.h (pinfo::alert_parent): New function. * exceptions.cc (sig_handle_tty_stop): Use alert_parent to send "signals" to parent. * fork.cc (fork_parent): Don't close pi.hProcess. Let the waiter thread do that. * pinfo.cc (proc_waiter): Detect case where process exits without setting the exit code and use value from GetExitCodeProcess. Reluctantly implement __SIGREPARENT. (pinfo::alert_parent): Define. * sigproc.h (__SIGREPARENT): New enum. * spawn.cc (spawn_guts): Send reparent signal to parent on exec. Always create process in suspended state to avoid races. Remove cygthread.h in favor of cygtls.h throughout since cygtls now includes cygthread.h. Eliminate ppid_handle usage throughout. * child_info.h: Regenerate magic number (child_info): Remove pppid_handle. * cygthread.h (cygthread::release): New method. Frees thread without waiting. * cygthread.cc (cygthread::stub): Set _ctinfo in _mytls to point to information for executing thread. Don't call SetEvent if thread is no longer in use. (cygthread::simplestub): Ditto. * cygtls.h (_cygtls::_ctinfo): New element contains pointer to information about executing cygthread, if any. * dcrt0.cc: Remove last vestiges of per_thread stuff. (dll_crt0_0): Ditto. Remove accommodation for ppid_handle. (do_exit): Remove obsolete reparenting test. (_exit): Exit with a more SUSv3-like exit value. * dtable.cc (dtable::stdio_init): Check for myself->cygstarted rather than myself->ppid_handle to see if we were started by a cygwin process. * exceptions.cc (open_stackdumpfile): Ditto. (handle_exceptions): Ditto. (ctrl_c_handler): Ditto. (sig_handle_tty_stop): Ditto. Let parent send signal to itself on STOP. (sigpacket::process): Comment out vfork test. (signal_exit): Use more SUSv3-like exit value on signal. * external.cc (fillout_pinfo): Don't set hProcess. * fork.cc: Remove VFORK cruft. (per_thread::set): Delete. (fork_child): Remove perthread stuff. (fork_parent): Remove obsolete subproc_init. Accommodate new method for tracking subprocesses. * pinfo.cc (set_myself): Accommodate new pinfo/_pinfo layout. Set some things here that used to be set in wait_sig. (_pinfo::exit): Set exitcode here. Close process pipe. (_pinfo::commune_send): Accommodeate new pinfo/_pinfo layout. (proc_waiter): New function. Waits, in a thread for subprocess to go away. (pinfo::wait): New function. Initialization for proc_waiter. * pinfo.h (_pinfo::exitcode): New element. (_pinfo::cygstarted): Ditto. (_pinfo::wr_proc_pipe): Ditto. (_pinfo::ppid_handle): Delete. (_pinfo::hProcess): Delete. (_pinfo::lock): Delete. (pinfo::hProcess): New element. (pinfo::lock): Ditto. (pinfo::wait): Declare new function. (pinfo::preserve): Define new function. * sigproc.cc: Remove old stuff from wait_subproc thread based method. (zombies): Remove. (procs): New. (my_parent_is_alive): Just check that the parent pid exists. (mychild): Just use pinfo methods to determine if child is mine. (proc_subproc): Revamp PROC_ADDCHILD to use pinfo::wait. Remove PROC_CHILDTERMINATED logic. Use different method to remove processes from list when SIGCHLD == SIG_IGN. (proc_terminate): Gut. (subproc_init): Delete. (init_child_info): Remove setting of pppid_handle. (checkstate): Revamp to only scan procs array. (remove_proc): Rename from remove_zombie. Don't close hProcess or pid_handle. Don't release memory if it's myself. (stopped_or_terminated): Change logic to handle new consolidated proc/zombie array. (wait_subproc): Delete. * sigproc.h: Remove obsolete EXIT_* defines. (subproc_init): Remove declaration. * spawn.cc (spawn_guts): Remove reparenting stuff. Use standard wait logic to wait for child if started from a non-cygwin process. * tlsoffsets.h: Regenerate. * tty.cc (tty_init): Check for myself->cygstarted rather than myself->ppid_handle to see if we were started by a cygwin process. * include/sys/signal.h (external_pinfo::exitcode): Replace hProcess. * include/sys/wait.h (WCOREDUMP): Define. * fhandler_tty.cc (fhandler_tty_slave::read): Add debugging output for timeout case. * signal.cc (abort): Flag that we are exiting with the ABORT signal.
2004-11-26 12:15:10 +08:00
{
termios_printf ("wait timed out, waiter %u", waiter);
break;
}
if (rc == WAIT_FAILED)
{
termios_printf ("wait for input event failed, %E");
break;
}
if (rc == WAIT_OBJECT_0)
{
2001-03-17 09:45:40 +08:00
/* if we've received signal after successfully reading some data,
just return all data successfully read */
if (totalread > 0)
break;
set_sig_errno (EINTR);
2003-09-07 10:22:58 +08:00
len = (size_t) -1;
return;
}
rc = WaitForSingleObject (input_mutex, 1000);
if (rc == WAIT_FAILED)
{
termios_printf ("wait for input mutex failed, %E");
break;
}
else if (rc == WAIT_TIMEOUT)
{
termios_printf ("failed to acquire input mutex after input event arrived");
break;
}
if (!PeekNamedPipe (get_handle (), peek_buf, sizeof (peek_buf), &bytes_in_pipe, NULL, NULL))
2000-02-18 03:38:33 +08:00
{
termios_printf ("PeekNamedPipe failed, %E");
raise (SIGHUP);
bytes_in_pipe = 0;
2000-02-18 03:38:33 +08:00
}
/* On first peek determine no. of bytes to flush. */
if (!ptr && len == UINT_MAX)
len = (size_t) bytes_in_pipe;
if (ptr && !bytes_in_pipe && !vmin && !time_to_wait)
{
ReleaseMutex (input_mutex);
len = (size_t) bytes_in_pipe;
return;
}
readlen = min (bytes_in_pipe, min (len, sizeof (buf)));
if (ptr && vmin && readlen > (unsigned) vmin)
readlen = vmin;
DWORD n = 0;
if (readlen)
{
termios_printf ("reading %d bytes (vtime %d)", readlen, vtime);
if (ReadFile (get_handle (), buf, readlen, &n, NULL) == FALSE)
{
termios_printf ("read failed, %E");
raise (SIGHUP);
}
/* 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 */
if (!PeekNamedPipe (get_handle (), peek_buf, 1, &bytes_in_pipe, NULL, NULL))
{
termios_printf ("PeekNamedPipe failed, %E");
raise (SIGHUP);
bytes_in_pipe = 0;
}
if (n)
{
len -= n;
totalread += n;
if (ptr)
{
memcpy (ptr, buf, n);
ptr = (char *) ptr + n;
}
}
}
if (!bytes_in_pipe)
ResetEvent (input_available_event);
ReleaseMutex (input_mutex);
if (!ptr)
{
if (!bytes_in_pipe)
break;
continue;
}
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;
}
if (get_ttyp ()->ti.c_lflag & ICANON || is_nonblocking ())
2000-02-18 03:38:33 +08:00
break;
if (vmin && totalread >= vmin)
break;
/* vmin == 0 && vtime == 0:
* 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,
* so return immediately
* 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
*/
if (vmin == 0)
break;
if (n)
waiter = time_to_wait;
2000-02-18 03:38:33 +08:00
}
termios_printf ("%d=read(%x, %d)", totalread, ptr, len);
len = (size_t) totalread;
2000-02-18 03:38:33 +08:00
}
int
2005-09-29 03:22:25 +08:00
fhandler_tty_slave::dup (fhandler_base *child)
{
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
fhandler_tty_slave *arch = (fhandler_tty_slave *) archetype;
/* In dtable::dup_worker, the path_conv member has already been assigned
from "this" to "child". Part of this assigment (path_conv::operator=)
is to allocate memory for the strings "path" and "normalized_path from
cygheap. The below `child = *arch' statement will overwrite child's
path_conv again, this time from "*arch". By doing that, it will allocate
new strings from cygheap, overwriting the old pointer values. Thus, the
old allocated strings are lost, and we're leaking memory for each tty dup,
unless we free the strings here.
FIXME: We can't redefine path_conv::operator= so that it frees the old
strings. Probably it would be most helpful to copy only the required
members from *arch, rather than copying everything. */
child->pc.free_strings ();
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
*(fhandler_tty_slave *) child = *arch;
child->set_flags (get_flags ());
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
child->usecount = 0;
arch->usecount++;
* cygheap.h (init_cygheap::manage_console_count): Declare new function. (init_cygheap::console_count): Renamed from open_fhs. Make private. * cygheap.cc (init_cygheap::manage_console_count): Define new function. * dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on elements of fd even when they are about to be closed. * fhandler.h (report_tty_counts): Remove open_fhs from debugging output. * fhandler_console.cc (fhandler_console::open): Use manage_console_count rather than manipulating count directly. (fhandler_console::close): Ditto. (fhandler_console::fixup_after_fork): Ditto. (fhandler_console::fixup_after_exec): Ditto. Don't close handles if close_on_exec. * fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather than manipulating count directly. Reflect change in arguments to report_tty_counts(). (fhandler_tty_slave::close): Ditto for both. (fhandler_tty_slave::dup): Ditto for both. (fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #. (fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to report_tty_counts(). (fhandler_tty_master::init_console): Use manage_console_count() rather than manipulating count directly. * fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't perform any operations if close_on_exec. * fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto. * fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto. * fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto. * pinfo.h (_pinfo::_ctty): Declare new function. (myctty): Declare new macro. (__ctty): Declare new macro. * pinfo.cc (_pinfo::_ctty): Define new function. (_pinfo::set_ctty): Use manage_console_count() rather than manipulating count directly. * signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty #. * syscalls.cc (setsid): Ditto. Use manage_console_count() rather than manipulating count directly.
2005-11-14 12:28:45 +08:00
cygheap->manage_console_count ("fhandler_tty_slave::dup", 1);
report_tty_counts (child, "duped", "");
* cygheap.h (cygheap_types): Add HEAP_ARCHETYPES. (init_cheap::ctty): Change to pointer. * dtable.h (dtable::find_archetype): Declare new function. (dtable::add_archetype): Declare new function. (dtable::delete_archetype): Declare new function. (dtable::narchetypes): Declare. (dtable::farchetypes): Declare. (dtable::initial_archetype_size): Declare. (dtable::dtable): Initialize new fields. (dtable::initial_archetype_size): Declare. * dtable.cc (dtable::find_archetype): Define new function. (dtable::add_archetype): Define new function. (dtable::delete_archetype): Define new function. (dtable::initial_archetype_size): Define. * fhandler.h (fhandler_base::archetype): Declare. (fhandler_base::usecount): Declare. * fhandler.cc (fhandler_base::fhandler_base): Initialize new fields. * fhandler_console.cc (fhandler_console::get_tty_stuff): Pass NULL to third argument of set_ctty. * fhandler_tty.cc (fhandler_tty_slave::open): Accommodate new archetype method to create only one instance of a tty. (fhandler_tty_slave::close): Don't close handles unless archetype usecount is zero. When that happens, close archetype too. (fhandler_tty_slave::dup): Just copy archetype. Set use count appropriately. Set ctty, if appropriate. (fhandler_tty_common::dup): Remove slave considerations. (fhandler_tty_common::set_close_on_exec): Remove cygheap->ctty considerations. * pinfo.cc (_pinfo::set_ctty): Accommodate new archetype methods. * pinfo.h (_pinfo::set_ctty): Make third argument explicit. * syscalls.cc (close_all_files): Decrement controlling tty use count before closing all handles to allow controlling tty to be closed. Remove previous controlling tty considerations.
2003-12-11 14:12:41 +08:00
return 0;
}
2000-02-18 03:38:33 +08:00
int
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fhandler_pty_master::dup (fhandler_base *child)
2000-02-18 03:38:33 +08:00
{
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fhandler_tty_master *arch = (fhandler_tty_master *) archetype;
/* See comment in fhandler_tty_slave::dup. */
child->pc.free_strings ();
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
*(fhandler_tty_master *) child = *arch;
child->set_flags (get_flags ());
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
child->usecount = 0;
arch->usecount++;
report_tty_counts (child, "duped master", "");
2000-02-18 03:38:33 +08:00
return 0;
}
int
fhandler_tty_slave::tcgetattr (struct termios *t)
{
*t = get_ttyp ()->ti;
return 0;
}
int
fhandler_tty_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
fhandler_tty_slave::tcflush (int queue)
2000-02-18 03:38:33 +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);
ret = ((int) len) >= 0 ? 0 : -1;
}
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
fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
{
termios_printf ("ioctl (%x)", cmd);
if (myself->pgid && get_ttyp ()->getpgid () != myself->pgid
* 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
&& myself->ctty == get_unit () && (get_ttyp ()->ti.c_lflag & TOSTOP))
2000-02-18 03:38:33 +08:00
{
/* background process */
* cygheap.h (init_cygheap::manage_console_count): Declare new function. (init_cygheap::console_count): Renamed from open_fhs. Make private. * cygheap.cc (init_cygheap::manage_console_count): Define new function. * dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on elements of fd even when they are about to be closed. * fhandler.h (report_tty_counts): Remove open_fhs from debugging output. * fhandler_console.cc (fhandler_console::open): Use manage_console_count rather than manipulating count directly. (fhandler_console::close): Ditto. (fhandler_console::fixup_after_fork): Ditto. (fhandler_console::fixup_after_exec): Ditto. Don't close handles if close_on_exec. * fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather than manipulating count directly. Reflect change in arguments to report_tty_counts(). (fhandler_tty_slave::close): Ditto for both. (fhandler_tty_slave::dup): Ditto for both. (fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #. (fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to report_tty_counts(). (fhandler_tty_master::init_console): Use manage_console_count() rather than manipulating count directly. * fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't perform any operations if close_on_exec. * fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto. * fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto. * fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto. * pinfo.h (_pinfo::_ctty): Declare new function. (myctty): Declare new macro. (__ctty): Declare new macro. * pinfo.cc (_pinfo::_ctty): Define new function. (_pinfo::set_ctty): Use manage_console_count() rather than manipulating count directly. * signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty #. * syscalls.cc (setsid): Ditto. Use manage_console_count() rather than manipulating count directly.
2005-11-14 12:28:45 +08:00
termios_printf ("bg ioctl pgid %d, tpgid %d, %s", myself->pgid,
get_ttyp ()->getpgid (), myctty ());
raise (SIGTTOU);
2000-02-18 03:38:33 +08:00
}
int retval;
2000-02-18 03:38:33 +08:00
switch (cmd)
{
case TIOCGWINSZ:
case TIOCSWINSZ:
case TIOCLINUX:
case KDGKBMETA:
case KDSKBMETA:
2000-02-18 03:38:33 +08:00
break;
case FIONBIO:
set_nonblocking (*(int *) arg);
retval = 0;
goto out;
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;
2000-02-18 03:38:33 +08:00
default:
set_errno (EINVAL);
return -1;
}
acquire_output_mutex (INFINITE);
get_ttyp ()->cmd = cmd;
get_ttyp ()->ioctl_retval = 0;
int val;
switch (cmd)
{
case TIOCGWINSZ:
get_ttyp ()->arg.winsize = get_ttyp ()->winsize;
if (ioctl_request_event)
SetEvent (ioctl_request_event);
*(struct winsize *) arg = get_ttyp ()->arg.winsize;
if (ioctl_done_event)
WaitForSingleObject (ioctl_done_event, INFINITE);
get_ttyp ()->winsize = get_ttyp ()->arg.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 ()->arg.winsize = *(struct winsize *) arg;
if (ioctl_request_event)
{
get_ttyp ()->ioctl_retval = -EINVAL;
SetEvent (ioctl_request_event);
}
else
{
get_ttyp ()->winsize = *(struct winsize *) arg;
* cygwin/include/signal.h: Add copyright notice. * cygwin.din: Make clock SIGFE. Add clock_gettime, sigwaitinfo, timer_create, timer_delete, timer_settime. * include/cygwin/version.h: Reflect above additions. * fork.cc (fork_child): Call fixup_timers_after_fork. * signal.cc (sigwait): Remove unused variable. * timer.cc: New file. (clock_gettime): Define new function. (timer_tracker): Define new struct used by timer functions. (timer_tracker::timer_tracker): New function. (to_us): New function. (timer_thread): New function. (timer_tracker::settime): New function. (timer_create): New function. (timer_settime): New function. (timer_delete): New function. (fixup_timers_after_fork): New function. * cygthread.cc: Bump thread count. * signal.cc (sigwaitinfo): Define new function. (sigwait): Redefine based on sigwaitinfo. * include/cygwin/signal.h (sigwaitinfo): Declare. (sigwait): Ditto. * dtable.cc (dtable::vfork_parent_restore): Avoid double close of ctty when ctty == ctty_on_hold. * cygtls.h (_threadinfo::threadkill): New element. (_threadinfo::set_threadkill): Declare new function. (_threadinfo::reset_threadkill): Declare new function. * dcrt0.cc (dcrt0_1): Call here so that it will be possible to attach to running process with #(*& Windows Me/9x. (initial_env): Try to initialize strace if uninitialized. * gendef: Don't zero signal if threadkill is set since that will happen in the called function. * signal.cc (sigwait): Ensure cleanup in error conditions. * sigproc.cc (sig_send): Clear packet mask storage. (wait_subproc): Fill in child exit code in siginfo_t structure. * thread.cc (pthread_kill): Set threadkill flag. * tlsoffsets.h: Regenerate. Throughout, use siginfo_t to fill out all signal information for "kernel" signals. * cygtls.h (_threadinfo::set_siginfo): Declare new function. * cygtls.cc (_threadinfo::set_siginfo): Define new function. * dcrt0.cc (do_exit): Accommodate siginfo_t considerations. * exceptions.cc (handle_exceptions): Ditto. (sig_handle_tty_stop): Ditto. (ctrl_c_handler): Use killsys() to send signal. (sigpacket::process): Rename from sig_handle. Use siginfo_t field from sigpacket for everything. (tty_min::kill_pgrp): Accommodate siginfo_t considerations. (fhandler_termios::bg_check): Ditto. * fhandler_tty.cc (fhandler_tty_slave::ioctl): Use killsys() to send signal. * signal.cc (kill_worker): Rewrite to use siginfo_t second argument. (kill_pgrp): Ditto. (kill0): Define new function pulled from kill(). (kill): Rewrite as frontend to kill0. (killsys): Define new function. * sigproc.cc (sigelem): Eliminate. (sigpacket): Move to sigproc.h. Subsume sigelem. (pending_signals): Use sigpacket rather than sigelem for everything. (sig_clear): Ditto. (wait_sig): Ditto. (sig_send): Rewrite to use siginfo_t argument. (sig_send): New function wratpper to sig_send with siginfo_t argument. (wait_subproc): Accommodate siginfo_t considerations. * thread.cc (pthread_kill): Ditto. * sigproc.h (sigpacket): Move here. (sigpacket::process): Declare "new" function. (sig_handle): Eliminate declaration. (sig_send): Declare with new paramaters. (killsys): Declare new function. (kill_pgrp): Declare. * winsup.h: Move some signal-specific stuff to sigproc.h. * include/cygwin/signal.h: Tweak some siginfo_t stuff.
2004-01-19 13:46:54 +08:00
killsys (-get_ttyp ()->getpgid (), SIGWINCH);
}
if (ioctl_done_event)
WaitForSingleObject (ioctl_done_event, INFINITE);
}
break;
case TIOCLINUX:
val = *(unsigned char *) arg;
if (val != 6 || !ioctl_request_event || !ioctl_done_event)
get_ttyp ()->ioctl_retval = -EINVAL;
else
{
get_ttyp ()->arg.value = val;
SetEvent (ioctl_request_event);
WaitForSingleObject (ioctl_done_event, INFINITE);
*(unsigned char *) arg = (unsigned char) (get_ttyp ()->arg.value);
}
break;
case KDGKBMETA:
if (ioctl_request_event)
{
SetEvent (ioctl_request_event);
if (ioctl_done_event)
WaitForSingleObject (ioctl_done_event, INFINITE);
*(int *) arg = get_ttyp ()->arg.value;
}
else
get_ttyp ()->ioctl_retval = -EINVAL;
break;
case KDSKBMETA:
if (ioctl_request_event)
{
get_ttyp ()->arg.value = (int) arg;
SetEvent (ioctl_request_event);
if (ioctl_done_event)
WaitForSingleObject (ioctl_done_event, INFINITE);
}
else
get_ttyp ()->ioctl_retval = -EINVAL;
break;
}
release_output_mutex ();
retval = get_ttyp ()->ioctl_retval;
if (retval < 0)
{
set_errno (-retval);
retval = -1;
}
out:
termios_printf ("%d = ioctl (%x)", retval, cmd);
return retval;
2000-02-18 03:38:33 +08:00
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
int __stdcall
fhandler_tty_slave::fstat (struct __stat64 *st)
{
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,
then fake uid and gid to strict, system-like values. */
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
fhandler_tty_slave::fch_open_handles ()
{
char buf[MAX_PATH];
tc = cygwin_shared->tty[get_unit ()];
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;
}
/* These members are optional, no error checking */
shared_name (buf, OUTPUT_DONE_EVENT, get_unit ());
output_done_event = OpenEvent (WRITE_DAC | WRITE_OWNER, TRUE, buf);
shared_name (buf, IOCTL_REQUEST_EVENT, get_unit ());
ioctl_request_event = OpenEvent (WRITE_DAC | WRITE_OWNER, TRUE, buf);
shared_name (buf, IOCTL_DONE_EVENT, get_unit ());
ioctl_done_event = OpenEvent (WRITE_DAC | WRITE_OWNER, TRUE, buf);
return true;
}
/* Helper function for fchmod and fchown, which sets the new security
descriptor on all objects representing the tty. */
int
fhandler_tty_slave::fch_set_sd (security_descriptor &sd, bool chown)
{
security_descriptor sd_old;
get_object_sd (input_available_event, sd_old);
if (!set_object_sd (input_available_event, sd, chown)
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
&& !set_object_sd (output_mutex, sd, chown)
&& !set_object_sd (input_mutex, sd, chown)
&& !set_object_sd (inuse, sd, chown)
&& (!output_done_event
|| !set_object_sd (output_done_event, sd, chown))
&& (!ioctl_request_event
|| !set_object_sd (ioctl_request_event, sd, chown))
&& (!ioctl_done_event
|| !set_object_sd (ioctl_done_event, sd, chown)))
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);
if (!output_done_event)
set_object_sd (output_done_event, sd_old, chown);
if (!ioctl_request_event)
set_object_sd (ioctl_request_event, sd_old, chown);
if (!ioctl_done_event)
set_object_sd (ioctl_done_event, sd_old, chown);
return -1;
}
/* Helper function for fchmod and fchown, which closes all object handles in
the tty. */
void
fhandler_tty_slave::fch_close_handles ()
{
close_maybe (get_io_handle ());
close_maybe (get_output_handle ());
close_maybe (output_done_event);
close_maybe (ioctl_done_event);
close_maybe (ioctl_request_event);
close_maybe (input_available_event);
close_maybe (output_mutex);
close_maybe (input_mutex);
close_maybe (inuse);
}
int __stdcall
fhandler_tty_slave::fchmod (mode_t mode)
{
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));
InitializeSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
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
fhandler_tty_slave::fchown (__uid32_t uid, __gid32_t gid)
{
int ret = -1;
bool to_close = false;
mode_t mode = 0;
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
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));
InitializeSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
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
*/
* 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::fhandler_pty_master ()
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
: fhandler_tty_common (), pktmode (0), need_nl (0), dwProcessId (0)
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
{
/* Note that allocate returns with the tty lock set if it was successful. */
int ntty = cygwin_shared->tty.allocate (false);
* 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
if (ntty < 0)
2000-02-18 03:38:33 +08:00
return 0;
dev().devn = FHDEV (DEV_TTYM_MAJOR, ntty);
if (!setup (true))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
{
* dcrt0.cc (dll_crt0_0): Call tty_list::init_session here. (dll_crt0_1): Reflect renaming from tty_init to tty::init_session. (do_exit): Reflect moving of tty_terminate into tty_list. * exceptions.cc (events_init): Move tty_mutex stuff elsewhere. * fhandler_console.cc (set_console_title): Use lock_ttys class. * fhandler_termios.cc (fhandler_termios::bg_check): Make debug output more accurate. * fhandler_tty.cc (fhandler_tty_slave::open): Reflect move of attach_tty into tty_list class. Don't attempt to grab master end of pty if master doesn't exist. (fhandler_pty_master::open): Reflect move of allocate_tty into tty_list class. Use lock_ttys::release to release mutex. Improve debugging output. (fhandler_pty_master::setup): Remove if 0'ed block. Fix argument to SetNamedPipeHandleState. * pinfo.cc (_pinfo::set_ctty): Lock ttys before setting sid/pgid. Improve debugging. Add temporary debugging. * tty.cc (tty_list::init_session): New function. (tty::init_session): Rename from tty_init. Reflect move of attach_tty to tty_list class. (tty::create_master): Rename from create_tty_master. (tty_list::attach): Rename from attach_tty. Reflect renaming of connect_tty to connect. Ditto for allocate_tty. (tty_terminate): Delete. (tty_list::terminate): Subsume tty_terminate. Use lock_ttys rather than manipulating mutex directly. (tty_list::allocate): Rename from allocate_tty. Use lock_ttys rather than manipulating mutex directly. Don't set sid here since linux apparently doesn't do this. Reflect move of create_tty_master into tty. (lock_ttys::lock_ttys): Define new constructor. (lock_ttys::release): New function. * tty.h (tty::exists): Return false immediately if !master_pid. (tty::set_master_closed): Define new function. (tty::create_master): Ditto. (tty::init_session): Ditto. (tty_list::mutex): New field. (tty_list::allocate): Define new function. (tty_list::connect): Ditto. (tty_list::attach): Ditto. (tty_list::init_session): Ditto. (lock_ttys): New class. (tty_init): Delete declaration. (tty_terminate): Ditto. (attach_tty): Ditto. (create_tty_master): Ditto.
2006-06-04 04:32:07 +08:00
lock_ttys::release ();
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
return 0;
}
* dcrt0.cc (dll_crt0_0): Call tty_list::init_session here. (dll_crt0_1): Reflect renaming from tty_init to tty::init_session. (do_exit): Reflect moving of tty_terminate into tty_list. * exceptions.cc (events_init): Move tty_mutex stuff elsewhere. * fhandler_console.cc (set_console_title): Use lock_ttys class. * fhandler_termios.cc (fhandler_termios::bg_check): Make debug output more accurate. * fhandler_tty.cc (fhandler_tty_slave::open): Reflect move of attach_tty into tty_list class. Don't attempt to grab master end of pty if master doesn't exist. (fhandler_pty_master::open): Reflect move of allocate_tty into tty_list class. Use lock_ttys::release to release mutex. Improve debugging output. (fhandler_pty_master::setup): Remove if 0'ed block. Fix argument to SetNamedPipeHandleState. * pinfo.cc (_pinfo::set_ctty): Lock ttys before setting sid/pgid. Improve debugging. Add temporary debugging. * tty.cc (tty_list::init_session): New function. (tty::init_session): Rename from tty_init. Reflect move of attach_tty to tty_list class. (tty::create_master): Rename from create_tty_master. (tty_list::attach): Rename from attach_tty. Reflect renaming of connect_tty to connect. Ditto for allocate_tty. (tty_terminate): Delete. (tty_list::terminate): Subsume tty_terminate. Use lock_ttys rather than manipulating mutex directly. (tty_list::allocate): Rename from allocate_tty. Use lock_ttys rather than manipulating mutex directly. Don't set sid here since linux apparently doesn't do this. Reflect move of create_tty_master into tty. (lock_ttys::lock_ttys): Define new constructor. (lock_ttys::release): New function. * tty.h (tty::exists): Return false immediately if !master_pid. (tty::set_master_closed): Define new function. (tty::create_master): Ditto. (tty::init_session): Ditto. (tty_list::mutex): New field. (tty_list::allocate): Define new function. (tty_list::connect): Ditto. (tty_list::attach): Ditto. (tty_list::init_session): Ditto. (lock_ttys): New class. (tty_init): Delete declaration. (tty_terminate): Ditto. (attach_tty): Ditto. (create_tty_master): Ditto.
2006-06-04 04:32:07 +08:00
lock_ttys::release ();
set_flags ((flags & ~O_TEXT) | O_BINARY);
set_open_status ();
/* FIXME: Do this better someday */
fhandler_pty_master *arch = (fhandler_tty_master *) cmalloc_abort (HEAP_ARCHETYPES, sizeof (*this));
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
*((fhandler_pty_master **) cygheap->fdtab.add_archetype ()) = arch;
archetype = arch;
*arch = *this;
arch->dwProcessId = GetCurrentProcessId ();
2000-02-18 03:38:33 +08:00
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
usecount = 0;
arch->usecount++;
* dcrt0.cc (dll_crt0_0): Call tty_list::init_session here. (dll_crt0_1): Reflect renaming from tty_init to tty::init_session. (do_exit): Reflect moving of tty_terminate into tty_list. * exceptions.cc (events_init): Move tty_mutex stuff elsewhere. * fhandler_console.cc (set_console_title): Use lock_ttys class. * fhandler_termios.cc (fhandler_termios::bg_check): Make debug output more accurate. * fhandler_tty.cc (fhandler_tty_slave::open): Reflect move of attach_tty into tty_list class. Don't attempt to grab master end of pty if master doesn't exist. (fhandler_pty_master::open): Reflect move of allocate_tty into tty_list class. Use lock_ttys::release to release mutex. Improve debugging output. (fhandler_pty_master::setup): Remove if 0'ed block. Fix argument to SetNamedPipeHandleState. * pinfo.cc (_pinfo::set_ctty): Lock ttys before setting sid/pgid. Improve debugging. Add temporary debugging. * tty.cc (tty_list::init_session): New function. (tty::init_session): Rename from tty_init. Reflect move of attach_tty to tty_list class. (tty::create_master): Rename from create_tty_master. (tty_list::attach): Rename from attach_tty. Reflect renaming of connect_tty to connect. Ditto for allocate_tty. (tty_terminate): Delete. (tty_list::terminate): Subsume tty_terminate. Use lock_ttys rather than manipulating mutex directly. (tty_list::allocate): Rename from allocate_tty. Use lock_ttys rather than manipulating mutex directly. Don't set sid here since linux apparently doesn't do this. Reflect move of create_tty_master into tty. (lock_ttys::lock_ttys): Define new constructor. (lock_ttys::release): New function. * tty.h (tty::exists): Return false immediately if !master_pid. (tty::set_master_closed): Define new function. (tty::create_master): Ditto. (tty::init_session): Ditto. (tty_list::mutex): New field. (tty_list::allocate): Define new function. (tty_list::connect): Ditto. (tty_list::attach): Ditto. (tty_list::init_session): Ditto. (lock_ttys): New class. (tty_init): Delete declaration. (tty_terminate): Ditto. (attach_tty): Ditto. (create_tty_master): Ditto.
2006-06-04 04:32:07 +08:00
char buf[sizeof ("opened pty master for ttyNNNNNNNNNNN")];
__small_sprintf (buf, "opened pty master for tty%d", get_unit ());
report_tty_counts (this, buf, "");
2000-02-18 03:38:33 +08:00
return 1;
}
_off64_t
fhandler_tty_common::lseek (_off64_t, int)
{
set_errno (ESPIPE);
return -1;
}
2000-02-18 03:38:33 +08:00
int
fhandler_tty_common::close ()
{
termios_printf ("tty%d <%p,%p> closing", get_unit (), get_handle (), get_output_handle ());
2000-02-18 03:38:33 +08:00
if (output_done_event && !CloseHandle (output_done_event))
termios_printf ("CloseHandle (output_done_event), %E");
if (ioctl_done_event && !CloseHandle (ioctl_done_event))
termios_printf ("CloseHandle (ioctl_done_event), %E");
if (ioctl_request_event && !CloseHandle (ioctl_request_event))
termios_printf ("CloseHandle (ioctl_request_event), %E");
if (!ForceCloseHandle (input_mutex))
termios_printf ("CloseHandle (input_mutex<%p>), %E", input_mutex);
* sync.h (new_muto): Just accept an argument which denotes the name of the muto. Use this argument to construct static storage. * cygheap.cc (cygheap_init): Reflect above change. * exceptions.cc (events_init): Ditto. * malloc.cc (malloc_init): Ditto. * path.cc (cwdstuff::init): Ditto. * cygheap.h (cwdstuff): Change name of lock element to make it less generic. * path.cc (cwdstuff::get_hash): Ditto. (cwdstuff::get_initial): Ditto. (cwdstuff::set): Ditto. (cwdstuff::get): Ditto. * sigproc.cc (proc_subproc): Ditto. * debug.cc (lock_debug): Change to method. Use method rather than macro throughout. * tty.h (tty_min::kill_pgrp): Declare new method. * fhandler_termios.cc (tty_min::kill_pgrp): New method. (fhandler_termios::line_edit): Use new method for killing process. * dcrt0.cc (do_exit): Ditto. * dtable.cc (dtable::get_debugger_info): New method for inheriting dtable info from a debugger. * tty.cc (tty_init): Attempt to grab file handle info from parent debugger, if appropriate. # dtable.cc (dtable::stdio_init): Make this a method. (dtable::init_std_file_from_handle): Don't set fd unless it's not open. (dtable::build_fhandler_from_name): Move name setting to dtable::build_fhandler. (dtable::build_fhandler): Add win32 name parameter. * dcrt0.cc (dll_crt0_1): Change to use dtable stdio_init. * dtable.h (dtable): Reflect build_fhandler parameter change. * mmap.cc (mmap_record::alloc_fh): Don't set name parameter in build_fhandler. * net.cc (fdsock): Remove set_name call since it is now handled by build_fhandler. * sigproc.cc (proc_subproc): Release muto as early as possible.
2002-02-23 03:33:41 +08:00
if (!ForceCloseHandle (output_mutex))
termios_printf ("CloseHandle (output_mutex<%p>), %E", output_mutex);
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 ());
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;
}
int
fhandler_pty_master::close ()
{
#if 0
while (accept_input () > 0)
continue;
#endif
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
archetype->usecount--;
report_tty_counts (this, "closing master", "");
2000-02-18 03:38:33 +08:00
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
if (archetype->usecount)
2000-02-18 03:38:33 +08:00
{
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
#ifdef DEBUGGING
if (archetype->usecount < 0)
system_printf ("error: usecount %d", archetype->usecount);
#endif
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
termios_printf ("just returning because archetype usecount is != 0");
return 0;
}
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fhandler_tty_master *arch = (fhandler_tty_master *) archetype;
termios_printf ("closing from_master(%p)/to_master(%p) since we own them(%d)",
arch->from_master, arch->to_master, arch->dwProcessId);
if (cygwin_finished_initializing)
{
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (arch->master_ctl && get_ttyp ()->master_pid == myself->pid)
{
char buf[MAX_PATH];
pipe_request req = { (DWORD) -1 };
pipe_reply repl;
DWORD len;
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-tty%d-master-ctl",
&installation_key, get_unit ());
CallNamedPipe (buf, &req, sizeof req, &repl, sizeof repl, &len, 500);
CloseHandle (arch->master_ctl);
arch->master_thread->detach ();
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
}
if (!ForceCloseHandle (arch->from_master))
termios_printf ("error closing from_master %p, %E", arch->from_master);
if (!ForceCloseHandle (arch->to_master))
termios_printf ("error closing from_master %p, %E", arch->to_master);
}
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fhandler_tty_common::close ();
* dcrt0.cc (dll_crt0_0): Call tty_list::init_session here. (dll_crt0_1): Reflect renaming from tty_init to tty::init_session. (do_exit): Reflect moving of tty_terminate into tty_list. * exceptions.cc (events_init): Move tty_mutex stuff elsewhere. * fhandler_console.cc (set_console_title): Use lock_ttys class. * fhandler_termios.cc (fhandler_termios::bg_check): Make debug output more accurate. * fhandler_tty.cc (fhandler_tty_slave::open): Reflect move of attach_tty into tty_list class. Don't attempt to grab master end of pty if master doesn't exist. (fhandler_pty_master::open): Reflect move of allocate_tty into tty_list class. Use lock_ttys::release to release mutex. Improve debugging output. (fhandler_pty_master::setup): Remove if 0'ed block. Fix argument to SetNamedPipeHandleState. * pinfo.cc (_pinfo::set_ctty): Lock ttys before setting sid/pgid. Improve debugging. Add temporary debugging. * tty.cc (tty_list::init_session): New function. (tty::init_session): Rename from tty_init. Reflect move of attach_tty to tty_list class. (tty::create_master): Rename from create_tty_master. (tty_list::attach): Rename from attach_tty. Reflect renaming of connect_tty to connect. Ditto for allocate_tty. (tty_terminate): Delete. (tty_list::terminate): Subsume tty_terminate. Use lock_ttys rather than manipulating mutex directly. (tty_list::allocate): Rename from allocate_tty. Use lock_ttys rather than manipulating mutex directly. Don't set sid here since linux apparently doesn't do this. Reflect move of create_tty_master into tty. (lock_ttys::lock_ttys): Define new constructor. (lock_ttys::release): New function. * tty.h (tty::exists): Return false immediately if !master_pid. (tty::set_master_closed): Define new function. (tty::create_master): Ditto. (tty::init_session): Ditto. (tty_list::mutex): New field. (tty_list::allocate): Define new function. (tty_list::connect): Ditto. (tty_list::attach): Ditto. (tty_list::init_session): Ditto. (lock_ttys): New class. (tty_init): Delete declaration. (tty_terminate): Ditto. (attach_tty): Ditto. (create_tty_master): Ditto.
2006-06-04 04:32:07 +08:00
if (hExeced || get_ttyp ()->master_pid != myself->pid)
termios_printf ("not clearing: %d, master_pid %d", hExeced, get_ttyp ()->master_pid);
else
get_ttyp ()->set_master_closed ();
2000-02-18 03:38:33 +08:00
return 0;
}
* sigproc.h (wait_for_sigthread): Eliminate parameter. * sigproc.cc (wait_for_sigthread): Ditto. Don't synchronize with wait_sig after receiving an event that it is ready to go. (init_sig_pipe): New function. (wait_sig): Call init_sig_pipe to create pipes for communicating signals to this process. Don't send sigCONT signal when initializing. * fork.cc (frok::child): Accommodate wait_for_sigpipe parameter change. * fhandler.h (fhandler_*::write): Make ssize_t/__stdcall. (fhandler_*::write_overlapped): Ditto. (fhandler_*::raw_write): Ditto. (fhandler_*::readv): Ditto. (fhandler_*::writev): Ditto. (fhandler_*::raw_read): Make __stdcall. * fhandler: Accommodate changes to read/write functions throughout. * fhandler_clipboard.cc: Ditto. * fhandler_console.cc: Ditto. * fhandler_dsp.cc: Ditto. * fhandler_fifo.cc: Ditto. * fhandler_mailslot.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_mem.cc: Ditto. * fhandler_random.cc: Ditto. * fhandler_tape.cc: Ditto. * fhandler_tty.cc: Ditto. * fhandler_virtual.cc: Ditto. * fhandler_windows.cc: Ditto. * fhandler_zero.cc: Ditto. * syscalls.cc (readv): Use ssize_t as temp variable. * fhandler.cc (fhandler_base::read): Coerce returned len to signed or it will never be treated as < 0. (fhandler_base::wait_overlapped): Minimize calls to GetLastError. Remove duplicate debugging test. Fix error return. * fhandler.h (fhandler_fifo::fifo_name): Declare new function. (fhandler_fifo::close): Ditto. (fhandler_fifo::dup): Ditto. (fhandler_fifo::close_on_exec): Ditto. * fhandler.cc (fhandler_fifo::fifo_name): Define new function. (FIFO_BUF_SIZE): New define. (cnp): Ditto. (fhandler_fifo::open): Rework. Use cnp to open named pipe. Always open write side as a client. Open dummy client when writing and can't connect. (wait): Rework. Implement fifo_wait_for_next_client. Handle signals during connect better. Add new fifo_wait_for_server code which polls (sigh) waiting for server. (fhandler_fifo::raw_read): Handle transition states when one client closes and another is available. (fhandler_fifo::close): Define. (fhandler_fifo::dup): Ditto. (fhandler_fifo::close_on_exec): Ditto.
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)
{
int i;
char *p = (char *) ptr;
termios ti = tc->ti;
for (i = 0; i < (int) len; i++)
{
line_edit_status status = line_edit (p++, 1, ti);
if (status > line_edit_signalled)
{
if (status != line_edit_pipe_full)
i = -1;
break;
}
}
return i;
2000-02-18 03:38:33 +08:00
}
void __stdcall
fhandler_pty_master::read (void *ptr, size_t& len)
2000-02-18 03:38:33 +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
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
fhandler_pty_master::tcflush (int queue)
2000-02-18 03:38:33 +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)
{
switch (cmd)
{
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);
case FIONBIO:
set_nonblocking (*(int *) arg);
break;
default:
set_errno (EINVAL);
return -1;
2000-02-18 03:38:33 +08:00
}
return 0;
}
char *
* 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::ptsname ()
2000-02-18 03:38:33 +08:00
{
static char buf[TTY_NAME_MAX];
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
__small_sprintf (buf, "/dev/tty%d", get_unit ());
2000-02-18 03:38:33 +08:00
return buf;
}
void
* Use new unified status_flag accessor methods from classes fhandler_*, tty_min, mtinfo and fs_info thoroughout. * fhandler.h: Redefine all set_close_on_exec methods to take a bool argument. (enum conn_state): Rename from connect_state. (class fhandler_base): Rename some status flags to align with accessor method names. Drop encoded flag entirely. Unify status accessor methods. Const'ify all read accessor methods. (class fhandler_socket): Ditto. (class fhandler_dev_raw): Ditto. * fhandler_disk_file.cc (fhandler_base::fstat_fs): Use fs.fs_is_fat() instead of evaluating FATness of file system here. (fhandler_disk_file::opendir): Drop call to set_encoded(). (fhandler_disk_file::readdir): Use pc.isencoded() directly. * mtinfo.h (class mtinfo_drive): Const'ify all read accessor methods. * path.cc (fsinfo_cnt): Add. (fs_info::update): Accomodate class changes. Evaluate file system name specific flags right here. Add thread safety for reading and writing global fsinfo array. * path.h (enum path_types): Drop values for flags kept in fs already. (struct fs_info): Move status informatin into private struct type status_flags. Add accessor methods. Remove path and file system name string arrays in favor of status bits. (class path_conv): Use new fs_info status information where appropriate. (path_conf::fs_has_ea): Rename from fs_fast_ea. (path_conf::fs_has_acls): New method. (path_conf::root_dir): Remove. (path_conf::volname): Remove. * syscalls (statfs): Evaluate root dir locally. * tty.h (class tty_min): Unify status accessor methods. Const'ify all read accessor methods.
2004-04-10 21:45:10 +08:00
fhandler_tty_common::set_close_on_exec (bool val)
2000-02-18 03:38:33 +08:00
{
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
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
}
void
fhandler_tty_slave::fixup_after_fork (HANDLE parent)
{
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
// fork_fixup (parent, inuse, "inuse");
// fhandler_tty_common::fixup_after_fork (parent);
* cygheap.h (init_cygheap::manage_console_count): Declare new function. (init_cygheap::console_count): Renamed from open_fhs. Make private. * cygheap.cc (init_cygheap::manage_console_count): Define new function. * dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on elements of fd even when they are about to be closed. * fhandler.h (report_tty_counts): Remove open_fhs from debugging output. * fhandler_console.cc (fhandler_console::open): Use manage_console_count rather than manipulating count directly. (fhandler_console::close): Ditto. (fhandler_console::fixup_after_fork): Ditto. (fhandler_console::fixup_after_exec): Ditto. Don't close handles if close_on_exec. * fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather than manipulating count directly. Reflect change in arguments to report_tty_counts(). (fhandler_tty_slave::close): Ditto for both. (fhandler_tty_slave::dup): Ditto for both. (fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #. (fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to report_tty_counts(). (fhandler_tty_master::init_console): Use manage_console_count() rather than manipulating count directly. * fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't perform any operations if close_on_exec. * fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto. * fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto. * fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto. * pinfo.h (_pinfo::_ctty): Declare new function. (myctty): Declare new macro. (__ctty): Declare new macro. * pinfo.cc (_pinfo::_ctty): Define new function. (_pinfo::set_ctty): Use manage_console_count() rather than manipulating count directly. * signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty #. * syscalls.cc (setsid): Ditto. Use manage_console_count() rather than manipulating count directly.
2005-11-14 12:28:45 +08:00
report_tty_counts (this, "inherited", "");
}
2000-02-18 03:38:33 +08:00
void
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fhandler_tty_slave::fixup_after_exec ()
2000-02-18 03:38:33 +08:00
{
if (!close_on_exec ())
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fixup_after_fork (NULL);
2000-02-18 03:38:33 +08:00
}
int
fhandler_tty_master::init_console ()
{
* 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
console = (fhandler_console *) build_fh_dev (*console_dev, "/dev/ttym");
2000-02-18 03:38:33 +08:00
if (console == NULL)
return -1;
console->init (INVALID_HANDLE_VALUE, GENERIC_READ | GENERIC_WRITE, O_BINARY);
* cygheap.h (init_cygheap::manage_console_count): Declare new function. (init_cygheap::console_count): Renamed from open_fhs. Make private. * cygheap.cc (init_cygheap::manage_console_count): Define new function. * dtable.cc (dtable::fixup_after_exec): Always call fixup_after_exec on elements of fd even when they are about to be closed. * fhandler.h (report_tty_counts): Remove open_fhs from debugging output. * fhandler_console.cc (fhandler_console::open): Use manage_console_count rather than manipulating count directly. (fhandler_console::close): Ditto. (fhandler_console::fixup_after_fork): Ditto. (fhandler_console::fixup_after_exec): Ditto. Don't close handles if close_on_exec. * fhandler_tty.cc (fhandler_tty_slave::open): Use manage_console_count() rather than manipulating count directly. Reflect change in arguments to report_tty_counts(). (fhandler_tty_slave::close): Ditto for both. (fhandler_tty_slave::dup): Ditto for both. (fhandler_tty_slave::ioctl): Use myctty() rather than raw ctty #. (fhandler_tty_slave::fixup_after_fork): Reflect change in arguments to report_tty_counts(). (fhandler_tty_master::init_console): Use manage_console_count() rather than manipulating count directly. * fhandler_clipboard.cc (fhandler_dev_clipboard::fixup_after_exec): Don't perform any operations if close_on_exec. * fhandler_dsp.cc (fhandler_dev_dsp::fixup_after_exec): Ditto. * fhandler_raw.cc (fhandler_dev_raw::fixup_after_exec): Ditto. * fhandler_serial.cc (fhandler_serial::fixup_after_exec): Ditto. * pinfo.h (_pinfo::_ctty): Declare new function. (myctty): Declare new macro. (__ctty): Declare new macro. * pinfo.cc (_pinfo::_ctty): Define new function. (_pinfo::set_ctty): Use manage_console_count() rather than manipulating count directly. * signal.cc (kill_pgrp): Use myctty() and __ctty() macros rather than raw ctty #. * syscalls.cc (setsid): Ditto. Use manage_console_count() rather than manipulating count directly.
2005-11-14 12:28:45 +08:00
cygheap->manage_console_count ("fhandler_tty_master::init_console", -1, true);
* Use new unified status_flag accessor methods from classes fhandler_*, tty_min, mtinfo and fs_info thoroughout. * fhandler.h: Redefine all set_close_on_exec methods to take a bool argument. (enum conn_state): Rename from connect_state. (class fhandler_base): Rename some status flags to align with accessor method names. Drop encoded flag entirely. Unify status accessor methods. Const'ify all read accessor methods. (class fhandler_socket): Ditto. (class fhandler_dev_raw): Ditto. * fhandler_disk_file.cc (fhandler_base::fstat_fs): Use fs.fs_is_fat() instead of evaluating FATness of file system here. (fhandler_disk_file::opendir): Drop call to set_encoded(). (fhandler_disk_file::readdir): Use pc.isencoded() directly. * mtinfo.h (class mtinfo_drive): Const'ify all read accessor methods. * path.cc (fsinfo_cnt): Add. (fs_info::update): Accomodate class changes. Evaluate file system name specific flags right here. Add thread safety for reading and writing global fsinfo array. * path.h (enum path_types): Drop values for flags kept in fs already. (struct fs_info): Move status informatin into private struct type status_flags. Add accessor methods. Remove path and file system name string arrays in favor of status bits. (class path_conv): Use new fs_info status information where appropriate. (path_conf::fs_has_ea): Rename from fs_fast_ea. (path_conf::fs_has_acls): New method. (path_conf::root_dir): Remove. (path_conf::volname): Remove. * syscalls (statfs): Evaluate root dir locally. * tty.h (class tty_min): Unify status accessor methods. Const'ify all read accessor methods.
2004-04-10 21:45:10 +08:00
console->uninterruptible_io (true);
2000-02-18 03:38:33 +08:00
return 0;
}
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
extern "C" BOOL WINAPI GetNamedPipeClientProcessId (HANDLE, PULONG);
/* 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.
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
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
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;
BOOL ret;
DWORD pid;
termios_printf ("Entered");
while (!exit && (ConnectNamedPipe (master_ctl, NULL) || GetLastError () == ERROR_PIPE_CONNECTED))
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
{
pipe_reply repl = { NULL, NULL, 0 };
bool deimp = false;
BOOL allow = FALSE;
ACCESS_MASK access = EVENT_MODIFY_STATE;
HANDLE client = NULL;
if (!ReadFile (master_ctl, &req, sizeof req, &len, NULL))
{
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;
}
if (!OpenThreadToken (GetCurrentThread (), TOKEN_QUERY, TRUE, &token))
{
termios_printf ("OpenThreadToken, %E");
goto reply;
}
len = sizeof ps;
ret = AccessCheck (sd, token, access, &map, &ps, &len, &access, &allow);
CloseHandle (token);
if (!ret)
{
termios_printf ("AccessCheck, %E");
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;
}
if (allow)
{
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
pty_master_thread (VOID *arg)
{
return ((fhandler_pty_master *) arg)->pty_master_thread ();
}
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
bool
fhandler_pty_master::setup (bool ispty)
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
{
int res;
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
security_descriptor sd;
SECURITY_ATTRIBUTES sa = { sizeof (SECURITY_ATTRIBUTES), NULL, TRUE };
tty& t = *cygwin_shared->tty[get_unit ()];
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
tcinit (&t, true); /* Set termios information. Force initialization. */
const char *errstr = NULL;
DWORD pipe_mode = PIPE_NOWAIT;
/* Create communication pipes */
char pipename[sizeof("ttyNNNN-from-master")];
__small_sprintf (pipename, "tty%d-from-master", get_unit ());
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
res = fhandler_pipe::create_selectable (ispty ? &sec_none : &sec_none_nih,
from_master, get_output_handle (),
128 * 1024, pipename);
if (res)
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
{
errstr = "input pipe";
goto err;
}
if (!SetNamedPipeHandleState (get_output_handle (), &pipe_mode, NULL, NULL))
termios_printf ("can't set output_handle(%p) to non-blocking mode",
get_output_handle ());
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
__small_sprintf (pipename, "tty%d-to-master", get_unit ());
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
res = fhandler_pipe::create_selectable (ispty ? &sec_none : &sec_none_nih,
get_io_handle (), to_master,
128 * 1024, pipename);
if (res)
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
{
errstr = "output pipe";
goto err;
}
need_nl = 0;
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
/* Create security attribute. Default permissions are 0620. */
sd.malloc (sizeof (SECURITY_DESCRIPTOR));
InitializeSecurityDescriptor (sd, SECURITY_DESCRIPTOR_REVISION);
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;
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
/* Create synchronisation events */
if (!ispty)
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
{
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(output_done_event = t.get_event (errstr = OUTPUT_DONE_EVENT, &sa)))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
goto err;
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(ioctl_done_event = t.get_event (errstr = IOCTL_DONE_EVENT, &sa)))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
goto err;
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(ioctl_request_event = t.get_event (errstr = IOCTL_REQUEST_EVENT,
&sa)))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
goto err;
}
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
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)
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
goto err;
char buf[MAX_PATH];
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
errstr = shared_name (buf, OUTPUT_MUTEX, t.ntty);
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(output_mutex = CreateMutex (&sa, FALSE, buf)))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
goto err;
errstr = shared_name (buf, INPUT_MUTEX, t.ntty);
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
if (!(input_mutex = CreateMutex (&sa, FALSE, buf)))
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
goto err;
/* Create master control pipe which allows the master to duplicate
the pty pipe handles to processes which deserve it. */
__small_sprintf (buf, "\\\\.\\pipe\\cygwin-%S-tty%d-master-ctl",
&installation_key, get_unit ());
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)
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
{
errstr = "pty master control pipe";
goto err;
}
master_thread = new cygthread (::pty_master_thread, this, "pty_master");
if (!master_thread)
{
errstr = "pty master control thread";
goto err;
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
}
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
t.from_master = from_master;
t.to_master = to_master;
// /* screws up tty master */ ProtectHandle1INH (output_mutex, output_mutex);
// /* screws up tty master */ ProtectHandle1INH (input_mutex, input_mutex);
t.winsize.ws_col = 80;
t.winsize.ws_row = 25;
t.master_pid = myself->pid;
termios_printf ("tty%d opened - from_slave %p, to_slave %p", t.ntty,
get_io_handle (), get_output_handle ());
return true;
err:
__seterrno ();
close_maybe (get_io_handle ());
close_maybe (get_output_handle ());
close_maybe (output_done_event);
close_maybe (ioctl_done_event);
close_maybe (ioctl_request_event);
close_maybe (input_available_event);
close_maybe (output_mutex);
close_maybe (input_mutex);
close_maybe (from_master);
close_maybe (to_master);
* autoload.cc (GetNamedPipeClientProcessId): Define. * fhandler.h (fhandler_tty_slave::fch_open_handles): Declare private. (fhandler_tty_slave::fch_close_handles): Ditto. (fhandler_tty_slave::cygserver_attach_tty): Drop declaration. (fhandler_tty_slave::fstat): Declare public. (fhandler_tty_slave::fchmod): Declare public. (fhandler_tty_slave::fchown): Declare public. (class fhandler_pty_master): Add master_ctl handle. (fhandler_pty_master::pty_master_thread): Declare public. * fhandler_termios.cc (fhandler_termios::tcinit): If the process is started from a non-Cygwin process, make it tty process group leader. * fhandler_tty.cc: Throughout accommodate additional security related arguments in calls to functions creating or opening objects. (close_maybe): Move to start of file to reuse it in other methods. (struct pipe_request): Define. (struct pipe_reply): Define. (fhandler_tty_slave::open): Throughout, try to open synchronization objects with MAXIMUM_ALLOWED permissions. Drop call to cygserver. Try to duplicate pipe handles via master_ctl pipe if duplicating directly doesn't work. (fhandler_tty_slave::cygserver_attach_tty): Remove. (fhandler_tty_slave::init): Close unused incoming pipe handle. (fhandler_pty_master::close): Send exit message to master control thread and close master_ctl handle. (fhandler_pty_master::pty_master_thread): New method, implementing the master control thread. (pty_master_thread): Static helper to start master control thread. (fhandler_pty_master::setup): Simplify creating pipe inheritance. Make sure we're the one creating the input_available_event. Add comment to explain why. Create master_ctl pipe and start master control thread. Close master_ctl handle in case of error. * security.cc (alloc_sd): Add code to handle tty objects. Add comments to explain what exactly is required. (get_object_sd): New function. (get_object_attribute): New function. (create_object_sd_from_attribute): New function. (set_object_sd): New function. (set_object_attribute): New function. (set_file_attribute): Change attribute type to mode_t. * security.h (set_file_attribute): Change attribute type to mode_t. (get_object_sd): Declare. (get_object_attribute): Declare. (create_object_sd_from_attribute): Declare. (set_object_sd): Declare. (set_object_attribute): Declare. * tty.cc (tty::slave_alive): Implement directly instead of via alive. (tty::exists): Open mutex handle with READ_CONTROL access. (tty::alive): Remove. (tty::open_output_mutex): Convert to inline method. (tty::open_input_mutex): Ditto. (tty::open_mutex): Take additional ACCESS_MASK parameter for the mutex open access mask. (tty::open_inuse): New method. (tty::create_inuse): Take PSECURITY_ATTRIBUTES parameter. Drop fmt name parameter. Always create TTY_SLAVE_ALIVE event. (tty::get_event): Take additional PSECURITY_ATTRIBUTES parameter for CreateEvent. * tty.h (class tty): Change declarations according to aforementioned changes. (tty::open_output_mutex): Implement as inline method. (tty::open_input_mutex): Ditto.
2010-04-20 03:52:43 +08:00
close_maybe (master_ctl);
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
termios_printf ("tty%d open failed - failed to create %s", errstr);
return false;
}
void
fhandler_pty_master::fixup_after_fork (HANDLE parent)
{
DWORD wpid = GetCurrentProcessId ();
fhandler_tty_master *arch = (fhandler_tty_master *) archetype;
if (arch->dwProcessId != wpid)
{
tty& t = *get_ttyp ();
if (!DuplicateHandle (parent, arch->from_master, GetCurrentProcess (),
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
&arch->from_master, 0, false, DUPLICATE_SAME_ACCESS))
system_printf ("couldn't duplicate from_parent(%p), %E", arch->from_master);
if (!DuplicateHandle (parent, arch->to_master, GetCurrentProcess (),
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
&arch->to_master, 0, false, DUPLICATE_SAME_ACCESS))
system_printf ("couldn't duplicate to_parent(%p), %E", arch->from_master);
if (myself->pid == t.master_pid)
{
t.from_master = arch->from_master;
t.to_master = arch->to_master;
}
arch->dwProcessId = wpid;
}
from_master = arch->from_master;
to_master = arch->to_master;
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
report_tty_counts (this, "inherited master", "");
}
void
fhandler_pty_master::fixup_after_exec ()
{
if (!close_on_exec ())
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
fixup_after_fork (spawn_info->parent);
else
from_master = to_master = NULL;
* fhandler.cc (fhandler_base::fixup_after_exec): Declare here. * fhandler.h (fhandler_base::fixup_after_exec): Make non-inline. (fhandler_termios::fixup_after_fork): Delete declaration. (fhandler_termios::fixup_after_exec): Ditto. (fhandler_tty_common::inuse): Remove. (fhandler_tty_common::dup): Delete declaration. (fhandler_tty_common::fixup_after_fork): Ditto. (fhandler_tty_slave::fixup_after_exec): Declare new function. (fhandler_pty_master::dwProcessId): New variable. (fhandler_pty_master::from_master): Ditto. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::setup): New function. (fhandler_pty_master::fixup_after_fork): Ditto. (fhandler_pty_master::fixup_after_exec): Ditto. * fhandler_termios.cc (fhandler_termios::fixup_after_exec): Delete definition. (fhandler_termios::fixup_after_fork): Ditto. * fhandler_tty.cc (fhandler_tty_master::init): Use fhandler_pty_master setup function rather than obsolete tty::common_init. Delete obsolete inuse setting. (fhandler_tty_slave::fhandler_tty_slave): Set inuse to NULL here. (fhandler_tty_slave::open): Change debugging output for clarity. Check for different things when doing a sanity check on the tty. Reflect the fact that master_pid now is the cygwin pid rather than the windows pid. Use "arch" rather than "archetype" for consistency. (fhandler_tty_slave::close): Close inuse here. (fhandler_tty_slave::dup): Remove old if 0'ed code. (fhandler_pty_master::dup): New function. Handles pty master archetype. (fhandler_pty_master::fhandler_pty_master): Zero pty_master specific fields. (fhandler_pty_master::open): Implement using archetypes, similar to slave. Use fhandler_pty_master setup function rather than obsolete tty::common_init. Don't set inuse. (fhandler_tty_common::close): Don't deal with inuse. Delete old if 0'ed code. (fhandler_pty_master::close): Implement using archetypes. Close from_master and to_master. (fhandler_tty_common::set_close_on_exec): Just set close_on_exec flag here since everything uses archetypes now. (fhandler_tty_common::fixup_after_fork): Delete definition. (fhandler_tty_slave::fixup_after_exec): Define new function. (fhandler_pty_master::setup): New function, derived from tty::common_init. (fhandler_pty_master::fixup_after_fork): New function. (shared_info.h): Reset SHARED_INFO_CB to reflect new tty size. * tty.cc (tty_list::terminate): Close individual handles from tty_master. (tty::master_alive): Delete. (tty::make_pipes): Ditto. (tty::common_init): Ditto. * tty.h (tty::from_slave): Delete. (tty::to_slave): Ditto. (tty::common_init): Delete declaration. (tty::make_pipes): Ditto. (tty::master_pid): Define as pid_t since it is now a cygwin pid.
2006-06-02 23:41:34 +08:00
}