* autoload.cc: Call _api_fatal in asm.

* child_info.h: Redefine CURR_CHILD_INFO_MAGIC.
(child_info_fork::abort): Rename from handle_failure.  Change arguments.
* cygtls.h (_local_storage::ttybuf): New field.
* dcrt0.cc (vapi_fatal): Split api_fatal.  Add "in forked process" to message
when appropriate.
(api_fatal): Use vapi_fatal.
* devices.h: Make multiple inclusion safe.
(fh_devices): Add FH_CONS* stuff.  Reorder slightly.
(device): Eliminate anonymous union.  Add more ways to access minor/major.
(device::setunit): Accommodate no-longer-anonymous union.
(device::is_fs): Ditto.
(device::is_fs_special): Ditto.
(device::major): New function.
(device::minor): Ditto.
(device::is_device): New function.
(device::not_device): Ditto.
(device::operator int): New operator.
(device::operator fh_devices): Ditto.
(device::operator bool): Ditto.
(device::operator DWORD): Ditto.
(device::operator =): Ditto.
(isproc_dev): New function.
(isprocsys_dev): Ditto.
(iscons_dev): Ditto.
(istty_slave_dev): Ditto.
* devices.in: Add new "/dev/cons*" strings.  Accommodate no-longer-anonymous
union throughout.
(BRACK): Use more precise method for initialization.
* devices.cc: Regenerate.
* dtable.cc (dtable::stdio_init): Use get_cttyp instead of get_tty.
(dtable::find_archetype): Use new DWORD operator in device to test archetypes.
(dtable::init_std_file_from_handle): Use different method to initialize 'dev'.
Adapt to different ctty handling and accommodate /dev/cons*.
(fh_alloc): Accommodate no-longer-anonymous union.  Adapt to new /dev/cons*.
(build_fh_pc): Make debugging output more useful.
* exceptions.cc (ctrl_c_handler): Use get_cttyp instead of get_tty.
* external.cc (fillout_pinfo): Accommodate new cons* stuff.
* fhandler.cc (fhandler_base::read): Eliminate is_slow() test.
* fhandler.h (fhandler_base::*): Adapt to changes in device.h.
(fhandler_*::is_slow): Delete.
( fhandler_proc::get_proc_fhandler): Return fh_devices type.
* fhandler_console.cc (open_shared_console): New function.
(console_unit): New class.
(console_unit::console_unit): New constructor.
(enum_windows): New function.  Declare as friend to console_unit.
(fhandler_console::set_unit): New function.
(fhandler_console::get_tty_stuff): Call set_unit to set the unit number and
determine if initialization is needed.  Eliminate flags parameter.
(tty_list::get_cttyp): Rename (sorta) from get_tty.  Return pointer to correct
tty_min.
(fhandler_console::open): Adapt to elimination of argument to get_tty_stuff.
(fhandler_console::output_tcsetattr): Properly detect error condition.
(fhandler_console::fixup_after_fork_exec): Adapt to get_tty_stuff() setting tc
automatically.
* fhandler_proc.cc: Use FH_BAD rather than 0 throughout where using fh_devices
enum.
(fhandler_proc::get_proc_fhandler): Return fh_devices.  Adapt to devices.h
changes.
* fhandler_process.cc: Adapt to devices.h changes.  Use FH_BAD rather than 0
throughout where using fh_devices enum.
* fhandler_procnet.cc: Ditto.
* fhandler_procsys.cc: Ditto.
* fhandler_procsysvipc.cc: Ditto.
* fhandler_tape.cc (fhandler_dev_tape::fhandler_dev_tape): Ditto.
* fhandler_termios.cc (handler_termios::bg_check): Use tc->ttyname() rather
than assuming that we can construct a tty.
* fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Just return
get_minor() of dev.
(fhandler_pty_master::process_slave_output): Add slightly more debugging info.
(fhandler_tty_slave::fhandler_tty_slave): Change name from ntty to unit.
(fhandler_pty_master::open): Ditto.
(fhandler_tty_slave::ioctl): Adapt to change which causes ctty to represent a
complete device.
(fhandler_tty_master::init_console): Add debugging for failure path.
(fhandler_pty_master::setup): Use get_unit() to retrieve unit number rather
than relying on raw ntty.
(fhandler_pty_master::setup): Ditto.
* fhandler_virtual.h (virt_tab_t): Redefine fhandler as fh_devices.
* fork.cc: Remove obsolete vfork stuff.
(frok::child): Don't assume that a ctty == 0 is valid.
* mount.cc (mount_info::conv_to_win32_path): Adapt to device struct changes.
(mount_info::conv_to_win32_path): Ditto.
* path.cc (path_conv::check): Retrive major/minor numbers via a method rather
than accessing them directly from device.  Rely on dev operators to
set/retrieve device information as required by device struct change.
* path.h (isproc_dev): Move to devices.h.
(isprocsys_dev): Ditto.
(isvirtual_dev): Ditto.
(path_conv:{isdevice,isfifo,isspecial,iscygdrive,issocket,get_devn,get_unitn}):
Use device methods to access/manipulate devices.
* pinfo.cc (pinfo::exit): Don't assume that ctty == 0 is valid.  Use iscons_dev
to determine if a device is a console.
(_pinfo::_ctty): Use device::parse to generate tty/cons name.
(_pinfo::set_ctty): Don't assume that ctty == 0 is valid.  Remove redundant
info from debugging.
* shared.cc (offsets): Remove console offset.
* shared_info.h (shared_locations): Ditto.
* syscalls.cc (umask): Use device methods to manipulate device information.
(ctermid): Use device::parse to generate term device name.
* tlsoffsets.h: Regenerate.
* tty.cc (ttyslot): Return minor number of ctty since ctty now represents a
full device.
(tty::create_master): Set ctty to a complete device.
(tty_list::attach): Rework to detect new /dev/cons* stuff.
(tty_list::terminate): Adapt to changes to ctty.
(tty_list::init): Adapt to change to setntty - pass in device major number.
(tty::exists): Use get_unit() to retrive tty unit number.
(tty::open_mutex): Ditto.
(tty::open_inuse): Ditto.
(tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty_min::ttyname): Define new function.
* tty.h (tty_min::ntty): Redefine as fh_devices.
(tty::exists): Use get_unit() to retrive tty unit number.
(tty::open_mutex): Ditto.
(tty::open_inuse): Ditto.
(tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty_min::ttyname): Declare new function.
(tty::getntty): Declare as const.
(tty_list::operator []): Assure that only minor part of argument is used.
* dll_init.cc (dll_list::alloc): Detect mismatch of data segments early issuing
an explicit error message if necessary.
* heap.cc (heap_init): Adapt to changes from fork->handle_failure to
fork->abort.
* pinfo.h (EXITCODE_FORK_FAILED): New enum.  (from Ryan Johnson)
* sigproc.cc (child_info_fork::abort): Rename from handle_failure.  Change
arguments to allow passing in a printf-like message.
* winsup.h (api_fatal): Delete macro definition.
(api_fatal): Redefine from __api_fatal.
(vapi_fatal): Declare new function.
* include/sys/strace.h (strace_vprintf): Define new macro.
* ntdll.h (_SYSTEM_INFORMATION_CLASS): Add SystemHandleInformation.
This commit is contained in:
Christopher Faylor 2011-05-28 18:17:09 +00:00
parent 747a0a5205
commit 44d2fc0a45
41 changed files with 4425 additions and 2924 deletions

View File

