Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2011-10-16 02:37:30 +0400
committerChristopher Faylor <me@cgf.cx>2011-10-16 02:37:30 +0400
commit23771fa1f7028454def918e01f98a2edafe26b4e (patch)
tree60eeedc24e19b97efeb903a280ae8b6f01729212 /winsup/cygwin/dtable.cc
parenta9cc13a8e053756f127c1360b2981dcb4e458966 (diff)
* cygerrno.h (__set_errno): Modify debugging output to make searching strace
logs easier. Throughout, change /dev/tty* to /dev/pty*. Throughout, add flags argument to fhandler_*::dup methods. * devices.in: Rename (temporarily?) /dev/ttyN to /dev/ptyN. Add /dev/ptymN devices for pty masters. * devices.cc: Regenerate. * devices.h (MAX_CONSOLES): Set to max number supported by devices.in. (fh_devices::FH_PTMX): Rename from FH_PTYM. (device::operator int): Return by reference. * dtable.cc (fh_alloc): Take pc as an argument rather than just the device. This makes debugging easier since more information is available. Actually implement handling for already-allocated pty master devices. Make different decisions when generating fhandler for not-opened devices. Add kludge to deal with opening /dev/tty. (cnew_no_ctor): New macro. (build_fh_pc): Make debugging output more verbose. Use new clone() fhandler interface to duplicate archetypes. Reset last term opened. (dtable::dup_worker): Use Use new clone() fhandler interface to duplicate archetypes. Pass flags to child dup handler. (dtable::dup3): Set O_NOCTTY flag if newfd is not stdin/stdout/stderr. * fhandler.cc (fhandler_base::reset): Rename from operator =() and reduce functionality and sense of copy direction. (fhandler_base::open_with_arch): Use published interface to query io_handle(). Use new copyto() fhandler method to copy from/to found archetype. * fhandler.h: Throughout, delete size(), add copyout, clone, and fhandler_* (void *) methods. (fhandler_base::reset): Rename from operator =(). (fhandler_termios::is_dev_tty): Delete. (fhandler_termios): change "protected" region to "private". (fhandler_termios::is_dev_tty): Delete. (fhandler_termios): Rearrange protected/public. (fhandler_termios::fhandler_termios): Remember last fhandler_termios "opened". (fhandler_termios::~fhandler_termios): Forget last fhandler_termios opened. (ioctl): Rename from ioctl_termios. Take a void * argument. Reflect argument change in pinfo::set_ctty. (fhandler_console::dup): Declare new function. Set ctty here if appropriate. (fhandler_pty_master::from_master): Privatize. (fhandler_pty_master::to_master): Ditto. (fhandler_pty_master::dwProcessId): Ditto. (fhandler_pty_master::fhandler_pty_master): Add an `int' argument. (fhandler_pty_master::open_setup): Declare new function. (fhandler_pty_master::~fhandler_pty_master): Declare new method. (fhandler_nodevice): Remove commented out function declaration. * fhandler_console.cc: Use get_ttyp() instead of tc() throughout. (fhandler_console::dup): Define new function to set controlling ctty on dup, as appropriate. (fhandler_console::ioctl): Reflect ioctl_termios name change. (fhandler_console::setup): Rename from get_tty_stuff. (fhandler_console::open_setup): Reflect argument change in pinfo::set_ctty. (fhandler_console::fhandler_console): Set _tc here. * fhandler_termios.cc (handler_termios::ioctl): Rename. Take a void * arg like other ioctl functions. * fhandler_tty.cc (fhandler_pty_slave::dup): Call myself->set_ctty to potentially reset the controlling terminal. (fhandler_pty_slave::ioctl): Reflect name/arg change for ioctl_termios. (fhandler_pty_slave::fhandler_pty_slave): Take a "unit" argument. Call setup() here so that we will know the unit number of this fhandler as soon as possible. Set the unit as appropriate. (handler_pty_master::open): Move most stuff to constructor and open_setup. (handler_pty_slave::open_setup): Reflect argument change in pinfo::set_ctty. (handler_pty_master::open_setup): Define new function. (fhandler_pty_master::cleanup): Clear handles as a flag that the destructor does not have to do "close" operations. (fhandler_pty_master::close): Ditto. (fhandler_pty_master::~fhandler_pty_master): Define new method. (fhandler_pty_master::ioctl): Reflect name/arg change for ioctl_termios. (fhandler_pty_master::setup): Allocate tty here. Rely on handles being returned from allocated test rather than opening them here. Avoid setting _need_nl here since it is already zeroed in the constructor. Set up device information with DEV_TTYM_MAJOR. * path.h (path_conv &operator =): Take a const argument. (path_conv::dup): Ditto. (pathconv_arg::PC_OPEN): New enum. (pathconv_arg::PC_CTTY): Ditto. (path_types::PATH_CTTY): Ditto. (path_types::PATH_OPEN): Ditto. (path_conv::isopen): New method. (path_conv::isctty_capable): Ditto. * path.cc (path_conv::check): Set PATH_OPEN and PATH_CTTY as appropriate. * pipe.cc (fhandler_pipe::open): Use copyto to copy pipe handle. * syscall.cc (open): Reinstate fd > 2 check to disallow resetting ctty on non-std* handles. * tty.cc (tty_list::allocate): Pass out handles for allocated tty. use `not_allocated' to find unallocated ttys. Avoid keeping the lock since the allocation of the tty should be sufficient to prevent multiple access. (tty::not_allocated): Clarify comment. Rename. Return handles when an unused tty is found. Simply test for existing tty. (tty::exists): Rewrite to use `not_allocated'. * tty.h (NTTYS): Reset down to actual number supported by devices.in. (tty::not_allocated): Declare new function. (tty_list::allocate): Pass out read/write tty handles. Zero them when not found. * fhandler_proc.cc: Reflect name change from FH_PTYM -> FH_PTMX. * pinfo.h (pinfo::set_ctty): Reduce/reorder arguments passed in. * pinfo.cc (pinfo::set_ctty): Ditto. Just use tc() built into the passed-in fhandler_termios pointer. Return true if ctty is assigned. * syscalls.cc (open): Call build_fh_pc with PC_OPEN flag. Set PC_CTTY if appropriate. (stat_worker): Remove is_dev_tty () stuff.
Diffstat (limited to 'winsup/cygwin/dtable.cc')
-rw-r--r--winsup/cygwin/dtable.cc114
1 files changed, 81 insertions, 33 deletions
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index f1175e3ac..ff42b744d 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -113,7 +113,7 @@ dtable::get_debugger_info ()
extern bool jit_debug;
if (!jit_debug && being_debugged ())
{
- char std[3][sizeof ("/dev/ttyNNNN")];
+ char std[3][sizeof ("/dev/ptyNNNN")];
std[0][0] = std[1][0] = std [2][0] = '\0';
char buf[sizeof ("cYgstd %x") + 32];
sprintf (buf, "cYgstd %x %x %x", (unsigned) &std, sizeof (std[0]), 3);
@@ -401,6 +401,12 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
ptr ? new (ptr) name (__VA_ARGS__) : NULL; \
})
+#define cnew_no_ctor(name, ...) \
+ ({ \
+ void* ptr = (void*) ccalloc (HEAP_FHANDLER, 1, sizeof (name)); \
+ ptr ? new (ptr) name (ptr) : NULL; \
+ })
+
fhandler_base *
build_fh_name (const char *name, unsigned opt, suffix_info *si)
{
@@ -429,15 +435,20 @@ build_fh_dev (const device& dev, const char *unix_name)
}
#define fh_unset ((fhandler_base *) 1)
+
static fhandler_base *
-fh_alloc (device dev)
+fh_alloc (path_conv& pc)
{
fhandler_base *fh = fh_unset;
+ fhandler_base *fhraw = NULL;
- switch (dev.get_major ())
+ switch (pc.dev.get_major ())
{
case DEV_TTYS_MAJOR:
- fh = cnew (fhandler_pty_slave, dev.get_minor ());
+ fh = cnew (fhandler_pty_slave, pc.dev.get_minor ());
+ break;
+ case DEV_TTYM_MAJOR:
+ fh = cnew (fhandler_pty_master, pc.dev.get_minor ());
break;
case DEV_CYGDRIVE_MAJOR:
fh = cnew (fhandler_cygdrive);
@@ -461,18 +472,21 @@ fh_alloc (device dev)
fh = cnew (fhandler_serial);
break;
case DEV_CONS_MAJOR:
- fh = cnew (fhandler_console, dev);
+ fh = cnew (fhandler_console, pc.dev);
break;
default:
- switch ((int) dev)
+ switch ((int) pc.dev)
{
case FH_CONSOLE:
case FH_CONIN:
case FH_CONOUT:
- fh = cnew (fhandler_console, dev);
+ fh = cnew (fhandler_console, pc.dev);
break;
- case FH_PTYM:
- fh = cnew (fhandler_pty_master);
+ case FH_PTMX:
+ if (pc.isopen ())
+ fh = cnew (fhandler_pty_master, -1);
+ else
+ fhraw = cnew_no_ctor (fhandler_pty_master, -1);
break;
case FH_WINDOWS:
fh = cnew (fhandler_windows);
@@ -540,40 +554,52 @@ fh_alloc (device dev)
fh = cnew (fhandler_netdrive);
break;
case FH_TTY:
- {
- if (myself->ctty > 0)
- {
- if (iscons_dev (myself->ctty))
- fh = cnew (fhandler_console, dev);
- else
- fh = cnew (fhandler_pty_slave, myself->ctty);
- }
- ((fhandler_termios *) fh)->is_dev_tty (true);
- break;
- }
+ if (!pc.isopen ())
+ fhraw = cnew_no_ctor (fhandler_console, -1);
+ else if (myself->ctty <= 0
+ && !myself->set_ctty (fhandler_termios::last, 0))
+ /* no tty assigned */;
+ else if (iscons_dev (myself->ctty))
+ fh = cnew (fhandler_console, pc.dev);
+ else
+ fh = cnew (fhandler_pty_slave, myself->ctty);
+ break;
case FH_KMSG:
fh = cnew (fhandler_mailslot);
break;
}
}
+ /* If `fhraw' is set that means that this fhandler is just a dummy
+ set up for stat(). Mock it up for use by stat without actually
+ trying to do any real initialization. */
+ if (fhraw)
+ {
+ fh = fhraw;
+ fh->set_name (pc);
+ if (fh->use_archetype ())
+ fh->archetype = fh;
+ }
if (fh == fh_unset)
fh = cnew (fhandler_nodevice);
+ else if (fh->dev () == FH_ERROR)
+ {
+ delete fh;
+ fh = NULL;
+ }
return fh;
}
fhandler_base *
build_fh_pc (path_conv& pc, bool set_name)
{
- fhandler_base *fh = fh_alloc (pc.dev);
+ fhandler_base *fh = fh_alloc (pc);
if (!fh)
{
- set_errno (EMFILE);
+ set_errno (ENXIO);
goto out;
}
- else if (fh->dev () == FH_ERROR)
- goto out;
else if (fh->dev () != FH_NADA)
fh->set_name (fh->dev ().name);
else if (set_name)
@@ -582,18 +608,25 @@ build_fh_pc (path_conv& pc, bool set_name)
if (!fh->use_archetype ())
/* doesn't use archetypes */;
else if ((fh->archetype = cygheap->fdtab.find_archetype (fh->dev ())))
- debug_printf ("found an archetype for %s(%d/%d)", fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor ());
+ debug_printf ("found an archetype for %s(%d/%d) io_handle %p", fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor (),
+ fh->archetype->get_io_handle ());
else
{
- debug_printf ("creating an archetype for %s(%d/%d)", fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor ());
- fh->archetype = fh_alloc (fh->pc.dev);
- *fh->archetype = *fh;
+ fh->archetype = fh->clone ();
+ debug_printf ("created an archetype (%p) for %s(%d/%d)", fh->archetype, fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor ());
fh->archetype->archetype = NULL;
*cygheap->fdtab.add_archetype () = fh->archetype;
}
+ /* The fhandler_termios constructor keeps track of the last tty-like thing
+ opened but we're only interested in this if we don't have a controlling
+ terminal since we could potentially want to open it if /dev/tty is
+ referenced. */
+ if (myself->ctty > 0 || !fh->is_tty () || !pc.isctty_capable ())
+ fhandler_termios::last = NULL;
+
out:
- debug_printf ("fh %p", fh);
+ debug_printf ("fh %p, dev %p", fh, (DWORD) fh->dev ());
return fh;
}
@@ -603,16 +636,16 @@ dtable::dup_worker (fhandler_base *oldfh, int flags)
/* Don't call set_name in build_fh_pc. It will be called in
fhandler_base::operator= below. Calling it twice will result
in double allocation. */
- fhandler_base *newfh = build_fh_pc (oldfh->pc, false);
+ fhandler_base *newfh = oldfh->clone ();
if (!newfh)
debug_printf ("build_fh_pc failed");
else
{
- *newfh = *oldfh;
if (!oldfh->archetype)
newfh->set_io_handle (NULL);
+
newfh->pc.reset_conv_handle ();
- if (oldfh->dup (newfh))
+ if (oldfh->dup (newfh, flags))
{
delete newfh;
newfh = NULL;
@@ -625,6 +658,14 @@ dtable::dup_worker (fhandler_base *oldfh, int flags)
/* The O_CLOEXEC flag enforces close-on-exec behaviour. */
newfh->set_close_on_exec (!!(flags & O_CLOEXEC));
debug_printf ("duped '%s' old %p, new %p", oldfh->get_name (), oldfh->get_io_handle (), newfh->get_io_handle ());
+#ifdef DEBUGGING
+ debug_printf ("duped output_handles old %p, new %p",
+ oldfh->get_output_handle (),
+ newfh->get_output_handle ());
+ debug_printf ("duped output_handles archetype old %p, archetype new %p",
+ oldfh->archetype->get_output_handle (),
+ newfh->archetype->get_output_handle ());
+#endif /*DEBUGGING*/
}
}
return newfh;
@@ -659,6 +700,13 @@ dtable::dup3 (int oldfd, int newfd, int flags)
return -1;
}
+ /* This is a temporary kludge until all utilities can catch up with
+ a change in behavior that implements linux functionality: opening
+ a tty should not automatically cause it to become the controlling
+ tty for the process. */
+ if (newfd > 2)
+ flags |= O_NOCTTY;
+
if ((newfh = dup_worker (fds[oldfd], flags)) == NULL)
{
res = -1;
@@ -817,7 +865,7 @@ static void
decode_tty (char *buf, WCHAR *w32)
{
int ttyn = wcstol (w32, NULL, 10);
- __small_sprintf (buf, "/dev/tty%d", ttyn);
+ __small_sprintf (buf, "/dev/pty%d", ttyn);
}
/* Try to derive posix filename from given handle. Return true if