2000-02-18 03:38:33 +08:00
|
|
|
/* fhandler_termios.cc
|
|
|
|
|
* wininfo.h (wininfo::timer_active): Delete.
(wininfo::itv): Ditto.
(wininfo::start_time): Ditto.
(wininfo::window_started): Ditto.
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(wininfo::wininfo): Ditto.
(wininfo::lock): New method.
(wininfo::release): Ditto.
* window.cc: Use new lock/acquire wininfo methods throughout.
(wininfo::wininfo): Delete
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(getitimer): Ditto.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
(wininfo::lock): Define new function.
(wininfo::release): Ditto.
(wininfo::process): Delete WM_TIMER handling.
* timer.cc (struct timetracker): Delete it, flags. Add it_interval,
interval_us, sleepto_us, running, init_muto(), syncthread, and gettime().
(ttstart): Make NO_COPY.
(lock_timer_tracker): New class.
(timer_tracker::timer_tracker): Distinguish ttstart case.
(timer_tracker::~timer_tracker): New destructor. Clean out events, and reset
magic.
(timer_tracker::init_muto): New method.
(to_us): Round up as per POSIX.
(timer_thread): Reorganize to match timer_tracker::settime and
timer_tracker::gettime. Call sig_send without wait. Call auto_release.
(timer_tracker::settime): Reorganize logic to avoid race. Call gettime to
recover old value.
(timer_tracker::gettime): New method.
(timer_create): Properly set errno on invalid timerid. Use new
lock_timer_tracker method.
(timer_delete): Ditto. Simplify code slightly.
(timer_gettime): New function.
(fixup_timers_after_fork): Reinit ttstart.
(getitimer): New implementation.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
* cygwin.din: Export timer_gettime.
* winsup.h: Remove has has_visible_window_station declaration.
* Makefile.in (DLL_OFILES): Add lsearch.o.
* cygthread.h (cygthread::notify_detached): New element.
(cygthread::cygthread): Take optional fourth argument signifying event to
signal on thread completion.
* cygthread.cc (cygthread::stub): Signal notify_detached event, if it exists.
(cygthread::cygthread): Initialize notify_detached from fourth argument.
(cygthread::detach): Wait for notify_detached field is present.
* lsearch.cc: New file.
* search.h: Ditto.
* include/cygwin/version.h: Bump API minor number to 126.
* cygwin.din: Export lsearch, lfind.
2005-03-27 09:57:38 +08:00
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2002-03-05 16:15:28 +08:00
|
|
|
#include <sys/termios.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.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 "path.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
#include "tty.h"
|
2003-09-17 09:15:56 +08:00
|
|
|
#include "sys/cygwin.h"
|
2005-06-30 10:52:14 +08:00
|
|
|
#include "cygtls.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Common functions shared by tty/console */
|
|
|
|
|
|
|
|
void
|
2003-12-08 06:37:12 +08:00
|
|
|
fhandler_termios::tcinit (tty_min *this_tc, bool force)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Initial termios values */
|
|
|
|
|
|
|
|
tc = this_tc;
|
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
if (force || !tc->initialized ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
tc->ti.c_iflag = BRKINT | ICRNL | IXON;
|
|
|
|
tc->ti.c_oflag = OPOST | ONLCR;
|
|
|
|
tc->ti.c_cflag = B38400 | CS8 | CREAD;
|
|
|
|
tc->ti.c_lflag = ISIG | ICANON | ECHO | IEXTEN;
|
|
|
|
|
|
|
|
tc->ti.c_cc[VDISCARD] = CFLUSH;
|
|
|
|
tc->ti.c_cc[VEOL] = CEOL;
|
|
|
|
tc->ti.c_cc[VEOL2] = CEOL2;
|
|
|
|
tc->ti.c_cc[VEOF] = CEOF;
|
|
|
|
tc->ti.c_cc[VERASE] = CERASE;
|
|
|
|
tc->ti.c_cc[VINTR] = CINTR;
|
|
|
|
tc->ti.c_cc[VKILL] = CKILL;
|
|
|
|
tc->ti.c_cc[VLNEXT] = CLNEXT;
|
|
|
|
tc->ti.c_cc[VMIN] = 1;
|
|
|
|
tc->ti.c_cc[VQUIT] = CQUIT;
|
|
|
|
tc->ti.c_cc[VREPRINT] = CRPRNT;
|
|
|
|
tc->ti.c_cc[VSTART] = CSTART;
|
|
|
|
tc->ti.c_cc[VSTOP] = CSTOP;
|
|
|
|
tc->ti.c_cc[VSUSP] = CSUSP;
|
|
|
|
tc->ti.c_cc[VSWTC] = CSWTCH;
|
|
|
|
tc->ti.c_cc[VTIME] = 0;
|
|
|
|
tc->ti.c_cc[VWERASE] = CWERASE;
|
|
|
|
|
|
|
|
tc->ti.c_ispeed = tc->ti.c_ospeed = B38400;
|
|
|
|
tc->pgid = myself->pgid;
|
2004-04-13 17:04:22 +08:00
|
|
|
tc->initialized (true);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_termios::tcsetpgrp (const pid_t pgid)
|
|
|
|
{
|
2001-08-07 13:15:59 +08:00
|
|
|
termios_printf ("tty %d pgid %d, sid %d, tsid %d", tc->ntty, pgid,
|
2000-02-18 03:38:33 +08:00
|
|
|
myself->sid, tc->getsid ());
|
2004-10-11 23:36:13 +08:00
|
|
|
if (myself->sid != tc->getsid ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EPERM);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-06-30 10:52:14 +08:00
|
|
|
int res;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
res = bg_check (-SIGTTOU);
|
|
|
|
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case bg_ok:
|
|
|
|
tc->setpgid (pgid);
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
case bg_signalled:
|
|
|
|
if (_my_tls.call_signal_handler ())
|
|
|
|
continue;
|
|
|
|
set_errno (EINTR);
|
|
|
|
/* fall through intentionally */
|
|
|
|
default:
|
|
|
|
res = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_termios::tcgetpgrp ()
|
|
|
|
{
|
|
|
|
return tc->pgid;
|
|
|
|
}
|
|
|
|
|
2002-02-23 03:33:41 +08:00
|
|
|
void
|
|
|
|
tty_min::kill_pgrp (int sig)
|
|
|
|
{
|
|
|
|
int killself = 0;
|
2003-09-17 09:15:56 +08:00
|
|
|
winpids pids ((DWORD) PID_MAP_RW);
|
2006-02-07 02:24:11 +08:00
|
|
|
siginfo_t si = {0};
|
2004-01-19 13:46:54 +08:00
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_KERNEL;
|
2002-02-23 03:33:41 +08:00
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
|
|
|
{
|
|
|
|
_pinfo *p = pids[i];
|
2005-02-27 04:50:25 +08:00
|
|
|
if (!p->exists () || p->ctty != ntty || p->pgid != pgid)
|
2002-02-23 03:33:41 +08:00
|
|
|
continue;
|
|
|
|
if (p == myself)
|
|
|
|
killself++;
|
|
|
|
else
|
2005-07-07 04:05:03 +08:00
|
|
|
sig_send (p, si);
|
2002-02-23 03:33:41 +08:00
|
|
|
}
|
|
|
|
if (killself)
|
2004-01-19 13:46:54 +08:00
|
|
|
sig_send (myself, si);
|
2002-02-23 03:33:41 +08:00
|
|
|
}
|
2002-05-28 09:55:40 +08:00
|
|
|
|
2001-01-17 22:57:09 +08:00
|
|
|
bg_check_types
|
2000-02-21 13:20:38 +08:00
|
|
|
fhandler_termios::bg_check (int sig)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (!myself->pgid || tc->getpgid () == myself->pgid ||
|
|
|
|
myself->ctty != tc->ntty ||
|
|
|
|
((sig == SIGTTOU) && !(tc->ti.c_lflag & TOSTOP)))
|
2001-01-17 22:57:09 +08:00
|
|
|
return bg_ok;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (sig < 0)
|
|
|
|
sig = -sig;
|
|
|
|
|
2005-11-14 12:28:45 +08:00
|
|
|
termios_printf ("bg I/O pgid %d, tpgid %d, %s", myself->pgid, tc->getpgid (),
|
|
|
|
myctty ());
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (tc->getsid () == 0)
|
|
|
|
{
|
|
|
|
/* The pty has been closed by the master. Return an EOF
|
|
|
|
indication. FIXME: There is nothing to stop somebody
|
|
|
|
from reallocating this pty. I think this is the case
|
|
|
|
which is handled by unlockpt on a Unix system. */
|
|
|
|
termios_printf ("closed by master");
|
2001-01-17 22:57:09 +08:00
|
|
|
return bg_eof;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the process group is no more or if process is ignoring or blocks 'sig',
|
|
|
|
return with error */
|
2000-09-02 04:54:22 +08:00
|
|
|
int pgid_gone = !pid_exists (myself->pgid);
|
2000-02-18 03:38:33 +08:00
|
|
|
int sigs_ignored =
|
2003-11-29 06:13:57 +08:00
|
|
|
((void *) global_sigs[sig].sa_handler == (void *) SIG_IGN) ||
|
2000-02-18 03:38:33 +08:00
|
|
|
(myself->getsigmask () & SIGTOMASK (sig));
|
|
|
|
|
|
|
|
if (pgid_gone)
|
|
|
|
goto setEIO;
|
|
|
|
else if (!sigs_ignored)
|
|
|
|
/* nothing */;
|
|
|
|
else if (sig == SIGTTOU)
|
2001-01-17 22:57:09 +08:00
|
|
|
return bg_ok; /* Just allow the output */
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
goto setEIO; /* This is an output error */
|
|
|
|
|
2001-01-17 22:57:09 +08:00
|
|
|
/* Don't raise a SIGTT* signal if we have already been interrupted
|
|
|
|
by another signal. */
|
|
|
|
if (WaitForSingleObject (signal_arrived, 0) != WAIT_OBJECT_0)
|
2004-01-19 13:46:54 +08:00
|
|
|
{
|
2006-02-07 02:24:11 +08:00
|
|
|
siginfo_t si = {0};
|
2004-01-19 13:46:54 +08:00
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_KERNEL;
|
|
|
|
kill_pgrp (myself->pgid, si);
|
|
|
|
}
|
2001-01-17 22:57:09 +08:00
|
|
|
return bg_signalled;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
setEIO:
|
|
|
|
set_errno (EIO);
|
2001-01-17 22:57:09 +08:00
|
|
|
return bg_error;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define set_input_done(x) input_done = input_done || (x)
|
|
|
|
|
2001-05-10 02:53:55 +08:00
|
|
|
inline void
|
|
|
|
fhandler_termios::echo_erase (int force)
|
|
|
|
{
|
|
|
|
if (force || tc->ti.c_lflag & ECHO)
|
|
|
|
doecho ("\b \b", 3);
|
|
|
|
}
|
|
|
|
|
2002-12-06 00:24:52 +08:00
|
|
|
line_edit_status
|
2002-12-27 11:50:29 +08:00
|
|
|
fhandler_termios::line_edit (const char *rptr, int nread, termios& ti)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-12-06 00:24:52 +08:00
|
|
|
line_edit_status ret = line_edit_ok;
|
2000-02-18 03:38:33 +08:00
|
|
|
char c;
|
|
|
|
int input_done = 0;
|
2002-12-21 12:38:12 +08:00
|
|
|
bool sawsig = false;
|
2002-12-27 11:50:29 +08:00
|
|
|
int iscanon = ti.c_lflag & ICANON;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
while (nread-- > 0)
|
|
|
|
{
|
|
|
|
c = *rptr++;
|
|
|
|
|
|
|
|
termios_printf ("char %c", c);
|
|
|
|
|
|
|
|
/* Check for special chars */
|
|
|
|
|
|
|
|
if (c == '\r')
|
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_iflag & IGNCR)
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_iflag & ICRNL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
c = '\n';
|
|
|
|
set_input_done (iscanon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '\n')
|
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_iflag & INLCR)
|
2000-02-18 03:38:33 +08:00
|
|
|
c = '\r';
|
|
|
|
else
|
|
|
|
set_input_done (iscanon);
|
|
|
|
}
|
|
|
|
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_iflag & ISTRIP)
|
2000-02-18 03:38:33 +08:00
|
|
|
c &= 0x7f;
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_lflag & ISIG)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int sig;
|
2002-12-27 11:50:29 +08:00
|
|
|
if (CCEQ (ti.c_cc[VINTR], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
sig = SIGINT;
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VQUIT], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
sig = SIGQUIT;
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VSUSP], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
sig = SIGTSTP;
|
|
|
|
else
|
|
|
|
goto not_a_sig;
|
|
|
|
|
|
|
|
termios_printf ("got interrupt %d, sending signal %d", c, sig);
|
2001-03-19 02:05:01 +08:00
|
|
|
eat_readahead (-1);
|
2002-02-23 03:33:41 +08:00
|
|
|
tc->kill_pgrp (sig);
|
2002-12-27 11:50:29 +08:00
|
|
|
ti.c_lflag &= ~FLUSHO;
|
2002-12-21 12:38:12 +08:00
|
|
|
sawsig = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
goto restart_output;
|
|
|
|
}
|
|
|
|
not_a_sig:
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_iflag & IXON)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
if (CCEQ (ti.c_cc[VSTOP], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-29 07:48:28 +08:00
|
|
|
if (!tc->output_stopped)
|
2000-09-07 09:18:37 +08:00
|
|
|
{
|
2001-04-29 07:48:28 +08:00
|
|
|
tc->output_stopped = 1;
|
2000-09-07 09:18:37 +08:00
|
|
|
acquire_output_mutex (INFINITE);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VSTART], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
restart_output:
|
2001-04-29 07:48:28 +08:00
|
|
|
tc->output_stopped = 0;
|
2000-09-07 09:18:37 +08:00
|
|
|
release_output_mutex ();
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if ((ti.c_iflag & IXANY) && tc->output_stopped)
|
2000-02-18 03:38:33 +08:00
|
|
|
goto restart_output;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
if (iscanon && ti.c_lflag & IEXTEN && CCEQ (ti.c_cc[VDISCARD], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
ti.c_lflag ^= FLUSHO;
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!iscanon)
|
|
|
|
/* nothing */;
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VERASE], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (eat_readahead (1))
|
2001-05-10 02:53:55 +08:00
|
|
|
echo_erase ();
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VWERASE], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
do
|
|
|
|
if (!eat_readahead (1))
|
|
|
|
break;
|
|
|
|
else
|
2001-05-10 02:53:55 +08:00
|
|
|
echo_erase ();
|
2000-02-18 03:38:33 +08:00
|
|
|
while ((ch = peek_readahead (1)) >= 0 && !isspace (ch));
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VKILL], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int nchars = eat_readahead (-1);
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_lflag & ECHO)
|
2001-05-10 02:53:55 +08:00
|
|
|
while (nchars--)
|
|
|
|
echo_erase (1);
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VREPRINT], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_lflag & ECHO)
|
2001-05-10 02:53:55 +08:00
|
|
|
{
|
|
|
|
doecho ("\n\r", 2);
|
|
|
|
doecho (rabuf, ralen);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VEOF], c))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
termios_printf ("EOF");
|
2005-07-07 04:05:03 +08:00
|
|
|
accept_input ();
|
2002-12-15 03:40:41 +08:00
|
|
|
ret = line_edit_input_done;
|
2000-02-18 03:38:33 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 11:50:29 +08:00
|
|
|
else if (CCEQ (ti.c_cc[VEOL], c) ||
|
|
|
|
CCEQ (ti.c_cc[VEOL2], c) ||
|
2000-02-18 03:38:33 +08:00
|
|
|
c == '\n')
|
|
|
|
{
|
|
|
|
set_input_done (1);
|
|
|
|
termios_printf ("EOL");
|
|
|
|
}
|
|
|
|
|
2002-12-27 11:50:29 +08:00
|
|
|
if (ti.c_iflag & IUCLC && isupper (c))
|
2000-10-19 11:12:44 +08:00
|
|
|
c = cyg_tolower (c);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-12-06 00:24:52 +08:00
|
|
|
put_readahead (c);
|
2002-12-28 14:30:47 +08:00
|
|
|
if (ti.c_lflag & ECHO)
|
|
|
|
doecho (&c, 1);
|
2002-12-27 11:50:29 +08:00
|
|
|
if (!iscanon || input_done)
|
2002-12-15 03:40:41 +08:00
|
|
|
{
|
2002-12-20 09:38:55 +08:00
|
|
|
int status = accept_input ();
|
2003-01-17 13:33:52 +08:00
|
|
|
if (status != 1)
|
2002-12-17 11:49:34 +08:00
|
|
|
{
|
2002-12-20 09:38:55 +08:00
|
|
|
ret = status ? line_edit_error : line_edit_pipe_full;
|
2002-12-17 11:49:34 +08:00
|
|
|
eat_readahead (1);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-15 03:40:41 +08:00
|
|
|
ret = line_edit_input_done;
|
|
|
|
input_done = 0;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2002-12-27 11:50:29 +08:00
|
|
|
if (!iscanon && ralen > 0)
|
2002-12-15 03:40:41 +08:00
|
|
|
ret = line_edit_input_done;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-05 14:28:25 +08:00
|
|
|
if (sawsig)
|
2002-12-06 00:24:52 +08:00
|
|
|
ret = line_edit_signalled;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-12-06 00:24:52 +08:00
|
|
|
return ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-03-13 05:27:42 +08:00
|
|
|
|
2005-12-21 02:14:42 +08:00
|
|
|
void
|
|
|
|
fhandler_termios::fixup_after_exec ()
|
|
|
|
{
|
|
|
|
if (!close_on_exec ())
|
|
|
|
fixup_after_fork (NULL);
|
|
|
|
}
|
|
|
|
|
2001-03-13 05:27:42 +08:00
|
|
|
void
|
|
|
|
fhandler_termios::fixup_after_fork (HANDLE parent)
|
|
|
|
{
|
2003-02-04 11:01:17 +08:00
|
|
|
fhandler_base::fixup_after_fork (parent);
|
2001-03-13 05:27:42 +08:00
|
|
|
fork_fixup (parent, get_output_handle (), "output_handle");
|
|
|
|
}
|
2002-03-19 12:39:01 +08:00
|
|
|
|
2003-04-02 00:11:41 +08:00
|
|
|
_off64_t
|
|
|
|
fhandler_termios::lseek (_off64_t, int)
|
2002-03-19 12:39:01 +08:00
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
2002-05-28 09:55:40 +08:00
|
|
|
return -1;
|
2002-03-19 12:39:01 +08:00
|
|
|
}
|