@ -1,3 +1,153 @@
2011-05-28 Christopher Faylor <me.cygwin2011@cgf.cx>
* autoload.cc: Call _api_fatal in asm.
* child_info.h: Redefine CURR_CHILD_INFO_MAGIC.
(child_info_fork::abort): Rename from handle_failure. Change
arguments.
* cygtls.h (_local_storage::ttybuf): New field.
* dcrt0.cc (vapi_fatal): Split api_fatal. Add "in forked process" to
message when appropriate.
(api_fatal): Use vapi_fatal.
* devices.h: Make multiple inclusion safe.
(fh_devices): Add FH_CONS* stuff. Reorder slightly.
(device): Eliminate anonymous union. Add more ways to access
minor/major.
(device::setunit): Accommodate no-longer-anonymous union.
(device::is_fs): Ditto.
(device::is_fs_special): Ditto.
(device::major): New function.
(device::minor): Ditto.
(device::is_device): New function.
(device::not_device): Ditto.
(device::operator int): New operator.
(device::operator fh_devices): Ditto.
(device::operator bool): Ditto.
(device::operator DWORD): Ditto.
(device::operator =): Ditto.
(isproc_dev): New function.
(isprocsys_dev): Ditto.
(iscons_dev): Ditto.
(istty_slave_dev): Ditto.
* devices.in: Add new "/dev/cons*" strings. Accommodate
no-longer-anonymous union throughout.
(BRACK): Use more precise method for initialization.
* devices.cc: Regenerate.
* dtable.cc (dtable::stdio_init): Use get_cttyp instead of get_tty.
(dtable::find_archetype): Use new DWORD operator in device to test
archetypes.
(dtable::init_std_file_from_handle): Use different method to initialize
'dev'. Adapt to different ctty handling and accommodate /dev/cons*.
(fh_alloc): Accommodate no-longer-anonymous union. Adapt to new
/dev/cons*.
(build_fh_pc): Make debugging output more useful.
* exceptions.cc (ctrl_c_handler): Use get_cttyp instead of get_tty.
* external.cc (fillout_pinfo): Accommodate new cons* stuff.
* fhandler.cc (fhandler_base::read): Eliminate is_slow() test.
* fhandler.h (fhandler_base::*): Adapt to changes in device.h.
(fhandler_*::is_slow): Delete.
( fhandler_proc::get_proc_fhandler): Return fh_devices type.
* fhandler_console.cc (open_shared_console): New function.
(console_unit): New class.
(console_unit::console_unit): New constructor.
(enum_windows): New function. Declare as friend to console_unit.
(fhandler_console::set_unit): New function.
(fhandler_console::get_tty_stuff): Call set_unit to set the unit number
and determine if initialization is needed. Eliminate flags parameter.
(tty_list::get_cttyp): Rename (sorta) from get_tty. Return pointer to
correct tty_min.
(fhandler_console::open): Adapt to elimination of argument to
get_tty_stuff.
(fhandler_console::output_tcsetattr): Properly detect error condition.
(fhandler_console::fixup_after_fork_exec): Adapt to get_tty_stuff()
setting tc automatically.
* fhandler_proc.cc: Use FH_BAD rather than 0 throughout where using
fh_devices enum.
(fhandler_proc::get_proc_fhandler): Return fh_devices. Adapt to
devices.h changes.
* fhandler_process.cc: Adapt to devices.h changes. Use FH_BAD rather
than 0 throughout where using fh_devices enum.
* fhandler_procnet.cc: Ditto.
* fhandler_procsys.cc: Ditto.
* fhandler_procsysvipc.cc: Ditto.
* fhandler_tape.cc (fhandler_dev_tape::fhandler_dev_tape): Ditto.
* fhandler_termios.cc (handler_termios::bg_check): Use tc->ttyname()
rather than assuming that we can construct a tty.
* fhandler_tty.cc (fhandler_tty_master::fhandler_tty_master): Just
return get_minor() of dev.
(fhandler_pty_master::process_slave_output): Add slightly more
debugging info.
(fhandler_tty_slave::fhandler_tty_slave): Change name from ntty to
unit.
(fhandler_pty_master::open): Ditto.
(fhandler_tty_slave::ioctl): Adapt to change which causes ctty to
represent a complete device.
(fhandler_tty_master::init_console): Add debugging for failure path.
(fhandler_pty_master::setup): Use get_unit() to retrieve unit number
rather than relying on raw ntty.
(fhandler_pty_master::setup): Ditto.
* fhandler_virtual.h (virt_tab_t): Redefine fhandler as fh_devices.
* fork.cc: Remove obsolete vfork stuff.
(frok::child): Don't assume that a ctty == 0 is valid.
* mount.cc (mount_info::conv_to_win32_path): Adapt to device struct
changes.
(mount_info::conv_to_win32_path): Ditto.
* path.cc (path_conv::check): Retrive major/minor numbers via a method
rather than accessing them directly from device. Rely on dev operators
to set/retrieve device information as required by device struct change.
* path.h (isproc_dev): Move to devices.h.
(isprocsys_dev): Ditto.
(isvirtual_dev): Ditto.
(path_conv:{isdevice,isfifo,isspecial,iscygdrive,issocket,get_devn,get_unitn}):
Use device methods to access/manipulate devices.
* pinfo.cc (pinfo::exit): Don't assume that ctty == 0 is valid. Use
iscons_dev to determine if a device is a console.
(_pinfo::_ctty): Use device::parse to generate tty/cons name.
(_pinfo::set_ctty): Don't assume that ctty == 0 is valid. Remove
redundant info from debugging.
* shared.cc (offsets): Remove console offset.
* shared_info.h (shared_locations): Ditto.
* syscalls.cc (umask): Use device methods to manipulate device
information.
(ctermid): Use device::parse to generate term device name.
* tlsoffsets.h: Regenerate.
* tty.cc (ttyslot): Return minor number of ctty since ctty now
represents a full device.
(tty::create_master): Set ctty to a complete device.
(tty_list::attach): Rework to detect new /dev/cons* stuff.
(tty_list::terminate): Adapt to changes to ctty.
(tty_list::init): Adapt to change to setntty - pass in device major
number.
(tty::exists): Use get_unit() to retrive tty unit number.
(tty::open_mutex): Ditto.
(tty::open_inuse): Ditto.
(tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty_min::ttyname): Define new function.
* tty.h (tty_min::ntty): Redefine as fh_devices.
(tty::exists): Use get_unit() to retrive tty unit number.
(tty::open_mutex): Ditto.
(tty::open_inuse): Ditto.
(tty::create_inuse): Ditto.
(tty::get_event): Ditto.
(tty_min::ttyname): Declare new function.
(tty::getntty): Declare as const.
(tty_list::operator []): Assure that only minor part of argument is
used.
* dll_init.cc (dll_list::alloc): Detect mismatch of data segments early
issuing an explicit error message if necessary.
* heap.cc (heap_init): Adapt to changes from fork->handle_failure to
fork->abort.
* pinfo.h (EXITCODE_FORK_FAILED): New enum. (from Ryan Johnson)
* sigproc.cc (child_info_fork::abort): Rename from handle_failure.
Change arguments to allow passing in a printf-like message.
* winsup.h (api_fatal): Delete macro definition.
(api_fatal): Redefine from __api_fatal.
(vapi_fatal): Declare new function.
* include/sys/strace.h (strace_vprintf): Define new macro.
* ntdll.h (_SYSTEM_INFORMATION_CLASS): Add SystemHandleInformation.
2011-05-27 Corinna Vinschen <corinna@vinschen.de>
* shared.cc (offsets): Reorder so that console_state is lowest in

View File

@ -150,7 +150,7 @@ noload: \n\
leal 8(%edx),%eax # Location of name of function \n\
pushl %eax \n\
pushl $msg1 # The message \n\
call ___api_fatal # Print message. Never returns \n\
call _api_fatal # Print message. Never returns \n\
\n\
.globl dll_func_load \n\
dll_func_load: \n\
@ -430,6 +430,7 @@ LoadDLLfunc (CreateWindowStationW, 16, user32)
LoadDLLfunc (DefWindowProcW, 16, user32)
LoadDLLfunc (DispatchMessageW, 4, user32)
LoadDLLfunc (EmptyClipboard, 0, user32)
LoadDLLfunc (EnumWindows, 8, user32)
LoadDLLfunc (GetClipboardData, 4, user32)
LoadDLLfunc (GetForegroundWindow, 0, user32)
LoadDLLfunc (GetKeyboardLayout, 4, user32)

View File

@ -1,6 +1,7 @@
/* child_info.h: shared child info for cygwin
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008 Red Hat, Inc.
Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009, 2011
Red Hat, Inc.
This file is part of Cygwin.
@ -37,7 +38,7 @@ enum child_status
#define EXEC_MAGIC_SIZE sizeof(child_info)
/* Change this value if you get a message indicating that it is out-of-sync. */
#define CURR_CHILD_INFO_MAGIC 0xbdf5842aU
#define CURR_CHILD_INFO_MAGIC 0x76ca2aaeU
/* NOTE: Do not make gratuitous changes to the names or organization of the
below class. The layout is checksummed to determine compatibility between
@ -89,7 +90,7 @@ public:
char filler[4];
child_info_fork ();
void handle_fork () __attribute__ ((regparm (1)));;
bool handle_failure (DWORD) __attribute__ ((regparm (2)));
bool abort (const char *fmt = NULL, ...);
void alloc_stack ();
void alloc_stack_hard_way (volatile char *);
};

View File

@ -133,6 +133,7 @@ struct _local_storage
/* All functions requiring temporary path buffers. */
tls_pathbuf pathbufs;
char ttybuf[32];
};
typedef struct struct_waitq

View File

