2000-02-17 20:38:33 +01:00
|
|
|
/* fhandler_termios.cc
|
|
|
|
|
2010-04-21 21:36:40 +02:00
|
|
|
Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009,
|
2011-04-18 13:26:37 +02:00
|
|
|
2010, 2011 Red Hat, Inc.
|
2000-02-17 20:38:33 +01: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-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.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 02:37:18 +02:00
|
|
|
#include "path.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-07 18:23:51 +02:00
|
|
|
#include "tty.h"
|
2005-06-30 04:52:14 +02:00
|
|
|
#include "cygtls.h"
|
2011-04-29 10:27:11 +02:00
|
|
|
#include "ntdll.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* Common functions shared by tty/console */
|
|
|
|
|
|
|
|
void
|
2011-06-04 02:12:29 +02:00
|
|
|
fhandler_termios::tcinit (bool is_pty_master)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
/* Initial termios values */
|
|
|
|
|
2011-06-04 02:12:29 +02:00
|
|
|
if (is_pty_master || !tc ()->initialized ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-06-04 02:12:29 +02: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;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-06-04 02:12:29 +02:00
|
|
|
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;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-06-04 02:12:29 +02:00
|
|
|
tc ()->ti.c_ispeed = tc ()->ti.c_ospeed = B38400;
|
|
|
|
tc ()->pgid = is_pty_master ? 0 : myself->pgid;
|
|
|
|
tc ()->initialized (true);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_termios::tcsetpgrp (const pid_t pgid)
|
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
termios_printf ("tty %d pgid %d, sid %d, tsid %d", tc ()->ntty, pgid,
|
|
|
|
myself->sid, tc ()->getsid ());
|
|
|
|
if (myself->sid != tc ()->getsid ())
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
set_errno (EPERM);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-06-30 04:52:14 +02:00
|
|
|
int res;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
res = bg_check (-SIGTTOU);
|
|
|
|
|
|
|
|
switch (res)
|
|
|
|
{
|
|
|
|
case bg_ok:
|
2011-06-04 02:12:29 +02:00
|
|
|
tc ()->setpgid (pgid);
|
|
|
|
init_console_handler (tc ()->gethwnd ());
|
2005-06-30 04:52:14 +02:00
|
|
|
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-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_termios::tcgetpgrp ()
|
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
if (myself->ctty != -1 && myself->ctty == tc ()->ntty)
|
|
|
|
return tc ()->pgid;
|
2009-10-07 09:52:30 +02:00
|
|
|
set_errno (ENOTTY);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_pty_master::tcgetpgrp ()
|
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
return tc ()->pgid;
|
2011-05-30 08:58:00 +02:00
|
|
|
}
|
|
|
|
|
2002-02-22 20:33:41 +01:00
|
|
|
void
|
|
|
|
tty_min::kill_pgrp (int sig)
|
|
|
|
{
|
|
|
|
int killself = 0;
|
2003-09-17 03:15:56 +02:00
|
|
|
winpids pids ((DWORD) PID_MAP_RW);
|
2006-02-06 19:24:11 +01:00
|
|
|
siginfo_t si = {0};
|
2004-01-19 06:46:54 +01:00
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_KERNEL;
|
2002-02-22 20:33:41 +01:00
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
|
|
|
{
|
|
|
|
_pinfo *p = pids[i];
|
2005-02-26 21:50:25 +01:00
|
|
|
if (!p->exists () || p->ctty != ntty || p->pgid != pgid)
|
2002-02-22 20:33:41 +01:00
|
|
|
continue;
|
|
|
|
if (p == myself)
|
|
|
|
killself++;
|
|
|
|
else
|
2005-07-06 22:05:03 +02:00
|
|
|
sig_send (p, si);
|
2002-02-22 20:33:41 +01:00
|
|
|
}
|
|
|
|
if (killself)
|
2004-01-19 06:46:54 +01:00
|
|
|
sig_send (myself, si);
|
2002-02-22 20:33:41 +01:00
|
|
|
}
|
2002-05-28 03:55:40 +02:00
|
|
|
|
2011-06-04 02:12:29 +02:00
|
|
|
int
|
|
|
|
tty_min::is_orphaned_process_group (int pgid)
|
|
|
|
{
|
|
|
|
/* An orphaned process group is a process group in which the parent
|
|
|
|
of every member is either itself a member of the group or is not
|
|
|
|
a member of the group's session. */
|
|
|
|
termios_printf ("checking pgid %d, my sid %d, my parent %d", pgid, myself->sid, myself->ppid);
|
|
|
|
winpids pids ((DWORD) 0);
|
|
|
|
for (unsigned i = 0; i < pids.npids; i++)
|
|
|
|
{
|
|
|
|
_pinfo *p = pids[i];
|
|
|
|
termios_printf ("checking pid %d - has pgid %d\n", p->pid, p->pgid);
|
|
|
|
if (!p || !p->exists () || p->pgid != pgid)
|
2011-06-06 07:02:13 +02:00
|
|
|
continue;
|
2011-06-04 02:12:29 +02:00
|
|
|
pinfo ppid (p->ppid);
|
|
|
|
if (!ppid)
|
|
|
|
continue;
|
|
|
|
termios_printf ("ppid->pgid %d, ppid->sid %d", ppid->pgid, ppid->sid);
|
|
|
|
if (ppid->pgid != pgid && ppid->sid == myself->sid)
|
2011-06-06 07:02:13 +02:00
|
|
|
return 0;
|
2011-06-04 02:12:29 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2001-01-17 15:57:09 +01:00
|
|
|
bg_check_types
|
2000-02-21 06:20:38 +01:00
|
|
|
fhandler_termios::bg_check (int sig)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
if (!myself->pgid || tc ()->getpgid () == myself->pgid ||
|
|
|
|
myself->ctty != tc ()->ntty ||
|
|
|
|
((sig == SIGTTOU) && !(tc ()->ti.c_lflag & TOSTOP)))
|
2001-01-17 15:57:09 +01:00
|
|
|
return bg_ok;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
if (sig < 0)
|
|
|
|
sig = -sig;
|
|
|
|
|
2011-06-04 02:12:29 +02:00
|
|
|
termios_printf ("bg I/O pgid %d, tpgid %d, %s, ntty %s", myself->pgid, tc ()->getpgid (),
|
|
|
|
myctty (), tc ()->ttyname ());
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-06-04 02:12:29 +02:00
|
|
|
if (tc ()->getsid () == 0)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
/* 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 15:57:09 +01:00
|
|
|
return bg_eof;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int sigs_ignored =
|
2003-11-28 23:13:57 +01:00
|
|
|
((void *) global_sigs[sig].sa_handler == (void *) SIG_IGN) ||
|
2008-02-15 18:53:11 +01:00
|
|
|
(_main_tls->sigmask & SIGTOMASK (sig));
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2011-05-30 08:58:00 +02:00
|
|
|
/* If the process is ignoring SIGTT*, then background IO is OK. If
|
|
|
|
the process is not ignoring SIGTT*, then the sig is to be sent to
|
|
|
|
all processes in the process group (unless the process group of the
|
|
|
|
process is orphaned, in which case we return EIO). */
|
|
|
|
if (sigs_ignored)
|
|
|
|
return bg_ok; /* Just allow the IO */
|
2011-06-04 02:12:29 +02:00
|
|
|
else if (tc ()->is_orphaned_process_group (myself->pgid))
|
2004-01-19 06:46:54 +01:00
|
|
|
{
|
2011-05-30 08:58:00 +02:00
|
|
|
termios_printf ("process group is orphaned");
|
|
|
|
set_errno (EIO); /* This is an IO error */
|
|
|
|
return bg_error;
|
2004-01-19 06:46:54 +01:00
|
|
|
}
|
2011-05-30 08:58:00 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Don't raise a SIGTT* signal if we have already been
|
|
|
|
interrupted by another signal. */
|
|
|
|
if (WaitForSingleObject (signal_arrived, 0) != WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
siginfo_t si = {0};
|
|
|
|
si.si_signo = sig;
|
|
|
|
si.si_code = SI_KERNEL;
|
|
|
|
kill_pgrp (myself->pgid, si);
|
|
|
|
}
|
|
|
|
return bg_signalled;
|
2011-06-06 07:02:13 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define set_input_done(x) input_done = input_done || (x)
|
|
|
|
|
2001-05-09 20:53:55 +02:00
|
|
|
inline void
|
|
|
|
fhandler_termios::echo_erase (int force)
|
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
if (force || tc ()->ti.c_lflag & ECHO)
|
2001-05-09 20:53:55 +02:00
|
|
|
doecho ("\b \b", 3);
|
|
|
|
}
|
|
|
|
|
2002-12-05 17:24:52 +01:00
|
|
|
line_edit_status
|
2002-12-27 04:50:29 +01:00
|
|
|
fhandler_termios::line_edit (const char *rptr, int nread, termios& ti)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-12-05 17:24:52 +01:00
|
|
|
line_edit_status ret = line_edit_ok;
|
2000-02-17 20:38:33 +01:00
|
|
|
char c;
|
|
|
|
int input_done = 0;
|
2002-12-21 05:38:12 +01:00
|
|
|
bool sawsig = false;
|
2002-12-27 04:50:29 +01:00
|
|
|
int iscanon = ti.c_lflag & ICANON;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
while (nread-- > 0)
|
|
|
|
{
|
|
|
|
c = *rptr++;
|
|
|
|
|
|
|
|
termios_printf ("char %c", c);
|
|
|
|
|
|
|
|
/* Check for special chars */
|
|
|
|
|
|
|
|
if (c == '\r')
|
|
|
|
{
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_iflag & IGNCR)
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_iflag & ICRNL)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
c = '\n';
|
|
|
|
set_input_done (iscanon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c == '\n')
|
|
|
|
{
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_iflag & INLCR)
|
2000-02-17 20:38:33 +01:00
|
|
|
c = '\r';
|
|
|
|
else
|
|
|
|
set_input_done (iscanon);
|
|
|
|
}
|
|
|
|
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_iflag & ISTRIP)
|
2000-02-17 20:38:33 +01:00
|
|
|
c &= 0x7f;
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_lflag & ISIG)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int sig;
|
2002-12-27 04:50:29 +01:00
|
|
|
if (CCEQ (ti.c_cc[VINTR], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
sig = SIGINT;
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VQUIT], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
sig = SIGQUIT;
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VSUSP], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
sig = SIGTSTP;
|
|
|
|
else
|
|
|
|
goto not_a_sig;
|
|
|
|
|
|
|
|
termios_printf ("got interrupt %d, sending signal %d", c, sig);
|
2001-03-18 19:05:01 +01:00
|
|
|
eat_readahead (-1);
|
2011-06-04 02:12:29 +02:00
|
|
|
tc ()->kill_pgrp (sig);
|
2002-12-27 04:50:29 +01:00
|
|
|
ti.c_lflag &= ~FLUSHO;
|
2002-12-21 05:38:12 +01:00
|
|
|
sawsig = true;
|
2000-02-17 20:38:33 +01:00
|
|
|
goto restart_output;
|
|
|
|
}
|
|
|
|
not_a_sig:
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_iflag & IXON)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-12-27 04:50:29 +01:00
|
|
|
if (CCEQ (ti.c_cc[VSTOP], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
if (!tc ()->output_stopped)
|
2000-09-07 03:18:37 +02:00
|
|
|
{
|
2011-06-04 02:12:29 +02:00
|
|
|
tc ()->output_stopped = 1;
|
2000-09-07 03:18:37 +02:00
|
|
|
acquire_output_mutex (INFINITE);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VSTART], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
restart_output:
|
2011-06-04 02:12:29 +02:00
|
|
|
tc ()->output_stopped = 0;
|
2000-09-07 03:18:37 +02:00
|
|
|
release_output_mutex ();
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-06-04 02:12:29 +02:00
|
|
|
else if ((ti.c_iflag & IXANY) && tc ()->output_stopped)
|
2000-02-17 20:38:33 +01:00
|
|
|
goto restart_output;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
if (iscanon && ti.c_lflag & IEXTEN && CCEQ (ti.c_cc[VDISCARD], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-12-27 04:50:29 +01:00
|
|
|
ti.c_lflag ^= FLUSHO;
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!iscanon)
|
|
|
|
/* nothing */;
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VERASE], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
if (eat_readahead (1))
|
2001-05-09 20:53:55 +02:00
|
|
|
echo_erase ();
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VWERASE], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
do
|
|
|
|
if (!eat_readahead (1))
|
|
|
|
break;
|
|
|
|
else
|
2001-05-09 20:53:55 +02:00
|
|
|
echo_erase ();
|
2000-02-17 20:38:33 +01:00
|
|
|
while ((ch = peek_readahead (1)) >= 0 && !isspace (ch));
|
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VKILL], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
int nchars = eat_readahead (-1);
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_lflag & ECHO)
|
2001-05-09 20:53:55 +02:00
|
|
|
while (nchars--)
|
|
|
|
echo_erase (1);
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VREPRINT], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_lflag & ECHO)
|
2001-05-09 20:53:55 +02:00
|
|
|
{
|
|
|
|
doecho ("\n\r", 2);
|
|
|
|
doecho (rabuf, ralen);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VEOF], c))
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
|
|
|
termios_printf ("EOF");
|
2005-07-06 22:05:03 +02:00
|
|
|
accept_input ();
|
2002-12-14 20:40:41 +01:00
|
|
|
ret = line_edit_input_done;
|
2000-02-17 20:38:33 +01:00
|
|
|
continue;
|
|
|
|
}
|
2002-12-27 04:50:29 +01:00
|
|
|
else if (CCEQ (ti.c_cc[VEOL], c) ||
|
|
|
|
CCEQ (ti.c_cc[VEOL2], c) ||
|
2000-02-17 20:38:33 +01:00
|
|
|
c == '\n')
|
|
|
|
{
|
|
|
|
set_input_done (1);
|
|
|
|
termios_printf ("EOL");
|
|
|
|
}
|
|
|
|
|
2002-12-27 04:50:29 +01:00
|
|
|
if (ti.c_iflag & IUCLC && isupper (c))
|
2000-10-19 05:12:44 +02:00
|
|
|
c = cyg_tolower (c);
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-12-05 17:24:52 +01:00
|
|
|
put_readahead (c);
|
2002-12-28 07:30:47 +01:00
|
|
|
if (ti.c_lflag & ECHO)
|
|
|
|
doecho (&c, 1);
|
2002-12-27 04:50:29 +01:00
|
|
|
if (!iscanon || input_done)
|
2002-12-14 20:40:41 +01:00
|
|
|
{
|
2002-12-20 02:38:55 +01:00
|
|
|
int status = accept_input ();
|
2003-01-17 06:33:52 +01:00
|
|
|
if (status != 1)
|
2002-12-17 04:49:34 +01:00
|
|
|
{
|
2002-12-20 02:38:55 +01:00
|
|
|
ret = status ? line_edit_error : line_edit_pipe_full;
|
2002-12-17 04:49:34 +01:00
|
|
|
eat_readahead (1);
|
|
|
|
break;
|
|
|
|
}
|
2002-12-14 20:40:41 +01:00
|
|
|
ret = line_edit_input_done;
|
|
|
|
input_done = 0;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2002-12-27 04:50:29 +01:00
|
|
|
if (!iscanon && ralen > 0)
|
2002-12-14 20:40:41 +01:00
|
|
|
ret = line_edit_input_done;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2001-03-05 07:28:25 +01:00
|
|
|
if (sawsig)
|
2002-12-05 17:24:52 +01:00
|
|
|
ret = line_edit_signalled;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-12-05 17:24:52 +01:00
|
|
|
return ret;
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2001-03-12 22:27:42 +01:00
|
|
|
|
2003-04-01 18:11:41 +02:00
|
|
|
_off64_t
|
|
|
|
fhandler_termios::lseek (_off64_t, int)
|
2002-03-19 05:39:01 +01:00
|
|
|
{
|
|
|
|
set_errno (ESPIPE);
|
2002-05-28 03:55:40 +02:00
|
|
|
return -1;
|
2002-03-19 05:39:01 +01:00
|
|
|
}
|
2011-04-17 21:56:25 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_termios::sigflush ()
|
|
|
|
{
|
2011-04-21 02:53:55 +02:00
|
|
|
/* FIXME: Checking get_ttyp() for NULL is not right since it should not
|
|
|
|
be NULL while this is alive. However, we can conceivably close a
|
|
|
|
ctty while exiting and that will zero this. */
|
|
|
|
if (get_ttyp () && !(get_ttyp ()->ti.c_lflag & NOFLSH))
|
2011-04-17 21:56:25 +02:00
|
|
|
tcflush (TCIFLUSH);
|
|
|
|
}
|