@ -1109,13 +1109,10 @@ _exit (int n)
extern "C" void cygwin_stackdump ();
extern "C" void
__api_fatal (const char *fmt, ...)
vapi_fatal (const char *fmt, va_list ap)
{
char buf[4096];
va_list ap;
va_start (ap, fmt);
int n = __small_sprintf (buf, "%P: *** fatal error - ");
int n = __small_sprintf (buf, "%P: *** fatal error %s- ", in_forkee ? "in forked process " : "");
__small_vsprintf (buf + n, fmt, ap);
va_end (ap);
strace.prntf (_STRACE_SYSTEM, NULL, "%s", buf);
@ -1127,6 +1124,15 @@ __api_fatal (const char *fmt, ...)
myself.exit (__api_fatal_exit_val);
}
extern "C" void
api_fatal (const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vapi_fatal (fmt, ap);
}
void
multiple_cygwin_problem (const char *what, unsigned magic_version, unsigned version)
{

File diff suppressed because it is too large Load Diff

View File

@ -8,6 +8,9 @@ This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
#ifndef _DEVICES_H
#define _DEVICES_H
typedef unsigned short _major_t;
typedef unsigned short _minor_t;
typedef mode_t _mode_t;
@ -17,6 +20,7 @@ typedef __dev32_t _dev_t;
#define _minor(dev) ((dev) & ((1 << (sizeof (_minor_t) * 8)) - 1))
#define _major(dev) ((dev) >> (sizeof (_major_t) * 8))
#define MAX_CONSOLES 31
enum fh_devices
{
FH_TTY = FHDEV (5, 0),
@ -25,6 +29,10 @@ enum fh_devices
FH_CONIN = FHDEV (5, 255),
FH_CONOUT = FHDEV (5, 254),
DEV_CONS_MAJOR = 3,
FH_CONS = FHDEV (DEV_CONS_MAJOR, 0),
FH_CONS_MAX = FHDEV (DEV_CONS_MAJOR, MAX_CONSOLES),
DEV_TTYM_MAJOR = 128,
FH_TTYM = FHDEV (DEV_TTYM_MAJOR, 0),
FH_TTYM_MAX= FHDEV (DEV_TTYM_MAJOR, 255),
@ -40,17 +48,17 @@ enum fh_devices
FH_CLIPBOARD=FHDEV (13, 254),
/* begin /proc directories */
FH_PROC_MAX_MINOR = FHDEV (0, 255),
FH_PROC = FHDEV (0, 255),
FH_PROCESS = FHDEV (0, 254),
FH_REGISTRY= FHDEV (0, 253),
FH_PROCNET = FHDEV (0, 252),
FH_PROCESSFD = FHDEV (0, 251),
FH_PROCSYS = FHDEV (0, 250),
FH_PROCSYSVIPC = FHDEV (0, 249),
FH_PROC_MIN_MINOR = FHDEV (0, 200),
FH_PROCSYSVIPC = FHDEV (0, 249),
FH_PROCSYS = FHDEV (0, 250),
FH_PROCESSFD = FHDEV (0, 251),
FH_PROCNET = FHDEV (0, 252),
FH_REGISTRY= FHDEV (0, 253),
FH_PROCESS = FHDEV (0, 254),
FH_PROC = FHDEV (0, 255),
FH_PROC_MAX_MINOR = FHDEV (0, 255),
/* end /proc directories */
FH_PIPE = FHDEV (0, 199),
@ -245,15 +253,18 @@ enum fh_devices
struct device
{
const char *name;
union
union __cygwin_dev
{
_dev_t devn;
DWORD devn_dword;
int devn_int;
fh_devices devn_fh_devices;
struct
{
_minor_t minor;
_major_t major;
};
};
} d;
const char *native;
_mode_t mode;
bool dev_on_fs;
@ -264,14 +275,40 @@ struct device
void parsedisk (int, int);
inline bool setunit (unsigned n)
{
minor = n;
d.minor = n;
return true;
}
static void init ();
inline operator int () const {return devn;}
static _major_t major (_dev_t n)
{
__cygwin_dev d;
d.devn = n;
return d.major;
}
static _minor_t minor (_dev_t n)
{
__cygwin_dev d;
d.devn = n;
return d.minor;
}
static _major_t major (int n) {return major ((_dev_t) n);}
static _minor_t minor (int n) {return minor ((_dev_t) n);}
bool is_device (_dev_t n) const {return n == d.devn; }
bool not_device (_dev_t n) const {return d.devn && n != d.devn; }
_minor_t get_minor () const {return d.minor;}
_minor_t get_major () const {return d.major;}
inline operator int () {return d.devn_int;}
inline operator fh_devices () {return d.devn_fh_devices;}
inline operator bool () {return !!d.devn_int;}
inline operator DWORD& () {return d.devn_dword;}
fh_devices operator = (fh_devices n) {return d.devn_fh_devices = n;}
inline void setfs (bool x) {dev_on_fs = x;}
inline bool isfs () const {return dev_on_fs || devn == FH_FS;}
inline bool is_fs_special () const {return dev_on_fs && devn != FH_FS;}
inline bool isfs () const {return dev_on_fs || d.devn == FH_FS;}
inline bool is_fs_special () const {return dev_on_fs && d.devn != FH_FS;}
};
extern const device *console_dev;
@ -302,3 +339,16 @@ extern const device dev_fh_storage;
#define fh_dev (&dev_fh_storage)
extern const device dev_fs_storage;
#define fs_dev (&dev_fs_storage)
#define isproc_dev(devn) \
(devn >= FH_PROC_MIN_MINOR && devn <= FH_PROC_MAX_MINOR)
#define isprocsys_dev(devn) (devn == FH_PROCSYS)
#define isvirtual_dev(devn) \
(isproc_dev (devn) || devn == FH_CYGDRIVE || devn == FH_NETDRIVE)
#define iscons_dev(n) (device::major (n) == DEV_CONS_MAJOR)
#define istty_slave_dev(n) (device::major (n) == DEV_TTYS_MAJOR)
#endif /*_DEVICES_H*/

View File

@ -57,13 +57,14 @@ const device dev_dgram_storage =
const device dev_bad_storage =
{"", {FH_BAD}, ""};
#define BRACK(x) {x}
#define BRACK(x) {devn_int: x}
%storage_here
}
%%
"/dev/tty", BRACK(FH_TTY), "/dev/tty"
"/dev/tty%(0-63)d", BRACK(FHDEV(DEV_TTYS_MAJOR, {$1})), "/dev/tty{$1}", ttys_dev
"/dev/cons%(0-63)d", BRACK(FHDEV(DEV_CONS_MAJOR, {$1})), "/dev/cons{$1}", cons_dev
"/dev/console", BRACK(FH_CONSOLE), "/dev/console", console_dev
"/dev/ttym", BRACK(FH_TTYM), "/dev/ttym", ttym_dev
"/dev/ptmx", BRACK(FH_PTYM), "/dev/ptmx"
@ -127,17 +128,17 @@ device::parse (_major_t major, _minor_t minor)
{
_dev_t dev = FHDEV (major, minor);
devn = 0;
d.devn = 0;
for (unsigned i = 0; i < (sizeof (dev_storage) / sizeof (dev_storage[0])); i++)
if (dev_storage[i].devn == dev)
if (dev_storage[i].d.devn == dev)
{
*this = dev_storage[i];
break;
}
if (!*this)
devn = FHDEV (major, minor);
d.devn = FHDEV (major, minor);
}
void

View File

@ -19,6 +19,7 @@ details. */
#include "dtable.h"
#include "cygheap.h"
#include "pinfo.h"
#include "child_info.h"
#include "cygtls.h"
#include "exception.h"
#include <wchar.h>
@ -131,6 +132,21 @@ dll_list::alloc (HINSTANCE h, per_process *p, dll_type type)
{
if (!in_forkee)
d->count++; /* Yes. Bump the usage count. */
else
{
if (d->p.data_start != p->data_start)
fork_info->abort ("data segment start: parent(%p) != child(%p)",
d->p.data_start, p->data_start);
else if (d->p.data_end != p->data_end)
fork_info->abort ("data segment end: parent(%p) != child(%p)",
d->p.data_end, p->data_end);
else if (d->p.bss_start != p->bss_start)
fork_info->abort ("data segment start: parent(%p) != child(%p)",
d->p.bss_start, p->bss_start);
else if (d->p.bss_end != p->bss_end)
fork_info->abort ("bss segment end: parent(%p) != child(%p)",
d->p.bss_end, p->bss_end);
}
d->p = p;
}
else

View File

@ -153,7 +153,7 @@ dtable::stdio_init ()
if (myself->cygstarted || ISSTATE (myself, PID_CYGPARENT))
{
tty_min *t = cygwin_shared->tty.get_tty (myself->ctty);
tty_min *t = cygwin_shared->tty.get_cttyp ();
if (t && t->getpgid () == myself->pid && t->gethwnd ())
init_console_handler (true);
return;
@ -196,7 +196,7 @@ fhandler_base *
dtable::find_archetype (device& dev)
{
for (unsigned i = 0; i < farchetype; i++)
if (archetypes[i]->get_device () == (unsigned) dev)
if (archetypes[i]->get_device () == (DWORD) dev)
return archetypes[i];
return NULL;
}
@ -268,9 +268,8 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
CONSOLE_SCREEN_BUFFER_INFO buf;
DCB dcb;
unsigned bin = O_BINARY;
device dev;
device dev = {};
dev.devn = 0; /* FIXME: device */
first_fd_for_open = 0;
if (!not_open (fd))
@ -311,9 +310,9 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
{
/* Console I/O */
if (!ISSTATE (myself, PID_USETTY))
dev = *console_dev;
else if (myself->ctty >= 0)
dev.parse (DEV_TTYS_MAJOR, myself->ctty);
dev.parse (FH_CONSOLE);
else if (myself->ctty > 0)
dev.parse (myself->ctty);
else
dev.parse (FH_TTY);
}
@ -352,7 +351,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle)
/* Console windows are not kernel objects, so the access mask returned
by NtQueryInformationFile is meaningless. CMD always hands down
stdin handles as R/O handles, but our tty slave sides are R/W. */
if (dev == FH_TTY || dev == FH_CONSOLE || dev.major == DEV_TTYS_MAJOR)
if (dev == FH_TTY || dev == FH_CONSOLE || dev.get_major () == DEV_TTYS_MAJOR)
access |= GENERIC_READ | GENERIC_WRITE;
else if (NT_SUCCESS (NtQueryInformationFile (handle, &io, &fai,
sizeof fai,
@ -431,10 +430,10 @@ fh_alloc (device dev)
{
fhandler_base *fh = fh_unset;
switch (dev.major)
switch (dev.get_major ())
{
case DEV_TTYS_MAJOR:
fh = cnew (fhandler_tty_slave) (dev.minor);
fh = cnew (fhandler_tty_slave) (dev.get_minor ());
break;
case DEV_TTYM_MAJOR:
fh = cnew (fhandler_tty_master) ();
@ -460,8 +459,11 @@ fh_alloc (device dev)
case DEV_SERIAL_MAJOR:
fh = cnew (fhandler_serial) ();
break;
case DEV_CONS_MAJOR:
fh = cnew (fhandler_console) ();
break;
default:
switch (dev)
switch ((int) dev)
{
case FH_CONSOLE:
case FH_CONIN:
@ -538,7 +540,7 @@ fh_alloc (device dev)
break;
case FH_TTY:
{
if (myself->ctty == TTY_CONSOLE)
if (iscons_dev (myself->ctty))
fh = cnew (fhandler_console) ();
else
fh = cnew (fhandler_tty_slave) (myself->ctty);
@ -570,10 +572,10 @@ 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 ().major, fh->dev ().minor);
debug_printf ("found an archetype for %s(%d/%d)", fh->get_name (), fh->dev ().get_major (), fh->dev ().get_minor ());
else
{
debug_printf ("creating an archetype for %s(%d/%d)", fh->get_name (), fh->dev ().major, fh->dev ().minor);
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->archetype = NULL;

View File

@ -996,7 +996,7 @@ ctrl_c_handler (DWORD type)
if (!pinfo (cygwin_pid (GetCurrentProcessId ())))
return TRUE;
tty_min *t = cygwin_shared->tty.get_tty (myself->ctty);
tty_min *t = cygwin_shared->tty.get_cttyp ();
/* Ignore this if we're not the process group leader since it should be handled
*by* the process group leader. */
if (myself->ctty != -1 && t->getpgid () == myself->pid &&

View File

@ -76,7 +76,7 @@ fillout_pinfo (pid_t pid, int winpid)
}
else if (nextpid || p->pid == pid || (winpid && thispid == (DWORD) pid))
{
ep.ctty = p->ctty;
ep.ctty = iscons_dev (p->ctty) ? p->ctty : device::minor (p->ctty);
ep.pid = p->pid;
ep.ppid = p->ppid;
ep.dwProcessId = p->dwProcessId;

View File

@ -693,7 +693,7 @@ fhandler_base::read (void *in_ptr, size_t& len)
char *ptr = (char *) in_ptr;
ssize_t copied_chars = get_readahead_into_buffer (ptr, len);
if (copied_chars && is_slow ())
if (copied_chars)
{
len = (size_t) copied_chars;
goto out;
@ -1814,7 +1814,7 @@ fhandler_base_overlapped::wait_overlapped (bool inres, bool writing, DWORD *byte
res = overlapped_error;
else
{
io_pending = err == ERROR_IO_PENDING;
io_pending = !inres && err == ERROR_IO_PENDING;
if (writing && !inres)
*bytes = len;
res = overlapped_success;

View File

@ -200,10 +200,10 @@ class fhandler_base
/* Non-virtual simple accessor functions. */
void set_io_handle (HANDLE x) { io_handle = x; }
DWORD& get_device () { return dev ().devn; }
DWORD get_major () { return dev ().major; }
DWORD get_minor () { return dev ().minor; }
virtual int get_unit () { return dev ().minor; }
DWORD& get_device () { return dev (); }
DWORD get_major () { return dev ().get_major (); }
DWORD get_minor () { return dev ().get_minor (); }
virtual int get_unit () { return dev ().get_minor (); }
int get_access () const { return access; }
void set_access (int x) { access = x; }
@ -414,7 +414,6 @@ public:
virtual void seekdir (DIR *, long);
virtual void rewinddir (DIR *);
virtual int closedir (DIR *);
virtual bool is_slow () {return false;}
bool is_auto_device () {return isdevice () && !dev ().isfs ();}
bool is_fs_special () {return pc.is_fs_special ();}
bool issymlink () {return pc.issymlink ();}
@ -906,7 +905,6 @@ class fhandler_serial: public fhandler_base
select_record *select_read (select_stuff *);
select_record *select_write (select_stuff *);
select_record *select_except (select_stuff *);
bool is_slow () {return true;}
size_t size () const { return sizeof (*this);}
};
@ -1109,8 +1107,8 @@ class fhandler_console: public fhandler_termios
void set_close_on_exec (bool val);
void set_input_state ();
void send_winch_maybe ();
tty_min *get_tty_stuff (int);
bool is_slow () {return true;}
tty_min *get_tty_stuff ();
bool set_unit ();
static bool need_invisible ();
static bool has_a () {return !invisible_console;}
size_t size () const { return sizeof (*this);}
@ -1144,7 +1142,6 @@ class fhandler_tty_common: public fhandler_termios
select_record *select_read (select_stuff *);
select_record *select_write (select_stuff *);
select_record *select_except (select_stuff *);
bool is_slow () {return true;}
};
class fhandler_tty_slave: public fhandler_tty_common
@ -1435,7 +1432,7 @@ class fhandler_proc: public fhandler_virtual
fhandler_proc ();
virtual_ftype_t exists();
int readdir (DIR *, dirent *) __attribute__ ((regparm (3)));
static DWORD get_proc_fhandler(const char *path);
static fh_devices get_proc_fhandler (const char *path);
int open (int flags, mode_t mode = 0);
int __stdcall fstat (struct __stat64 *buf) __attribute__ ((regparm (2)));

View File

@ -78,50 +78,112 @@ beep ()
MessageBeep (MB_OK);
}
console_state *
open_shared_console (HWND hw, HANDLE& h, shared_locations& m)
{
wchar_t namebuf[(sizeof "XXXXXXXXXXXXXXXXXX-consNNNNNNNNNN")];
__small_swprintf (namebuf, L"%S-cons%p", &installation_key, hw);
h = NULL;
return (console_state *) open_shared (namebuf, 0, h,
sizeof (*shared_console_info),
&m);
}
class console_unit
{
int n;
unsigned long bitmask;
HWND me;
public:
operator int () const {return n;}
console_unit (HWND);
friend BOOL CALLBACK enum_windows (HWND, LPARAM);
};
BOOL CALLBACK
enum_windows (HWND hw, LPARAM lp)
{
console_unit *this1 = (console_unit *) lp;
if (hw == this1->me)
return TRUE;
shared_locations m = SH_JUSTOPEN;
HANDLE h;
console_state *cs;
if ((cs = open_shared_console (hw, h, m)))
{
this1->bitmask ^= 1 << cs->tty_min_state.getntty ();
UnmapViewOfFile ((void *) cs);
CloseHandle (h);
}
return TRUE;
}
console_unit::console_unit (HWND me0):
bitmask (0xffffffff), me (me0)
{
EnumWindows (enum_windows, (LPARAM) this);
n = (_minor_t) ffs (bitmask) - 1;
if (n < 0)
api_fatal ("console device allocation failure - too many consoles in use, max consoles is 32");
}
bool
fhandler_console::set_unit ()
{
bool need_initializing;
if (shared_console_info)
need_initializing = false;
else
{
HWND me = GetConsoleWindow ();
shared_locations m = SH_JUSTCREATE;
shared_console_info = open_shared_console (me, cygheap->console_h, m);
ProtectHandleINH (cygheap->console_h);
if ((need_initializing = m != SH_JUSTOPEN))
{
lock_ttys here;
shared_console_info->tty_min_state.setntty (DEV_CONS_MAJOR, console_unit (me));
}
}
dev_state = &shared_console_info->dev_state;
return need_initializing;
}
/* Allocate and initialize the shared record for the current console.
Returns a pointer to shared_console_info. */
tty_min *
fhandler_console::get_tty_stuff (int flags = 0)
fhandler_console::get_tty_stuff ()
{
if (dev_state)
return &shared_console_info->tty_min_state;
if (set_unit ())
{
shared_console_info =
(console_state *) open_shared (NULL, 0, cygheap->console_h,
sizeof (*shared_console_info),
SH_SHARED_CONSOLE);
dev_state = &shared_console_info->dev_state;
ProtectHandleINH (cygheap->console_h);
if (!shared_console_info->tty_min_state.ntty)
{
shared_console_info->tty_min_state.setntty (TTY_CONSOLE);
dev_state->scroll_region.Bottom = -1;
dev_state->dwLastCursorPosition.X = -1;
dev_state->dwLastCursorPosition.Y = -1;
dev_state->dwLastMousePosition.X = -1;
dev_state->dwLastMousePosition.Y = -1;
dev_state->dwLastButtonState = 0; /* none pressed */
dev_state->last_button_code = 3; /* released */
dev_state->underline_color = FOREGROUND_GREEN | FOREGROUND_BLUE;
dev_state->dim_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
dev_state->meta_mask = LEFT_ALT_PRESSED;
/* Set the mask that determines if an input keystroke is modified by
META. We set this based on the keyboard layout language loaded
for the current thread. The left <ALT> key always generates
META, but the right <ALT> key only generates META if we are using
an English keyboard because many "international" keyboards
replace common shell symbols ('[', '{', etc.) with accented
language-specific characters (umlaut, accent grave, etc.). On
these keyboards right <ALT> (called AltGr) is used to produce the
shell symbols and should not be interpreted as META. */
if (PRIMARYLANGID (LOWORD (GetKeyboardLayout (0))) == LANG_ENGLISH)
dev_state->meta_mask |= RIGHT_ALT_PRESSED;
dev_state->set_default_attr ();
dev_state->backspace_keycode = CERASE;
shared_console_info->tty_min_state.sethwnd ((HWND) INVALID_HANDLE_VALUE);
}
dev_state->scroll_region.Bottom = -1;
dev_state->dwLastCursorPosition.X = -1;
dev_state->dwLastCursorPosition.Y = -1;
dev_state->dwLastMousePosition.X = -1;
dev_state->dwLastMousePosition.Y = -1;
dev_state->dwLastButtonState = 0; /* none pressed */
dev_state->last_button_code = 3; /* released */
dev_state->underline_color = FOREGROUND_GREEN | FOREGROUND_BLUE;
dev_state->dim_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
dev_state->meta_mask = LEFT_ALT_PRESSED;
/* Set the mask that determines if an input keystroke is modified by
META. We set this based on the keyboard layout language loaded
for the current thread. The left <ALT> key always generates
META, but the right <ALT> key only generates META if we are using
an English keyboard because many "international" keyboards
replace common shell symbols ('[', '{', etc.) with accented
language-specific characters (umlaut, accent grave, etc.). On
these keyboards right <ALT> (called AltGr) is used to produce the
shell symbols and should not be interpreted as META. */
if (PRIMARYLANGID (LOWORD (GetKeyboardLayout (0))) == LANG_ENGLISH)
dev_state->meta_mask |= RIGHT_ALT_PRESSED;
dev_state->set_default_attr ();
dev_state->backspace_keycode = CERASE;
shared_console_info->tty_min_state.sethwnd ((HWND) INVALID_HANDLE_VALUE);
}
return &shared_console_info->tty_min_state;
}
@ -129,13 +191,14 @@ fhandler_console::get_tty_stuff (int flags = 0)
/* Return the tty structure associated with a given tty number. If the
tty number is < 0, just return a dummy record. */
tty_min *
tty_list::get_tty (int n)
tty_list::get_cttyp ()
{
static tty_min nada;
if (n == TTY_CONSOLE)
_dev_t n = myself->ctty;
if (iscons_dev (n))
return &shared_console_info->tty_min_state;
else if (n >= 0)
return &cygwin_shared->tty.ttys[n];
else if (n > 0)
return &ttys[device::minor (n)];
else
return &nada;
}
@ -695,7 +758,7 @@ fhandler_console::open (int flags, mode_t)
{
HANDLE h;
tcinit (get_tty_stuff (flags), false);
tcinit (get_tty_stuff (), false);
set_io_handle (NULL);
set_output_handle (NULL);
@ -847,7 +910,7 @@ fhandler_console::output_tcsetattr (int, struct termios const *t)
DWORD flags = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
int res = SetConsoleMode (get_output_handle (), flags) ? 0 : -1;
if (!res)
if (res)
__seterrno_from_win_error (GetLastError ());
syscall_printf ("%d = tcsetattr (,%x) (ENABLE FLAGS %x) (lflag %x oflag %x)",
res, t, flags, t->c_lflag, t->c_oflag);
@ -974,7 +1037,8 @@ fhandler_console::tcgetattr (struct termios *t)
fhandler_console::fhandler_console () :
fhandler_termios ()
{
dev ().parse (FH_CONSOLE);
get_tty_stuff ();
dev ().parse (shared_console_info->tty_min_state.getntty ());
trunc_buf.len = 0;
}
@ -2121,7 +2185,7 @@ set_console_title (char *title)
void
fhandler_console::fixup_after_fork_exec (bool execing)
{
get_tty_stuff ();
((fhandler_console *)archetype)->tc = tc = get_tty_stuff ();
}
// #define WINSTA_ACCESS (WINSTA_READATTRIBUTES | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | WINSTA_CREATEDESKTOP | WINSTA_EXITWINDOWS)

View File

@ -68,7 +68,7 @@ static const virt_tab_t proc_tab[] = {
{ _VN ("sysvipc"), FH_PROCSYSVIPC, virt_directory, NULL },
{ _VN ("uptime"), FH_PROC, virt_file, format_proc_uptime },
{ _VN ("version"), FH_PROC, virt_file, format_proc_version },
{ NULL, 0, 0, virt_none, NULL }
{ NULL, 0, FH_BAD, virt_none, NULL }
};
#define PROC_DIR_COUNT 4
@ -96,7 +96,7 @@ virt_tab_t *
virt_tab_search (const char *path, bool prefix, const virt_tab_t *table,
size_t nelem)
{
virt_tab_t key = { path, 0, 0, virt_none, NULL };
virt_tab_t key = { path, 0, FH_BAD, virt_none, NULL };
virt_tab_t *entry = (virt_tab_t *) bsearch (&key, table, nelem,
sizeof (virt_tab_t),
proc_tab_cmp);
@ -108,7 +108,7 @@ virt_tab_search (const char *path, bool prefix, const virt_tab_t *table,
/* Auxillary function that returns the fhandler associated with the given
path. */
DWORD
fh_devices
fhandler_proc::get_proc_fhandler (const char *path)
{
debug_printf ("get_proc_fhandler(%s)", path);
@ -1149,7 +1149,7 @@ format_proc_partitions (void *, char *&destbuf)
}
dev.parsedisk (drive_num, 0);
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
dev.major, dev.minor,
dev.get_major (), dev.get_minor (),
size >> 10, dev.name + 5);
/* Fetch drive layout info to get size of all partitions on the disk. */
if (wincap.has_disk_ex_ioctls ()
@ -1202,7 +1202,7 @@ format_proc_partitions (void *, char *&destbuf)
continue;
dev.parsedisk (drive_num, part_num);
bufptr += __small_sprintf (bufptr, "%5d %5d %9U %s\n",
dev.major, dev.minor,
dev.get_major (), dev.get_minor (),
size >> 10, dev.name + 5);
}
NtClose (devhdl);

View File

@ -76,7 +76,7 @@ static const virt_tab_t process_tab[] =
{ _VN ("uid"), FH_PROCESS, virt_file, format_process_uid },
{ _VN ("winexename"), FH_PROCESS, virt_file, format_process_winexename },
{ _VN ("winpid"), FH_PROCESS, virt_file, format_process_winpid },
{ NULL, 0, 0, virt_none, NULL }
{ NULL, 0, FH_BAD, virt_none, NULL }
};
static const int PROCESS_LINK_COUNT =
@ -418,9 +418,11 @@ format_process_gid (void *data, char *&destbuf)
static _off64_t
format_process_ctty (void *data, char *&destbuf)
{
device d;
_pinfo *p = (_pinfo *) data;
destbuf = (char *) crealloc_abort (destbuf, 40);
return __small_sprintf (destbuf, "%d\n", p->ctty);
d.parse (p->ctty);
destbuf = (char *) crealloc_abort (destbuf, strlen (d.name) + 2);
return __small_sprintf (destbuf, "%s\n", d.name);
}
static _off64_t
@ -1108,7 +1110,7 @@ format_process_stat (void *data, char *&destbuf)
"%lu",
p->pid, cmd,
state,
p->ppid, p->pgid, p->sid, makedev (FH_TTYS, p->ctty),
p->ppid, p->pgid, p->sid, p->ctty,
-1, 0, fault_count, fault_count, 0, 0, utime, stime,
utime, stime, priority, 0, 0, 0,
start_time, vmsize,

View File

@ -1,6 +1,6 @@
/* fhandler_procnet.cc: fhandler for /proc/net virtual filesystem
Copyright 2007, 2008, 2009 Red Hat, Inc.
Copyright 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
This file is part of Cygwin.
@ -42,7 +42,7 @@ static const virt_tab_t procnet_tab[] =
{ _VN ("."), FH_PROCNET, virt_directory, NULL },
{ _VN (".."), FH_PROCNET, virt_directory, NULL },
{ _VN ("if_inet6"), FH_PROCNET, virt_file, format_procnet_ifinet6 },
{ NULL, 0, 0, virt_none, NULL }
{ NULL, 0, FH_BAD, virt_none, NULL }
};
static const int PROCNET_LINK_COUNT =

View File

@ -271,7 +271,7 @@ fhandler_procsys::fstat (struct __stat64 *buf)
buf->st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
buf->st_uid = 544;
buf->st_gid = 18;
buf->st_dev = buf->st_rdev = dev ().devn;
buf->st_dev = buf->st_rdev = (int) dev ();
buf->st_ino = get_ino ();
switch (exists (buf))
{

View File

@ -49,7 +49,7 @@ static const virt_tab_t procsysvipc_tab[] =
{ _VN ("msg"), FH_PROCSYSVIPC, virt_file, format_procsysvipc_msg },
{ _VN ("sem"), FH_PROCSYSVIPC, virt_file, format_procsysvipc_sem },
{ _VN ("shm"), FH_PROCSYSVIPC, virt_file, format_procsysvipc_shm },
{ NULL, 0, 0, virt_none, NULL }
{ NULL, 0, FH_BAD, virt_none, NULL }
};
static const int PROCSYSVIPC_LINK_COUNT =

View File

@ -1180,7 +1180,7 @@ fhandler_dev_tape::unlock (int ret)
fhandler_dev_tape::fhandler_dev_tape ()
: fhandler_dev_raw ()
{
debug_printf ("unit: %d", dev ().minor);
debug_printf ("unit: %d", dev ().get_minor ());
}
int

View File

@ -145,8 +145,8 @@ fhandler_termios::bg_check (int sig)
if (sig < 0)
sig = -sig;
termios_printf ("bg I/O pgid %d, tpgid %d, %s, ntty tty%d", myself->pgid, tc->getpgid (),
myctty (), tc->ntty);
termios_printf ("bg I/O pgid %d, tpgid %d, %s, ntty %s", myself->pgid, tc->getpgid (),
myctty (), tc->ttyname ());
if (tc->getsid () == 0)
{

View File

@ -58,7 +58,7 @@ fhandler_tty_master::fhandler_tty_master ()
int
fhandler_tty_slave::get_unit ()
{
return dev () == FH_TTY ? myself->ctty : dev ().minor;
return dev ().get_minor ();
}
void
@ -300,7 +300,7 @@ fhandler_pty_master::process_slave_output (char *buf, size_t len, int pktmode_on
{
if (!PeekNamedPipe (handle, NULL, 0, NULL, &n, NULL))
{
termios_printf ("PeekNamedPipe failed, %E");
termios_printf ("PeekNamedPipe(%p) failed, %E", handle);
goto err;
}
if (n > 0)
@ -469,11 +469,11 @@ process_ioctl (void *)
/**********************************************************************/
/* Tty slave stuff */
fhandler_tty_slave::fhandler_tty_slave (int ntty)
fhandler_tty_slave::fhandler_tty_slave (int unit)
: fhandler_tty_common (), inuse (NULL)
{
if (ntty >= 0)
dev ().parse (DEV_TTYS_MAJOR, ntty);
if (unit >= 0)
dev ().parse (DEV_TTYS_MAJOR, unit);
}
/* FIXME: This function needs to close handles when it has
@ -1086,7 +1086,8 @@ fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
termios_printf ("ioctl (%x)", cmd);
if (myself->pgid && get_ttyp ()->getpgid () != myself->pgid
&& myself->ctty == get_unit () && (get_ttyp ()->ti.c_lflag & TOSTOP))
&& (unsigned) myself->ctty == FHDEV (DEV_TTYS_MAJOR, get_unit ())
&& (get_ttyp ()->ti.c_lflag & TOSTOP))
{
/* background process */
termios_printf ("bg ioctl pgid %d, tpgid %d, %s", myself->pgid,
@ -1390,11 +1391,11 @@ int
fhandler_pty_master::open (int flags, mode_t)
{
/* Note that allocate returns with the tty lock set if it was successful. */
int ntty = cygwin_shared->tty.allocate (false);
if (ntty < 0)
int unit = cygwin_shared->tty.allocate (false);
if (unit < 0)
return 0;
dev().devn = FHDEV (DEV_TTYM_MAJOR, ntty);
dev().parse (DEV_TTYM_MAJOR, unit);
if (!setup (true))
{
lock_ttys::release ();
@ -1631,7 +1632,10 @@ fhandler_tty_master::init_console ()
{
console = (fhandler_console *) build_fh_dev (*console_dev, "/dev/ttym_console");
if (console == NULL)
return -1;
{
termios_printf ("console creation failed?");
return -1;
}
console->init (NULL, GENERIC_READ | GENERIC_WRITE, O_BINARY);
cygheap->manage_console_count ("fhandler_tty_master::init_console", -1, true);
@ -1857,11 +1861,11 @@ fhandler_pty_master::setup (bool ispty)
goto err;
char buf[MAX_PATH];
errstr = shared_name (buf, OUTPUT_MUTEX, t.ntty);
errstr = shared_name (buf, OUTPUT_MUTEX, t.get_unit ());
if (!(output_mutex = CreateMutex (&sa, FALSE, buf)))
goto err;
errstr = shared_name (buf, INPUT_MUTEX, t.ntty);
errstr = shared_name (buf, INPUT_MUTEX, t.get_unit ());
if (!(input_mutex = CreateMutex (&sa, FALSE, buf)))
goto err;
@ -1893,7 +1897,7 @@ fhandler_pty_master::setup (bool ispty)
t.winsize.ws_row = 25;
t.master_pid = myself->pid;
termios_printf ("tty%d opened - from_slave %p, to_slave %p", t.ntty,
termios_printf ("tty%d opened - from_slave %p, to_slave %p", t.get_unit (),
get_io_handle (), get_output_handle ());
return true;

View File

@ -1,6 +1,6 @@
/* fhandler_virtual.h: Header for virtual fhandlers
Copyright 2009, 2010 Red Hat, Inc.
Copyright 2009, 2010, 2011 Red Hat, Inc.
This file is part of Cygwin.
@ -11,7 +11,7 @@ details. */
struct virt_tab_t {
const char *name;
size_t name_len;
__dev32_t fhandler;
fh_devices fhandler;
virtual_ftype_t type;
_off64_t (*format_func)(void *data, char *&);
};

View File

@ -234,7 +234,7 @@ frok::child (volatile char * volatile here)
sync_with_parent ("loaded dlls", true);
}
init_console_handler (myself->ctty >= 0);
init_console_handler (myself->ctty > 0);
ForceCloseHandle1 (fork_info->forker_finished, forker_finished);
pthread::atforkchild ();
@ -672,85 +672,12 @@ fork_init ()
}
#endif /*DEBUGGING*/
#ifdef NEWVFORK
/* Dummy function to force second assignment below to actually be
carried out */
static vfork_save *
get_vfork_val ()
{
return vfork_storage.val ();
}
#endif
extern "C" int
vfork ()
{
#ifndef NEWVFORK
debug_printf ("stub called");
return fork ();
#else
vfork_save *vf = get_vfork_val ();
char **esp, **pp;
if (vf == NULL)
vf = vfork_storage.create ();
else if (vf->pid)
return fork ();
// FIXME the tls stuff could introduce a signal race if a child process
// exits quickly.
if (!setjmp (vf->j))
{
vf->pid = -1;
__asm__ volatile ("movl %%esp,%0": "=r" (vf->vfork_esp):);
__asm__ volatile ("movl %%ebp,%0": "=r" (vf->vfork_ebp):);
for (pp = (char **) vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 2; pp++, esp++)
*pp = *esp;
vf->ctty = myself->ctty;
vf->sid = myself->sid;
vf->pgid = myself->pgid;
cygheap->ctty_on_hold = cygheap->ctty;
vf->console_count = cygheap->console_count;
debug_printf ("cygheap->ctty_on_hold %p, cygheap->console_count %d", cygheap->ctty_on_hold, cygheap->console_count);
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
debug_printf ("%d = vfork()", res);
_my_tls.call_signal_handler (); // FIXME: racy
vf->tls = _my_tls;
return res;
}
vf = get_vfork_val ();
for (pp = (char **) vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 2; pp++, esp++)
*esp = *pp;
cygheap->fdtab.vfork_parent_restore ();
myself->ctty = vf->ctty;
myself->sid = vf->sid;
myself->pgid = vf->pgid;
termios_printf ("cygheap->ctty %p, cygheap->ctty_on_hold %p", cygheap->ctty, cygheap->ctty_on_hold);
cygheap->console_count = vf->console_count;
if (vf->pid < 0)
{
int exitval = vf->exitval;
vf->pid = 0;
if ((vf->pid = fork ()) == 0)
exit (exitval);
}
int pid = vf->pid;
vf->pid = 0;
debug_printf ("exiting vfork, pid %d", pid);
sig_dispatch_pending ();
_my_tls.call_signal_handler (); // FIXME: racy
_my_tls = vf->tls;
return pid;
#endif
}
/* Copy memory from one process to another. */

View File

@ -133,7 +133,7 @@ heap_init ()
if ((reserve_size -= page_const) < allocsize)
break;
}
if (!p && in_forkee && !fork_info->handle_failure (GetLastError ()))
if (!p && in_forkee && !fork_info->abort (NULL))
api_fatal ("couldn't allocate heap, %E, base %p, top %p, "
"reserve_size %d, allocsize %d, page_const %d",
cygheap->user_heap.base, cygheap->user_heap.top,

View File

@ -1,7 +1,7 @@
/* sys/strace.h
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2008, 2010 Red Hat, Inc.
2005, 2008, 2010, 2011 Red Hat, Inc.
This file is part of Cygwin.
@ -116,6 +116,12 @@ void strace_printf (unsigned, const char *func, const char *, ...);
strace.prntf((_STRACE_ ## what) | _STRACE_NOTALL, __PRETTY_FUNCTION__, fmt, ## args); \
0; \
}))
#define strace_vprintf(what, fmt, arg) \
((void) ({\
if ((_STRACE_ ## what & _STRACE_SYSTEM) || strace.active ()) \
strace.vprntf((_STRACE_ ## what) | _STRACE_NOTALL, __PRETTY_FUNCTION__, fmt, arg); \
0; \
}))
#endif /*NOSTRACE*/
#define debug_printf(fmt, args...) strace_printf_wrap(DEBUG, fmt , ## args)

View File

@ -561,7 +561,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
MALLOC_CHECK;
dev.devn = FH_FS;
dev = FH_FS;
*flags = 0;
debug_printf ("conv_to_win32_path (%s)", src_path);
@ -619,11 +619,11 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
if (isproc (src_path))
{
dev = *proc_dev;
dev.devn = fhandler_proc::get_proc_fhandler (src_path);
if (dev.devn == FH_BAD)
dev = fhandler_proc::get_proc_fhandler (src_path);
if (dev == FH_BAD)
return ENOENT;
set_flags (flags, PATH_BINARY);
if (isprocsys_dev (dev.devn))
if (isprocsys_dev (dev))
{
if (src_path[procsys_len])
backslashify (src_path + procsys_len, dst, 0);

View File

@ -251,6 +251,7 @@ typedef enum _SYSTEM_INFORMATION_CLASS
SystemTimeOfDayInformation = 3,
SystemProcessesAndThreadsInformation = 5,
SystemProcessorTimes = 8,
SystemHandleInformation = 16,
SystemPagefileInformation = 18,
/* There are a lot more of these... */
} SYSTEM_INFORMATION_CLASS;

View File

@ -712,7 +712,7 @@ path_conv::check (const char *src, unsigned opt,
sym.pflags |= pflags_or;
if (dev.major == DEV_CYGDRIVE_MAJOR)
if (dev.get_major () == DEV_CYGDRIVE_MAJOR)
{
if (!component)
fileattr = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_READONLY;
@ -720,13 +720,13 @@ path_conv::check (const char *src, unsigned opt,
{
fileattr = getfileattr (THIS_path,
sym.pflags & MOUNT_NOPOSIX);
dev.devn = FH_FS;
dev = FH_FS;
}
goto out;
}
else if (dev == FH_DEV)
{
dev.devn = FH_FS;
dev = FH_FS;
#if 0
fileattr = getfileattr (THIS_path, sym.pflags & MOUNT_NOPOSIX);
if (!component && fileattr == INVALID_FILE_ATTRIBUTES)
@ -736,7 +736,7 @@ path_conv::check (const char *src, unsigned opt,
}
#endif
}
else if (isvirtual_dev (dev.devn))
else if (isvirtual_dev (dev))
{
/* FIXME: Calling build_fhandler here is not the right way to handle this. */
fhandler_virtual *fh = (fhandler_virtual *) build_fh_dev (dev, path_copy);
@ -804,12 +804,12 @@ path_conv::check (const char *src, unsigned opt,
fileattr = INVALID_FILE_ATTRIBUTES;
goto virtual_component_retry;
}
if (component == 0 || dev.devn != FH_NETDRIVE)
if (component == 0 || dev != FH_NETDRIVE)
path_flags |= PATH_RO;
goto out;
}
/* devn should not be a device. If it is, then stop parsing now. */
else if (dev.devn != FH_FS)
else if (dev != FH_FS)
{
fileattr = 0;
path_flags = sym.pflags;
@ -1008,7 +1008,7 @@ out:
set_path (THIS_path);
if (add_ext)
add_ext_from_sym (sym);
if (dev.devn == FH_NETDRIVE && component)
if (dev == FH_NETDRIVE && component)
{
/* This case indicates a non-existant resp. a non-retrievable
share. This happens for instance if the share is a printer.
@ -1017,7 +1017,7 @@ out:
is used on it. */
dev.parse (FH_FS);
}
else if (isproc_dev (dev.devn) && fileattr == INVALID_FILE_ATTRIBUTES)
else if (isproc_dev (dev) && fileattr == INVALID_FILE_ATTRIBUTES)
{
/* FIXME: Usually we don't set error to ENOENT if a file doesn't
exist. This is typically indicated by the fileattr content.

View File

@ -17,14 +17,6 @@ details. */
#include <sys/ioctl.h>
#include <fcntl.h>
#define isproc_dev(devn) \
(devn >= FH_PROC_MIN_MINOR && devn <= FH_PROC_MAX_MINOR)
#define isprocsys_dev(devn) (devn == FH_PROCSYS)
#define isvirtual_dev(devn) \
(isproc_dev (devn) || devn == FH_CYGDRIVE || devn == FH_NETDRIVE)
inline bool
has_attribute (DWORD attributes, DWORD attribs_to_test)
{
@ -173,15 +165,15 @@ class path_conv
int issymlink () const {return path_flags & PATH_SYMLINK;}
int is_lnk_symlink () const {return path_flags & PATH_LNK;}
int is_rep_symlink () const {return path_flags & PATH_REP;}
int isdevice () const {return dev.devn && dev.devn != FH_FS && dev.devn != FH_FIFO;}
int isfifo () const {return dev == FH_FIFO;}
int isspecial () const {return dev.devn && dev.devn != FH_FS;}
int iscygdrive () const {return dev.devn == FH_CYGDRIVE;}
int isdevice () const {return dev.not_device (FH_FS) && dev.not_device (FH_FIFO);}
int isfifo () const {return dev.is_device (FH_FIFO);}
int isspecial () const {return dev.not_device (FH_FS);}
int iscygdrive () const {return dev.is_device (FH_CYGDRIVE);}
int is_auto_device () const {return isdevice () && !is_fs_special ();}
int is_fs_device () const {return isdevice () && is_fs_special ();}
int is_fs_special () const {return dev.is_fs_special ();}
int is_lnk_special () const {return is_fs_device () || isfifo () || is_lnk_symlink ();}
int issocket () const {return dev.devn == FH_UNIX;}
int issocket () const {return dev.is_device (FH_UNIX);}
int iscygexec () const {return path_flags & PATH_CYGWIN_EXEC;}
void set_cygexec (bool isset)
{
@ -298,8 +290,8 @@ class path_conv
cfree (modifiable_path ());
cfree ((char *) normalized_path);
}
DWORD get_devn () const {return dev.devn;}
short get_unitn () const {return dev.minor;}
DWORD get_devn () {return (DWORD) dev;}
short get_unitn () const {return dev.get_minor ();}
DWORD file_attributes () const {return fileattr;}
void file_attributes (DWORD new_attr) {fileattr = new_attr;}
DWORD fs_flags () {return fs.flags ();}

View File

@ -187,10 +187,10 @@ pinfo::exit (DWORD n)
}
sigproc_terminate (ES_FINAL);
if (myself->ctty >= 0 && myself->ctty != TTY_CONSOLE)
if (myself->ctty > 0 && !iscons_dev (myself->ctty))
{
lock_ttys here;
tty *t = cygwin_shared->tty[myself->ctty];
tty *t = cygwin_shared->tty[device::minor(myself->ctty)];
if (!t->slave_alive ())
t->setpgid (0);
}
@ -361,12 +361,14 @@ pinfo::set_acl()
const char *
_pinfo::_ctty (char *buf)
{
if (ctty == TTY_CONSOLE)
strcpy (buf, "ctty /dev/console");
else if (ctty < 0)
if (ctty <= 0)
strcpy (buf, "no ctty");
else
__small_sprintf (buf, "ctty /dev/tty%d", ctty);
{
device d;
d.parse (ctty);
__small_sprintf (buf, "ctty %s", d.name);
}
return buf;
}
@ -374,12 +376,12 @@ void
_pinfo::set_ctty (tty_min *tc, int flags, fhandler_termios *fh)
{
debug_printf ("old %s, ctty %d, tc->ntty %d flags & O_NOCTTY %p", __ctty (), ctty, tc->ntty, flags & O_NOCTTY);
if ((ctty < 0 || ctty == tc->ntty) && !(flags & O_NOCTTY))
if ((ctty <= 0 || ctty == tc->ntty) && !(flags & O_NOCTTY))
{
ctty = tc->ntty;
if (cygheap->ctty != fh->archetype)
{
debug_printf ("/dev/tty%d cygheap->ctty %p, archetype %p", ctty, cygheap->ctty, fh->archetype);
debug_printf ("cygheap->ctty %p, archetype %p", cygheap->ctty, fh->archetype);
if (!cygheap->ctty)
syscall_printf ("ctty was NULL");
else

View File

@ -32,10 +32,11 @@ enum picom
PICOM_PIPE_FHANDLER = 6
};
#define EXITCODE_SET 0x8000000
#define EXITCODE_NOSET 0x4000000
#define EXITCODE_RETRY 0x2000000
#define EXITCODE_OK 0x1000000
#define EXITCODE_SET 0x8000000
#define EXITCODE_NOSET 0x4000000
#define EXITCODE_RETRY 0x2000000
#define EXITCODE_OK 0x1000000
#define EXITCODE_FORK_FAILED 0x0800000
class fhandler_pipe;

View File

@ -206,10 +206,7 @@ shared_name (WCHAR *ret_buf, const WCHAR *str, int num)
/* The order in offsets is so that the constant blocks shared_info
and user_info are right below the cygwin DLL, then the pinfo block
which changes with each process. Below that is the console_state,
an optional block which only exists when running in a Windows console
window. Therefore, if we are not running in a console, we have 64K
more of contiguous memory below the Cygwin DLL. */
which changes with each process. */
static ptrdiff_t offsets[] =
{
- pround (sizeof (shared_info)),
@ -220,8 +217,7 @@ static ptrdiff_t offsets[] =
- pround (sizeof (_pinfo)),
- pround (sizeof (shared_info))
- pround (sizeof (user_info))
- pround (sizeof (_pinfo))
- pround (sizeof (console_state)),
- pround (sizeof (_pinfo)),
0
};

View File

@ -65,7 +65,6 @@ enum shared_locations
SH_CYGWIN_SHARED,
SH_USER_SHARED,
SH_MYSELF,
SH_SHARED_CONSOLE,
SH_TOTAL_SIZE,
SH_JUSTCREATE,
SH_JUSTOPEN

View File

@ -1,9 +1,7 @@
/* sigproc.cc: inter/intra signal and sub process handler
Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010 Red Hat, Inc.
Written by Christopher Faylor
2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
This file is part of Cygwin.
@ -930,11 +928,18 @@ child_info::proc_retry (HANDLE h)
}
bool
child_info_fork::handle_failure (DWORD err)
child_info_fork::abort (const char *fmt, ...)
{
if (fmt)
{
va_list ap;
va_start (ap, fmt);
strace_vprintf (SIGP, fmt, ap);
ExitProcess (EXITCODE_FORK_FAILED);
}
if (retry > 0)
ExitProcess (EXITCODE_RETRY);
return 0;
return false;
}
/* Check the state of all of our children to see if any are stopped or

View File

@ -1369,7 +1369,7 @@ umask (mode_t mask)
int
chmod_device (path_conv& pc, mode_t mode)
{
return mknod_worker (pc.get_win32 (), pc.dev.mode & S_IFMT, mode, pc.dev.major, pc.dev.minor);
return mknod_worker (pc.get_win32 (), pc.dev.mode & S_IFMT, mode, pc.dev.get_major (), pc.dev.get_minor ());
}
#define FILTERED_MODE(m) ((m) & (S_ISUID | S_ISGID | S_ISVTX \
@ -2370,13 +2370,16 @@ ttyname (int fd)
extern "C" char *
ctermid (char *str)
{
static NO_COPY char buf[16];
if (str == NULL)
str = buf;
if (!real_tty_attached (myself))
strcpy (str, "/dev/conin");
str = _my_tls.locals.ttybuf;
if (myself->ctty < 0)
strcpy (str, "no tty");
else
__small_sprintf (str, "/dev/tty%d", myself->ctty);
{
device d;
d.parse (myself->ctty);
strcpy (str, d.name);
}
return str;
}

View File

@ -1,6 +1,6 @@
//;# autogenerated: Do not edit.
//; $tls::sizeof__cygtls = 4012;
//; $tls::sizeof__cygtls = 4044;
//; $tls::func = -12700;
//; $tls::pfunc = 0;
//; $tls::saved_errno = -12696;
@ -37,26 +37,26 @@
//; $tls::p__dontuse = 412;
//; $tls::locals = -11200;
//; $tls::plocals = 1500;
//; $tls::_ctinfo = -9772;
//; $tls::p_ctinfo = 2928;
//; $tls::andreas = -9768;
//; $tls::pandreas = 2932;
//; $tls::wq = -9764;
//; $tls::pwq = 2936;
//; $tls::sig = -9736;
//; $tls::psig = 2964;
//; $tls::incyg = -9732;
//; $tls::pincyg = 2968;
//; $tls::spinning = -9728;
//; $tls::pspinning = 2972;
//; $tls::stacklock = -9724;
//; $tls::pstacklock = 2976;
//; $tls::stackptr = -9720;
//; $tls::pstackptr = 2980;
//; $tls::stack = -9716;
//; $tls::pstack = 2984;
//; $tls::initialized = -8692;
//; $tls::pinitialized = 4008;
//; $tls::_ctinfo = -9740;
//; $tls::p_ctinfo = 2960;
//; $tls::andreas = -9736;
//; $tls::pandreas = 2964;
//; $tls::wq = -9732;
//; $tls::pwq = 2968;
//; $tls::sig = -9704;
//; $tls::psig = 2996;
//; $tls::incyg = -9700;
//; $tls::pincyg = 3000;
//; $tls::spinning = -9696;
//; $tls::pspinning = 3004;
//; $tls::stacklock = -9692;
//; $tls::pstacklock = 3008;
//; $tls::stackptr = -9688;
//; $tls::pstackptr = 3012;
//; $tls::stack = -9684;
//; $tls::pstack = 3016;
//; $tls::initialized = -8660;
//; $tls::pinitialized = 4040;
//; __DATA__
#define tls_func (-12700)
@ -95,23 +95,23 @@
#define tls_p__dontuse (412)
#define tls_locals (-11200)
#define tls_plocals (1500)
#define tls__ctinfo (-9772)
#define tls_p_ctinfo (2928)
#define tls_andreas (-9768)
#define tls_pandreas (2932)
#define tls_wq (-9764)
#define tls_pwq (2936)
#define tls_sig (-9736)
#define tls_psig (2964)
#define tls_incyg (-9732)
#define tls_pincyg (2968)
#define tls_spinning (-9728)
#define tls_pspinning (2972)
#define tls_stacklock (-9724)
#define tls_pstacklock (2976)
#define tls_stackptr (-9720)
#define tls_pstackptr (2980)
#define tls_stack (-9716)
#define tls_pstack (2984)
#define tls_initialized (-8692)
#define tls_pinitialized (4008)
#define tls__ctinfo (-9740)
#define tls_p_ctinfo (2960)
#define tls_andreas (-9736)
#define tls_pandreas (2964)
#define tls_wq (-9732)
#define tls_pwq (2968)
#define tls_sig (-9704)
#define tls_psig (2996)
#define tls_incyg (-9700)
#define tls_pincyg (3000)
#define tls_spinning (-9696)
#define tls_pspinning (3004)
#define tls_stacklock (-9692)
#define tls_pstacklock (3008)
#define tls_stackptr (-9688)
#define tls_pstackptr (3012)
#define tls_stack (-9684)
#define tls_pstack (3016)
#define tls_initialized (-8660)
#define tls_pinitialized (4040)

View File

@ -1,7 +1,7 @@
/* tty.cc
Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009,
2010 Red Hat, Inc.
2010, 2011 Red Hat, Inc.
This file is part of Cygwin.
@ -55,7 +55,7 @@ ttyslot (void)
{
if (NOTSTATE (myself, PID_USETTY))
return -1;
return myself->ctty;
return device::minor (myself->ctty);
}
HANDLE NO_COPY tty_list::mutex = NULL;
@ -119,21 +119,24 @@ tty::create_master (int ttynum)
strncpy (our_utmp.ut_id, our_utmp.ut_line + len, UT_IDLEN);
our_utmp.ut_type = USER_PROCESS;
our_utmp.ut_pid = myself->pid;
myself->ctty = ttynum;
myself->ctty = FHDEV (DEV_TTYS_MAJOR, ttynum);
login (&our_utmp);
}
}
int __stdcall
tty_list::attach (int num)
tty_list::attach (int n)
{
if (num != -1)
{
return connect (num);
}
if (NOTSTATE (myself, PID_USETTY))
return -1;
return allocate (true);
int res;
if (iscons_dev (n))
res = -1;
else if (n != -1)
res = connect (device::minor (n));
else if (ISSTATE (myself, PID_USETTY))
res = allocate (true);
else
res = -1;
return res;
}
void
@ -141,10 +144,10 @@ tty_list::terminate ()
{
if (NOTSTATE (myself, PID_USETTY))
return;
int ttynum = myself->ctty;
int ttynum = device::minor (myself->ctty);
/* Keep master running till there are connected clients */
if (ttynum != -1 && tty_master && ttys[ttynum].master_pid == myself->pid)
if (myself->ctty != -1 && tty_master && ttys[ttynum].master_pid == myself->pid)
{
tty *t = ttys + ttynum;
/* Wait for children which rely on tty handling in this process to
@ -202,7 +205,7 @@ tty_list::init ()
for (int i = 0; i < NTTYS; i++)
{
ttys[i].init ();
ttys[i].setntty (i);
ttys[i].setntty (DEV_TTYS_MAJOR, i);
}
}
@ -292,7 +295,7 @@ tty::exists ()
/* Attempt to open the from-master side of the tty. If it is accessible
then it exists although it may have been privileges to actually use it. */
char pipename[sizeof("ttyNNNN-from-master")];
__small_sprintf (pipename, "tty%d-from-master", ntty);
__small_sprintf (pipename, "tty%d-from-master", get_unit ());
HANDLE r, w;
int res = fhandler_pipe::create_selectable (&sec_none_nih, r, w, 0, pipename);
if (res)
@ -323,7 +326,7 @@ HANDLE
tty::open_mutex (const char *mutex, ACCESS_MASK access)
{
char buf[MAX_PATH];
shared_name (buf, mutex, ntty);
shared_name (buf, mutex, get_unit ());
return OpenMutex (access, TRUE, buf);
}
@ -331,7 +334,7 @@ HANDLE
tty::open_inuse (ACCESS_MASK access)
{
char buf[MAX_PATH];
shared_name (buf, TTY_SLAVE_ALIVE, ntty);
shared_name (buf, TTY_SLAVE_ALIVE, get_unit ());
return OpenEvent (access, FALSE, buf);
}
@ -341,7 +344,7 @@ tty::create_inuse (PSECURITY_ATTRIBUTES sa)
HANDLE h;
char buf[MAX_PATH];
shared_name (buf, TTY_SLAVE_ALIVE, ntty);
shared_name (buf, TTY_SLAVE_ALIVE, get_unit ());
h = CreateEvent (sa, TRUE, FALSE, buf);
termios_printf ("%s %p", buf, h);
if (!h)
@ -366,7 +369,7 @@ tty::get_event (const char *fmt, PSECURITY_ATTRIBUTES sa, BOOL manual_reset)
HANDLE hev;
char buf[MAX_PATH];
shared_name (buf, fmt, ntty);
shared_name (buf, fmt, get_unit ());
if (!sa)
sa = &sec_all;
if (!(hev = CreateEvent (sa, manual_reset, FALSE, buf)))
@ -394,3 +397,11 @@ lock_ttys::release ()
{
ReleaseMutex (tty_list::mutex);
}
const char *
tty_min::ttyname ()
{
device d;
d.parse (ntty);
return d.name;
}

View File

@ -1,6 +1,6 @@
/* tty.h: shared tty info for cygwin
Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010 Red Hat, Inc.
Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011 Red Hat, Inc.
This file is part of Cygwin.
@ -13,7 +13,7 @@ details. */
#define INP_BUFFER_SIZE 256
#define OUT_BUFFER_SIZE 256
#define NTTYS 128
#define real_tty_attached(p) ((p)->ctty >= 0 && (p)->ctty != TTY_CONSOLE)
#define real_tty_attached(p) ((p)->ctty >= 0 && !iscons_dev ((p)->ctty))
/* Input/Output/ioctl events */
@ -33,6 +33,7 @@ details. */
#define MIN_CTRL_C_SLOP 50
#endif
#include <devices.h>
class tty_min
{
pid_t sid; /* Session ID of tty */
@ -45,7 +46,7 @@ class tty_min
public:
pid_t pgid;
int output_stopped;
int ntty;
fh_devices ntty;
DWORD last_ctrl_c; /* tick count of last ctrl-c */
HWND hwnd; /* Console window handle tty belongs to */
@ -70,14 +71,17 @@ public:
int ioctl_retval;
int write_error;
void setntty (int n) {ntty = n;}
pid_t getpgid () {return pgid;}
void setntty (_major_t t, int n) {ntty = (fh_devices) FHDEV (t, n);}
int getntty () const {return ntty;}
int get_unit () const {return device::minor (ntty);}
pid_t getpgid () const {return pgid;}
void setpgid (int pid) {pgid = pid;}
int getsid () {return sid;}
int getsid () const {return sid;}
void setsid (pid_t tsid) {sid = tsid;}
void kill_pgrp (int sig);
HWND gethwnd () {return hwnd;}
HWND gethwnd () const {return hwnd;}
void sethwnd (HWND wnd) {hwnd = wnd;}
const char *ttyname () __attribute ((regparm (1)));
};
class fhandler_pty_master;
@ -117,13 +121,13 @@ class tty_list
static HANDLE mutex;
public:
tty * operator [](int n) {return ttys + n;}
tty * operator [](int n) {return ttys + device::minor (n);}
int allocate (bool); /* true if allocate a tty, pty otherwise */
int connect (int);
void terminate ();
void init ();
tty_min *get_tty (int n);
int __stdcall attach (int);
tty_min *get_cttyp ();
int __stdcall attach (int n) __attribute__ ((regparm (2)));
static void __stdcall init_session ();
friend class lock_ttys;
};

View File

@ -133,7 +133,6 @@ extern int cygserver_running;
#define SIGTOMASK(sig) (1 << ((sig) - 1))
#define set_api_fatal_return(n) do {extern int __api_fatal_exit_val; __api_fatal_exit_val = (n);} while (0)
#define api_fatal(fmt, args...) __api_fatal (fmt,## args)
#undef issep
#define issep(ch) (strchr (" \t\n\r", (ch)) != NULL)
@ -239,7 +238,8 @@ void __set_winsock_errno (const char *fn, int ln) __attribute__ ((regparm(2)));
extern bool wsock_started;
/* Printf type functions */
extern "C" void __api_fatal (const char *, ...) __attribute__ ((noreturn));
extern "C" void vapi_fatal (const char *, va_list ap) __attribute__ ((noreturn));
extern "C" void api_fatal (const char *, ...) __attribute__ ((noreturn));
int __small_sprintf (char *dst, const char *fmt, ...) /*__attribute__ ((regparm (2)))*/;
int __small_vsprintf (char *dst, const char *fmt, va_list ap) /*__attribute__ ((regparm (3)))*/;
int __small_swprintf (PWCHAR dst, const WCHAR *fmt, ...) /*__attribute__ ((regparm (2)))*/;