2000-08-12 12:48:44 +08:00
|
|
|
/* dtable.cc: file descriptor support.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-02-20 12:25:33 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
|
2011-04-18 03:56:25 +08:00
|
|
|
2005, 2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
|
|
|
#define __INSIDE_CYGWIN_NET__
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2008-03-23 05:04:16 +08:00
|
|
|
#include <wchar.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-03-21 03:50:28 +08:00
|
|
|
#define USE_SYS_TYPES_FD_SET
|
2000-07-28 01:30:51 +08:00
|
|
|
#include <winsock.h>
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "pinfo.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-03-05 14:28:25 +08:00
|
|
|
#include "perprocess.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2009-07-01 05:18:44 +08:00
|
|
|
#include "select.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "dtable.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "cygheap.h"
|
2008-03-11 21:17:52 +08:00
|
|
|
#include "tls_pbuf.h"
|
2002-05-28 09:55:40 +08:00
|
|
|
#include "ntdll.h"
|
2006-04-22 02:53:05 +08:00
|
|
|
#include "shared_info.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-06 13:17:22 +08:00
|
|
|
static const NO_COPY DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
|
2002-02-23 03:33:41 +08:00
|
|
|
STD_ERROR_HANDLE};
|
2000-10-09 10:53:44 +08:00
|
|
|
|
2008-03-23 05:27:05 +08:00
|
|
|
static bool handle_to_fn (HANDLE, char *);
|
2008-03-23 05:04:16 +08:00
|
|
|
|
|
|
|
#define WCLEN(x) ((sizeof (x) / sizeof (WCHAR)) - 1)
|
2011-08-20 02:19:22 +08:00
|
|
|
static const char unknown_file[] = "some disk file";
|
|
|
|
static const WCHAR DEV_NULL[] = L"\\Device\\Null";
|
2009-08-10 23:38:37 +08:00
|
|
|
static const WCHAR DEV_SOCKET[] = L"\\Device\\Afd";
|
2008-03-23 05:04:16 +08:00
|
|
|
|
2011-08-20 02:19:22 +08:00
|
|
|
static const WCHAR DEVICE_PREFIX[] = L"\\device\\";
|
|
|
|
static const size_t DEVICE_PREFIX_LEN WCLEN (DEVICE_PREFIX);
|
2008-03-23 05:04:16 +08:00
|
|
|
|
|
|
|
static const WCHAR DEV_NAMED_PIPE[] = L"\\Device\\NamedPipe\\";
|
|
|
|
static const size_t DEV_NAMED_PIPE_LEN = WCLEN (DEV_NAMED_PIPE);
|
2002-10-08 04:06:16 +08:00
|
|
|
|
2008-03-23 05:04:16 +08:00
|
|
|
static const WCHAR DEV_REMOTE[] = L"\\Device\\LanmanRedirector\\";
|
|
|
|
static const size_t DEV_REMOTE_LEN = WCLEN (DEV_REMOTE);
|
|
|
|
|
|
|
|
static const WCHAR DEV_REMOTE1[] = L"\\Device\\WinDfs\\Root\\";
|
|
|
|
static const size_t DEV_REMOTE1_LEN = WCLEN (DEV_REMOTE1);
|
2007-12-17 05:21:23 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Set aside space for the table of fds */
|
|
|
|
void
|
2004-01-14 23:45:37 +08:00
|
|
|
dtable_init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-04-19 05:10:15 +08:00
|
|
|
if (!cygheap->fdtab.size)
|
2001-09-05 04:48:45 +08:00
|
|
|
cygheap->fdtab.extend (NOFILE_INCR);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __stdcall
|
|
|
|
set_std_handle (int fd)
|
|
|
|
{
|
|
|
|
if (fd == 0)
|
2001-04-19 05:10:15 +08:00
|
|
|
SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_handle ());
|
2000-10-09 10:53:44 +08:00
|
|
|
else if (fd <= 2)
|
2001-04-19 05:10:15 +08:00
|
|
|
SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2000-08-12 12:48:44 +08:00
|
|
|
dtable::extend (int howmuch)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int new_size = size + howmuch;
|
|
|
|
fhandler_base **newfds;
|
|
|
|
|
|
|
|
if (howmuch <= 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-09-22 12:09:03 +08:00
|
|
|
if (new_size > OPEN_MAX_MAX)
|
2003-07-09 09:33:06 +08:00
|
|
|
{
|
|
|
|
set_errno (EMFILE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:48:45 +08:00
|
|
|
/* Try to allocate more space for fd table. We can't call realloc ()
|
2000-02-18 03:38:33 +08:00
|
|
|
here to preserve old table if memory allocation fails */
|
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
if (!(newfds = (fhandler_base **) ccalloc (HEAP_ARGV, new_size, sizeof newfds[0])))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
debug_printf ("calloc failed");
|
2003-07-09 09:33:06 +08:00
|
|
|
set_errno (ENOMEM);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (fds)
|
|
|
|
{
|
2003-07-09 09:33:06 +08:00
|
|
|
memcpy (newfds, fds, size * sizeof (fds[0]));
|
2004-04-11 12:00:01 +08:00
|
|
|
cfree (fds);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
size = new_size;
|
|
|
|
fds = newfds;
|
2000-02-24 11:00:37 +08:00
|
|
|
debug_printf ("size %d, fds %p", size, fds);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-02-23 03:33:41 +08:00
|
|
|
void
|
|
|
|
dtable::get_debugger_info ()
|
|
|
|
{
|
2009-07-04 02:05:51 +08:00
|
|
|
extern bool jit_debug;
|
|
|
|
if (!jit_debug && being_debugged ())
|
2002-02-23 03:33:41 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
char std[3][sizeof ("/dev/ptyNNNN")];
|
2002-02-23 03:33:41 +08:00
|
|
|
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);
|
|
|
|
OutputDebugString (buf);
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
if (std[i][0])
|
|
|
|
{
|
|
|
|
HANDLE h = GetStdHandle (std_consts[i]);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_base *fh = build_fh_name (std[i]);
|
2002-02-23 03:33:41 +08:00
|
|
|
if (!fh)
|
|
|
|
continue;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fds[i] = fh;
|
2004-07-23 17:04:59 +08:00
|
|
|
if (!fh->open ((i ? (i == 2 ? O_RDWR : O_WRONLY) : O_RDONLY)
|
|
|
|
| O_BINARY, 0777))
|
2002-02-23 03:33:41 +08:00
|
|
|
release (i);
|
|
|
|
else
|
2011-08-18 17:16:50 +08:00
|
|
|
{
|
|
|
|
CloseHandle (h);
|
|
|
|
/* Copy to Windows' idea of a standard handle, otherwise
|
|
|
|
we have invalid standard handles when calling Windows
|
|
|
|
functions (small_printf and strace might suffer, too). */
|
|
|
|
SetStdHandle (std_consts[i], i ? fh->get_output_handle ()
|
|
|
|
: fh->get_handle ());
|
|
|
|
}
|
2002-02-23 03:33:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Initialize the file descriptor/handle mapping table.
|
2002-01-07 01:29:41 +08:00
|
|
|
This function should only be called when a cygwin function is invoked
|
|
|
|
by a non-cygwin function, i.e., it should only happen very rarely. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
void
|
2002-02-23 03:33:41 +08:00
|
|
|
dtable::stdio_init ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
/* Set these before trying to output anything from strace.
|
|
|
|
Also, always set them even if we're to pick up our parent's fds
|
|
|
|
in case they're missed. */
|
|
|
|
|
2004-11-26 12:15:10 +08:00
|
|
|
if (myself->cygstarted || ISSTATE (myself, PID_CYGPARENT))
|
2006-03-24 00:52:34 +08:00
|
|
|
{
|
2011-05-29 02:17:09 +08:00
|
|
|
tty_min *t = cygwin_shared->tty.get_cttyp ();
|
2011-06-15 05:48:43 +08:00
|
|
|
if (t && t->getpgid () == myself->pid && t->is_console)
|
2006-04-22 02:53:05 +08:00
|
|
|
init_console_handler (true);
|
2006-03-24 00:52:34 +08:00
|
|
|
return;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-02-23 03:33:41 +08:00
|
|
|
HANDLE in = GetStdHandle (STD_INPUT_HANDLE);
|
|
|
|
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
|
|
|
|
HANDLE err = GetStdHandle (STD_ERROR_HANDLE);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-10-15 04:25:52 +08:00
|
|
|
init_std_file_from_handle (0, in);
|
2002-02-23 03:33:41 +08:00
|
|
|
|
|
|
|
/* STD_ERROR_HANDLE has been observed to be the same as
|
|
|
|
STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes
|
|
|
|
to pass data from child to parent). */
|
2008-10-18 00:24:20 +08:00
|
|
|
/* CV 2008-10-17: Under debugger control, std fd's have been potentially
|
|
|
|
initialized in dtable::get_debugger_info (). In this case
|
|
|
|
init_std_file_from_handle is a no-op, so, even if out == err we don't
|
|
|
|
want to duplicate the handle since it will be unused. */
|
2011-08-18 17:16:50 +08:00
|
|
|
if (out == err && (!being_debugged () || not_open (2)))
|
2002-02-23 03:33:41 +08:00
|
|
|
{
|
|
|
|
/* Since this code is not invoked for forked tasks, we don't have
|
|
|
|
to worry about the close-on-exec flag here. */
|
2009-11-26 18:58:06 +08:00
|
|
|
if (!DuplicateHandle (GetCurrentProcess (), out,
|
|
|
|
GetCurrentProcess (), &err,
|
|
|
|
0, TRUE, DUPLICATE_SAME_ACCESS))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-02-23 03:33:41 +08:00
|
|
|
/* If that fails, do this as a fall back. */
|
|
|
|
err = out;
|
2009-11-26 18:58:06 +08:00
|
|
|
system_printf ("couldn't make stderr distinct from stdout, %E");
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
2002-02-23 03:33:41 +08:00
|
|
|
|
2002-10-15 04:25:52 +08:00
|
|
|
init_std_file_from_handle (1, out);
|
|
|
|
init_std_file_from_handle (2, err);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2003-12-11 14:12:41 +08:00
|
|
|
const int dtable::initial_archetype_size;
|
|
|
|
|
|
|
|
fhandler_base *
|
|
|
|
dtable::find_archetype (device& dev)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < farchetype; i++)
|
2011-05-29 02:17:09 +08:00
|
|
|
if (archetypes[i]->get_device () == (DWORD) dev)
|
2003-12-11 14:12:41 +08:00
|
|
|
return archetypes[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_base **
|
|
|
|
dtable::add_archetype ()
|
|
|
|
{
|
|
|
|
if (farchetype++ >= narchetypes)
|
2007-12-17 05:21:23 +08:00
|
|
|
archetypes = (fhandler_base **) crealloc_abort (archetypes, (narchetypes += initial_archetype_size) * sizeof archetypes[0]);
|
2003-12-11 14:12:41 +08:00
|
|
|
return archetypes + farchetype - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dtable::delete_archetype (fhandler_base *fh)
|
|
|
|
{
|
2003-12-30 09:57:16 +08:00
|
|
|
for (unsigned i = 0; i < farchetype; i++)
|
2003-12-11 14:12:41 +08:00
|
|
|
if (fh == archetypes[i])
|
|
|
|
{
|
2011-10-23 00:26:30 +08:00
|
|
|
debug_printf ("deleting element %d for %s(%d/%d)", i, fh->get_name (),
|
|
|
|
fh->dev ().get_major (), fh->dev ().get_minor ());
|
2003-12-11 14:12:41 +08:00
|
|
|
if (i < --farchetype)
|
|
|
|
archetypes[i] = archetypes[farchetype];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete fh;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
int
|
2000-08-12 12:48:44 +08:00
|
|
|
dtable::find_unused_handle (int start)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2002-06-25 05:14:04 +08:00
|
|
|
for (size_t i = start; i < size; i++)
|
2000-08-04 12:04:46 +08:00
|
|
|
/* See if open -- no need for overhead of not_open */
|
|
|
|
if (fds[i] == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
while (extend (NOFILE_INCR));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-12 12:48:44 +08:00
|
|
|
dtable::release (int fd)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (!not_open (fd))
|
|
|
|
{
|
2009-11-17 18:43:01 +08:00
|
|
|
if (fds[fd]->need_fixup_before ())
|
|
|
|
dec_need_fixup_before ();
|
2000-10-17 07:55:58 +08:00
|
|
|
delete fds[fd];
|
2000-02-18 03:38:33 +08:00
|
|
|
fds[fd] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-03 11:20:50 +08:00
|
|
|
extern "C" int
|
2001-10-03 11:49:26 +08:00
|
|
|
cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
|
|
|
|
DWORD myaccess)
|
|
|
|
{
|
|
|
|
if (fd == -1)
|
|
|
|
fd = cygheap->fdtab.find_unused_handle ();
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_base *fh = build_fh_name (name);
|
|
|
|
cygheap->fdtab[fd] = fh;
|
|
|
|
fh->init (handle, myaccess, bin ?: fh->pc_binmode ());
|
2001-10-03 11:49:26 +08:00
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
void
|
2002-10-15 04:25:52 +08:00
|
|
|
dtable::init_std_file_from_handle (int fd, HANDLE handle)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-10-03 11:49:26 +08:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO buf;
|
|
|
|
DCB dcb;
|
2002-10-18 09:28:48 +08:00
|
|
|
unsigned bin = O_BINARY;
|
2011-05-29 02:17:09 +08:00
|
|
|
device dev = {};
|
2001-10-03 11:49:26 +08:00
|
|
|
|
|
|
|
first_fd_for_open = 0;
|
2001-03-28 11:42:58 +08:00
|
|
|
|
2002-02-23 03:33:41 +08:00
|
|
|
if (!not_open (fd))
|
|
|
|
return;
|
|
|
|
|
2002-05-29 13:15:43 +08:00
|
|
|
SetLastError (0);
|
2008-03-23 05:04:16 +08:00
|
|
|
DWORD access = 0;
|
2002-05-29 13:15:43 +08:00
|
|
|
DWORD ft = GetFileType (handle);
|
2008-03-23 05:04:16 +08:00
|
|
|
char name[NT_MAX_PATH];
|
|
|
|
name[0] = '\0';
|
2008-03-23 05:27:05 +08:00
|
|
|
if (ft == FILE_TYPE_UNKNOWN && GetLastError () == ERROR_INVALID_HANDLE)
|
|
|
|
/* can't figure out what this is */;
|
|
|
|
else if (ft == FILE_TYPE_PIPE)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2009-08-10 23:38:37 +08:00
|
|
|
int rcv = 0, len = sizeof (int);
|
|
|
|
|
2008-03-23 05:27:05 +08:00
|
|
|
if (handle_to_fn (handle, name))
|
2010-04-20 00:25:11 +08:00
|
|
|
dev.parse (name);
|
2009-08-10 23:38:37 +08:00
|
|
|
else if (strcmp (name, ":sock:") == 0
|
2011-04-04 19:24:20 +08:00
|
|
|
/* NtQueryObject returns an error when called on an LSP socket
|
|
|
|
handle. While fdsock now tries to fetch the underlying
|
|
|
|
base socket, this only works on Vista and later. */
|
2009-08-10 23:38:37 +08:00
|
|
|
|| (strcmp (name, unknown_file) == 0
|
|
|
|
&& !::getsockopt ((SOCKET) handle, SOL_SOCKET, SO_RCVBUF,
|
|
|
|
(char *) &rcv, &len)))
|
|
|
|
{
|
|
|
|
/* socket */
|
|
|
|
dev = *tcp_dev;
|
|
|
|
name[0] = '\0';
|
|
|
|
}
|
2008-03-23 05:04:16 +08:00
|
|
|
else if (fd == 0)
|
|
|
|
dev = *piper_dev;
|
2001-10-02 09:58:06 +08:00
|
|
|
else
|
2008-03-23 05:04:16 +08:00
|
|
|
dev = *pipew_dev;
|
2001-10-02 09:58:06 +08:00
|
|
|
}
|
2011-05-06 06:30:53 +08:00
|
|
|
else if (GetConsoleScreenBufferInfo (handle, &buf)
|
2011-06-06 13:02:13 +08:00
|
|
|
|| GetNumberOfConsoleInputEvents (handle, (DWORD *) &buf))
|
2008-03-23 05:04:16 +08:00
|
|
|
{
|
2011-05-06 06:30:53 +08:00
|
|
|
/* Console I/O */
|
2011-06-15 05:48:43 +08:00
|
|
|
if (myself->ctty > 0)
|
2011-05-29 02:17:09 +08:00
|
|
|
dev.parse (myself->ctty);
|
2008-03-23 05:04:16 +08:00
|
|
|
else
|
2011-10-23 00:26:30 +08:00
|
|
|
{
|
|
|
|
dev.parse (FH_CONSOLE);
|
|
|
|
CloseHandle (handle);
|
|
|
|
handle = INVALID_HANDLE_VALUE;
|
|
|
|
}
|
2008-03-23 05:04:16 +08:00
|
|
|
}
|
|
|
|
else if (GetCommState (handle, &dcb))
|
2011-05-06 06:30:53 +08:00
|
|
|
/* FIXME: Not right - assumes ttyS0 */
|
|
|
|
dev.parse (DEV_SERIAL_MAJOR, 0);
|
2008-03-23 05:04:16 +08:00
|
|
|
else
|
|
|
|
/* Try to figure it out from context - probably a disk file */
|
|
|
|
handle_to_fn (handle, name);
|
2002-05-29 13:15:43 +08:00
|
|
|
|
2008-03-23 05:04:16 +08:00
|
|
|
if (!name[0] && !dev)
|
2002-05-29 13:15:43 +08:00
|
|
|
fds[fd] = NULL;
|
|
|
|
else
|
2001-10-02 09:58:06 +08:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_base *fh;
|
|
|
|
|
|
|
|
if (dev)
|
2008-03-23 05:04:16 +08:00
|
|
|
fh = build_fh_dev (dev);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
else
|
|
|
|
fh = build_fh_name (name);
|
|
|
|
|
2008-03-23 05:04:16 +08:00
|
|
|
if (name[0])
|
2002-10-18 09:28:48 +08:00
|
|
|
{
|
2007-12-17 05:21:23 +08:00
|
|
|
bin = fh->pc_binmode ();
|
|
|
|
if (!bin)
|
|
|
|
{
|
|
|
|
bin = fh->get_default_fmode (O_RDWR);
|
|
|
|
if (!bin && dev)
|
|
|
|
bin = O_BINARY;
|
|
|
|
}
|
2002-10-18 09:28:48 +08:00
|
|
|
}
|
2002-10-08 10:44:35 +08:00
|
|
|
|
2010-04-20 00:25:11 +08:00
|
|
|
IO_STATUS_BLOCK io;
|
|
|
|
FILE_ACCESS_INFORMATION fai;
|
2011-10-23 00:26:30 +08:00
|
|
|
int openflags = O_BINARY;
|
2010-04-20 00:25:11 +08:00
|
|
|
|
|
|
|
/* Console windows are not kernel objects, so the access mask returned
|
2010-04-22 02:44:39 +08:00
|
|
|
by NtQueryInformationFile is meaningless. CMD always hands down
|
|
|
|
stdin handles as R/O handles, but our tty slave sides are R/W. */
|
2011-10-23 00:26:30 +08:00
|
|
|
if (!iscons_dev (dev) && fh->is_tty ())
|
|
|
|
{
|
|
|
|
openflags |= O_RDWR;
|
|
|
|
access |= GENERIC_READ | GENERIC_WRITE;
|
|
|
|
}
|
|
|
|
else if (!iscons_dev (dev)
|
|
|
|
&& NT_SUCCESS (NtQueryInformationFile (handle, &io, &fai,
|
|
|
|
sizeof fai,
|
|
|
|
FileAccessInformation)))
|
2010-04-20 00:25:11 +08:00
|
|
|
{
|
|
|
|
if (fai.AccessFlags & FILE_WRITE_DATA)
|
2011-10-23 00:26:30 +08:00
|
|
|
{
|
|
|
|
openflags |= O_WRONLY;
|
|
|
|
access |= GENERIC_WRITE;
|
|
|
|
}
|
|
|
|
if (fai.AccessFlags & FILE_READ_DATA)
|
|
|
|
{
|
|
|
|
openflags |= openflags & O_WRONLY ? O_RDWR : O_RDONLY;
|
|
|
|
access |= GENERIC_READ;
|
|
|
|
}
|
2010-04-20 00:25:11 +08:00
|
|
|
}
|
2008-02-08 02:59:40 +08:00
|
|
|
else if (fd == 0)
|
2011-10-23 00:26:30 +08:00
|
|
|
{
|
|
|
|
openflags |= O_RDONLY;
|
|
|
|
access |= GENERIC_READ;
|
|
|
|
}
|
2008-02-16 01:53:11 +08:00
|
|
|
else
|
2011-10-23 00:26:30 +08:00
|
|
|
{
|
|
|
|
openflags |= O_WRONLY;
|
|
|
|
access |= GENERIC_WRITE; /* Should be rdwr for stderr but not sure that's
|
|
|
|
possible for some versions of handles */
|
|
|
|
}
|
|
|
|
if (!fh->init (handle, access, bin))
|
2009-07-04 02:05:51 +08:00
|
|
|
api_fatal ("couldn't initialize fd %d for %s", fd, fh->get_name ());
|
2010-04-02 23:41:27 +08:00
|
|
|
|
2011-10-23 00:26:30 +08:00
|
|
|
fh->open_setup (openflags);
|
|
|
|
fh->usecount = 0;
|
2010-04-02 23:41:27 +08:00
|
|
|
cygheap->fdtab[fd] = fh;
|
|
|
|
set_std_handle (fd);
|
2002-05-29 13:15:43 +08:00
|
|
|
paranoid_printf ("fd %d, handle %p", fd, handle);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-30 22:04:51 +08:00
|
|
|
#define cnew(name, ...) \
|
|
|
|
({ \
|
|
|
|
void* ptr = (void*) ccalloc (HEAP_FHANDLER, 1, sizeof (name)); \
|
2011-07-02 06:04:20 +08:00
|
|
|
ptr ? new (ptr) name (__VA_ARGS__) : NULL; \
|
2011-06-30 22:04:51 +08:00
|
|
|
})
|
2008-03-23 05:04:16 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
#define cnew_no_ctor(name, ...) \
|
|
|
|
({ \
|
|
|
|
void* ptr = (void*) ccalloc (HEAP_FHANDLER, 1, sizeof (name)); \
|
|
|
|
ptr ? new (ptr) name (ptr) : NULL; \
|
|
|
|
})
|
|
|
|
|
2010-01-12 18:14:59 +08:00
|
|
|
fhandler_base *
|
|
|
|
build_fh_name (const char *name, unsigned opt, suffix_info *si)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-01-12 18:14:59 +08:00
|
|
|
path_conv pc (name, opt | PC_NULLEMPTY | PC_POSIX, si);
|
2001-10-02 09:58:06 +08:00
|
|
|
if (pc.error)
|
|
|
|
{
|
2011-06-30 22:04:51 +08:00
|
|
|
fhandler_base *fh = cnew (fhandler_nodevice);
|
|
|
|
if (fh)
|
2005-08-08 12:06:07 +08:00
|
|
|
fh->set_error (pc.error);
|
|
|
|
set_errno (fh ? pc.error : EMFILE);
|
2003-11-25 10:03:17 +08:00
|
|
|
return fh;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
return build_fh_pc (pc);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_base *
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
build_fh_dev (const device& dev, const char *unix_name)
|
2002-05-24 13:44:10 +08:00
|
|
|
{
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
path_conv pc (dev);
|
|
|
|
if (unix_name)
|
2008-05-13 21:44:04 +08:00
|
|
|
pc.set_normalized_path (unix_name);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
else
|
2008-05-13 21:44:04 +08:00
|
|
|
pc.set_normalized_path (dev.name);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
return build_fh_pc (pc);
|
2002-05-24 13:44:10 +08:00
|
|
|
}
|
|
|
|
|
2005-08-08 12:06:07 +08:00
|
|
|
#define fh_unset ((fhandler_base *) 1)
|
2011-10-23 00:26:30 +08:00
|
|
|
static device last_tty_dev;
|
|
|
|
#define fh_last_tty_dev ((fhandler_termios *) cygheap->fdtab.find_archetype (last_tty_dev))
|
2011-10-16 06:37:30 +08:00
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
static fhandler_base *
|
2011-10-16 06:37:30 +08:00
|
|
|
fh_alloc (path_conv& pc)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-08-08 12:06:07 +08:00
|
|
|
fhandler_base *fh = fh_unset;
|
2011-10-16 06:37:30 +08:00
|
|
|
fhandler_base *fhraw = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
switch (pc.dev.get_major ())
|
2005-06-20 23:33:50 +08:00
|
|
|
{
|
2011-10-20 22:02:54 +08:00
|
|
|
case DEV_PTYS_MAJOR:
|
2011-10-16 06:37:30 +08:00
|
|
|
fh = cnew (fhandler_pty_slave, pc.dev.get_minor ());
|
|
|
|
break;
|
2011-10-20 22:02:54 +08:00
|
|
|
case DEV_PTYM_MAJOR:
|
2011-10-16 06:37:30 +08:00
|
|
|
fh = cnew (fhandler_pty_master, pc.dev.get_minor ());
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case DEV_CYGDRIVE_MAJOR:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_cygdrive);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case DEV_FLOPPY_MAJOR:
|
|
|
|
case DEV_CDROM_MAJOR:
|
|
|
|
case DEV_SD_MAJOR:
|
2006-11-06 21:46:24 +08:00
|
|
|
case DEV_SD1_MAJOR:
|
2006-11-23 17:55:55 +08:00
|
|
|
case DEV_SD2_MAJOR:
|
|
|
|
case DEV_SD3_MAJOR:
|
|
|
|
case DEV_SD4_MAJOR:
|
|
|
|
case DEV_SD5_MAJOR:
|
|
|
|
case DEV_SD6_MAJOR:
|
|
|
|
case DEV_SD7_MAJOR:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_floppy);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case DEV_TAPE_MAJOR:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_tape);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case DEV_SERIAL_MAJOR:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_serial);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
2011-05-29 02:17:09 +08:00
|
|
|
case DEV_CONS_MAJOR:
|
2011-10-16 06:37:30 +08:00
|
|
|
fh = cnew (fhandler_console, pc.dev);
|
2011-05-29 02:17:09 +08:00
|
|
|
break;
|
2005-06-20 23:33:50 +08:00
|
|
|
default:
|
2011-10-16 06:37:30 +08:00
|
|
|
switch ((int) pc.dev)
|
2005-06-20 23:33:50 +08:00
|
|
|
{
|
|
|
|
case FH_CONSOLE:
|
|
|
|
case FH_CONIN:
|
|
|
|
case FH_CONOUT:
|
2011-10-16 06:37:30 +08:00
|
|
|
fh = cnew (fhandler_console, pc.dev);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
2011-10-16 06:37:30 +08:00
|
|
|
case FH_PTMX:
|
|
|
|
if (pc.isopen ())
|
|
|
|
fh = cnew (fhandler_pty_master, -1);
|
|
|
|
else
|
|
|
|
fhraw = cnew_no_ctor (fhandler_pty_master, -1);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_WINDOWS:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_windows);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_FIFO:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_fifo);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_PIPE:
|
|
|
|
case FH_PIPER:
|
|
|
|
case FH_PIPEW:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_pipe);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_TCP:
|
|
|
|
case FH_UDP:
|
|
|
|
case FH_ICMP:
|
|
|
|
case FH_UNIX:
|
|
|
|
case FH_STREAM:
|
|
|
|
case FH_DGRAM:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_socket);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_FS:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_disk_file);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_NULL:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_null);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_ZERO:
|
|
|
|
case FH_FULL:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_zero);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_RANDOM:
|
|
|
|
case FH_URANDOM:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_random);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_MEM:
|
|
|
|
case FH_PORT:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_mem);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_CLIPBOARD:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_clipboard);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_OSS_DSP:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_dev_dsp);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_PROC:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_proc);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_REGISTRY:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_registry);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_PROCESS:
|
2009-01-21 01:22:11 +08:00
|
|
|
case FH_PROCESSFD:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_process);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
2007-01-18 03:26:58 +08:00
|
|
|
case FH_PROCNET:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_procnet);
|
2007-01-18 03:26:58 +08:00
|
|
|
break;
|
2010-09-06 17:47:01 +08:00
|
|
|
case FH_PROCSYS:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_procsys);
|
2010-09-06 17:47:01 +08:00
|
|
|
break;
|
2011-04-02 03:48:19 +08:00
|
|
|
case FH_PROCSYSVIPC:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_procsysvipc);
|
2011-04-02 03:48:19 +08:00
|
|
|
break;
|
2005-06-20 23:33:50 +08:00
|
|
|
case FH_NETDRIVE:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_netdrive);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
|
|
|
case FH_TTY:
|
2011-10-16 06:37:30 +08:00
|
|
|
if (!pc.isopen ())
|
2011-10-20 22:02:54 +08:00
|
|
|
{
|
2011-10-23 00:26:30 +08:00
|
|
|
fhraw = cnew_no_ctor (fhandler_console, -1);
|
|
|
|
debug_printf ("not called from open for /dev/tty");
|
|
|
|
}
|
|
|
|
else if (myself->ctty <= 0 && last_tty_dev
|
|
|
|
&& !myself->set_ctty (fh_last_tty_dev, 0))
|
|
|
|
debug_printf ("no /dev/tty assigned");
|
|
|
|
else if (myself->ctty > 0)
|
|
|
|
{
|
|
|
|
debug_printf ("determining /dev/tty assignment for ctty %p", myself->ctty);
|
2011-10-20 22:02:54 +08:00
|
|
|
if (iscons_dev (myself->ctty))
|
|
|
|
fh = cnew (fhandler_console, pc.dev);
|
|
|
|
else
|
|
|
|
fh = cnew (fhandler_pty_slave, myself->ctty);
|
2011-10-23 00:26:30 +08:00
|
|
|
if (fh->dev () != FH_NADA)
|
|
|
|
fh->set_name ("/dev/tty");
|
2011-10-20 22:02:54 +08:00
|
|
|
}
|
2011-10-16 06:37:30 +08:00
|
|
|
break;
|
2005-06-20 23:33:50 +08:00
|
|
|
case FH_KMSG:
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_mailslot);
|
2005-06-20 23:33:50 +08:00
|
|
|
break;
|
2003-10-01 20:36:39 +08:00
|
|
|
}
|
2005-06-20 23:33:50 +08:00
|
|
|
}
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
/* 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;
|
|
|
|
}
|
2005-08-08 21:53:05 +08:00
|
|
|
if (fh == fh_unset)
|
2011-06-30 22:04:51 +08:00
|
|
|
fh = cnew (fhandler_nodevice);
|
2011-10-16 06:37:30 +08:00
|
|
|
else if (fh->dev () == FH_ERROR)
|
|
|
|
{
|
|
|
|
delete fh;
|
|
|
|
fh = NULL;
|
|
|
|
}
|
2011-05-06 06:30:53 +08:00
|
|
|
return fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_base *
|
2011-10-23 00:26:30 +08:00
|
|
|
build_fh_pc (path_conv& pc)
|
2011-05-06 06:30:53 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
fhandler_base *fh = fh_alloc (pc);
|
2005-08-08 21:53:05 +08:00
|
|
|
|
2009-08-20 16:34:21 +08:00
|
|
|
if (!fh)
|
2011-06-30 17:37:36 +08:00
|
|
|
{
|
2011-10-16 06:37:30 +08:00
|
|
|
set_errno (ENXIO);
|
2011-06-30 17:37:36 +08:00
|
|
|
goto out;
|
|
|
|
}
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
|
2011-05-06 06:30:53 +08:00
|
|
|
if (!fh->use_archetype ())
|
2011-10-23 00:26:30 +08:00
|
|
|
fh->set_name (pc);
|
2011-05-06 06:30:53 +08:00
|
|
|
else if ((fh->archetype = cygheap->fdtab.find_archetype (fh->dev ())))
|
2011-10-23 00:26:30 +08:00
|
|
|
{
|
|
|
|
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 ());
|
|
|
|
if (!fh->get_name ())
|
|
|
|
fh->set_name (fh->archetype->dev ().name);
|
|
|
|
}
|
|
|
|
else if (cygwin_finished_initializing && !pc.isopen ())
|
|
|
|
fh->set_name (pc);
|
2011-05-06 06:30:53 +08:00
|
|
|
else
|
|
|
|
{
|
2011-10-23 00:26:30 +08:00
|
|
|
if (!fh->get_name ())
|
|
|
|
fh->set_name (fh->dev ().name);
|
2011-10-16 06:37:30 +08:00
|
|
|
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 ());
|
2011-05-06 06:30:53 +08:00
|
|
|
fh->archetype->archetype = NULL;
|
|
|
|
*cygheap->fdtab.add_archetype () = fh->archetype;
|
|
|
|
}
|
|
|
|
|
2011-10-23 00:26:30 +08:00
|
|
|
|
|
|
|
/* Keep track of the last tty-like thing opened. We could potentially want
|
|
|
|
to open it if /dev/tty is referenced. */
|
2011-10-16 06:37:30 +08:00
|
|
|
if (myself->ctty > 0 || !fh->is_tty () || !pc.isctty_capable ())
|
2011-10-23 00:26:30 +08:00
|
|
|
last_tty_dev = FH_NADA;
|
|
|
|
else
|
|
|
|
last_tty_dev = fh->dev ();
|
2011-10-16 06:37:30 +08:00
|
|
|
|
2011-06-13 04:15:26 +08:00
|
|
|
out:
|
2011-10-23 00:26:30 +08:00
|
|
|
debug_printf ("fh %p, dev %p", fh, fh ? (DWORD) fh->dev () : 0);
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
return fh;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fhandler_base *
|
2010-01-15 02:46:02 +08:00
|
|
|
dtable::dup_worker (fhandler_base *oldfh, int flags)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2009-08-20 16:34:21 +08:00
|
|
|
/* 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. */
|
2011-10-16 06:37:30 +08:00
|
|
|
fhandler_base *newfh = oldfh->clone ();
|
2005-08-08 12:06:07 +08:00
|
|
|
if (!newfh)
|
|
|
|
debug_printf ("build_fh_pc failed");
|
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2011-05-06 06:30:53 +08:00
|
|
|
if (!oldfh->archetype)
|
|
|
|
newfh->set_io_handle (NULL);
|
2011-10-16 06:37:30 +08:00
|
|
|
|
2010-06-15 20:05:15 +08:00
|
|
|
newfh->pc.reset_conv_handle ();
|
2011-10-16 06:37:30 +08:00
|
|
|
if (oldfh->dup (newfh, flags))
|
2005-08-08 12:06:07 +08:00
|
|
|
{
|
2009-08-20 16:34:21 +08:00
|
|
|
delete newfh;
|
|
|
|
newfh = NULL;
|
2005-08-08 12:06:07 +08:00
|
|
|
debug_printf ("oldfh->dup failed");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-05-06 06:30:53 +08:00
|
|
|
newfh->usecount = 0;
|
|
|
|
newfh->archetype_usecount (1);
|
2010-01-15 02:46:02 +08:00
|
|
|
/* The O_CLOEXEC flag enforces close-on-exec behaviour. */
|
2011-05-06 06:30:53 +08:00
|
|
|
newfh->set_close_on_exec (!!(flags & O_CLOEXEC));
|
2005-08-08 12:06:07 +08:00
|
|
|
debug_printf ("duped '%s' old %p, new %p", oldfh->get_name (), oldfh->get_io_handle (), newfh->get_io_handle ());
|
2011-10-16 06:37:30 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
debug_printf ("duped output_handles old %p, new %p",
|
|
|
|
oldfh->get_output_handle (),
|
|
|
|
newfh->get_output_handle ());
|
2011-10-23 00:26:30 +08:00
|
|
|
if (oldfh->archetype)
|
|
|
|
debug_printf ("duped output_handles archetype old %p, archetype new %p",
|
|
|
|
oldfh->archetype->get_output_handle (),
|
|
|
|
newfh->archetype->get_output_handle ());
|
2011-10-16 06:37:30 +08:00
|
|
|
#endif /*DEBUGGING*/
|
2005-08-08 12:06:07 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
return newfh;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2010-01-15 02:46:02 +08:00
|
|
|
dtable::dup3 (int oldfd, int newfd, int flags)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int res = -1;
|
|
|
|
fhandler_base *newfh = NULL; // = NULL to avoid an incorrect warning
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
2010-01-15 02:46:02 +08:00
|
|
|
debug_printf ("dup3 (%d, %d, %p)", oldfd, newfd, flags);
|
2004-01-14 23:45:37 +08:00
|
|
|
lock ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (not_open (oldfd))
|
|
|
|
{
|
2000-06-26 23:27:12 +08:00
|
|
|
syscall_printf ("fd %d not open", oldfd);
|
2000-02-18 03:38:33 +08:00
|
|
|
set_errno (EBADF);
|
|
|
|
goto done;
|
|
|
|
}
|
2002-06-25 04:05:52 +08:00
|
|
|
if (newfd < 0)
|
|
|
|
{
|
|
|
|
syscall_printf ("new fd out of bounds: %d", newfd);
|
|
|
|
set_errno (EBADF);
|
|
|
|
goto done;
|
|
|
|
}
|
2010-01-15 02:46:02 +08:00
|
|
|
if ((flags & ~O_CLOEXEC) != 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-01-15 02:46:02 +08:00
|
|
|
syscall_printf ("invalid flags value %x", flags);
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2011-10-16 06:37:30 +08:00
|
|
|
/* 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;
|
|
|
|
|
2010-01-15 02:46:02 +08:00
|
|
|
if ((newfh = dup_worker (fds[oldfd], flags)) == NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
res = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2009-08-05 12:44:27 +08:00
|
|
|
debug_printf ("newfh->io_handle %p, oldfh->io_handle %p, new win32_name %p, old win32_name %p",
|
|
|
|
newfh->get_io_handle (), fds[oldfd]->get_io_handle (), newfh->get_win32_name (), fds[oldfd]->get_win32_name ());
|
2000-09-03 12:16:35 +08:00
|
|
|
|
2002-06-25 04:05:52 +08:00
|
|
|
if (!not_open (newfd))
|
2002-10-21 09:00:58 +08:00
|
|
|
close (newfd);
|
2002-06-25 04:05:52 +08:00
|
|
|
else if ((size_t) newfd < size)
|
|
|
|
/* nothing to do */;
|
|
|
|
else if (find_unused_handle (newfd) < 0)
|
2000-06-26 23:27:12 +08:00
|
|
|
{
|
2002-06-25 04:05:52 +08:00
|
|
|
newfh->close ();
|
|
|
|
res = -1;
|
2000-06-26 23:27:12 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2000-09-03 12:16:35 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
fds[newfd] = newfh;
|
2000-10-26 18:13:41 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if ((res = newfd) <= 2)
|
|
|
|
set_std_handle (res);
|
|
|
|
|
|
|
|
done:
|
2002-06-25 04:05:52 +08:00
|
|
|
MALLOC_CHECK;
|
2004-01-14 23:45:37 +08:00
|
|
|
unlock ();
|
2011-12-04 05:43:27 +08:00
|
|
|
syscall_printf ("%R = dup3(%d, %d, %p)", res, oldfd, newfd, flags);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
bool
|
|
|
|
dtable::select_read (int fd, select_stuff *ss)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
if (not_open (fd))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
2009-07-01 05:18:44 +08:00
|
|
|
return false;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-09-03 12:16:35 +08:00
|
|
|
fhandler_base *fh = fds[fd];
|
2009-07-01 05:18:44 +08:00
|
|
|
select_record *s = fh->select_read (ss);
|
2000-02-18 03:38:33 +08:00
|
|
|
s->fd = fd;
|
2009-02-27 08:34:40 +08:00
|
|
|
if (!s->fh)
|
|
|
|
s->fh = fh;
|
2005-01-13 06:40:46 +08:00
|
|
|
s->thread_errno = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("%s fd %d", fh->get_name (), fd);
|
2009-07-01 05:18:44 +08:00
|
|
|
return true;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
bool
|
|
|
|
dtable::select_write (int fd, select_stuff *ss)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
if (not_open (fd))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-09-03 12:16:35 +08:00
|
|
|
fhandler_base *fh = fds[fd];
|
2009-07-01 05:18:44 +08:00
|
|
|
select_record *s = fh->select_write (ss);
|
2000-02-18 03:38:33 +08:00
|
|
|
s->fd = fd;
|
|
|
|
s->fh = fh;
|
2005-01-13 06:40:46 +08:00
|
|
|
s->thread_errno = 0;
|
2011-05-31 08:26:37 +08:00
|
|
|
debug_printf ("%s fd %d", fh->get_name (), fd);
|
2009-07-01 05:18:44 +08:00
|
|
|
return true;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-01 05:18:44 +08:00
|
|
|
bool
|
|
|
|
dtable::select_except (int fd, select_stuff *ss)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
if (not_open (fd))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
set_errno (EBADF);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-09-03 12:16:35 +08:00
|
|
|
fhandler_base *fh = fds[fd];
|
2009-07-01 05:18:44 +08:00
|
|
|
select_record *s = fh->select_except (ss);
|
2000-02-18 03:38:33 +08:00
|
|
|
s->fd = fd;
|
|
|
|
s->fh = fh;
|
2005-01-13 06:40:46 +08:00
|
|
|
s->thread_errno = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
debug_printf ("%s fd %d", fh->get_name (), fd);
|
2009-07-01 05:18:44 +08:00
|
|
|
return true;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2006-12-12 02:55:29 +08:00
|
|
|
void
|
|
|
|
dtable::move_fd (int from, int to)
|
|
|
|
{
|
|
|
|
// close (to); /* It is assumed that this is close-on-exec */
|
|
|
|
fds[to] = fds[from];
|
|
|
|
fds[from] = NULL;
|
|
|
|
}
|
|
|
|
|
2002-10-18 01:45:09 +08:00
|
|
|
void
|
|
|
|
dtable::set_file_pointers_for_exec ()
|
|
|
|
{
|
2007-12-14 19:32:40 +08:00
|
|
|
/* This is not POSIX-compliant so the function is only called for
|
|
|
|
non-Cygwin processes. */
|
2007-05-30 01:25:36 +08:00
|
|
|
LONG off_high = 0;
|
2004-01-14 23:45:37 +08:00
|
|
|
lock ();
|
2002-10-18 01:45:09 +08:00
|
|
|
fhandler_base *fh;
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
if ((fh = fds[i]) != NULL && fh->get_flags () & O_APPEND)
|
2007-05-30 01:25:36 +08:00
|
|
|
SetFilePointer (fh->get_handle (), 0, &off_high, FILE_END);
|
2004-01-14 23:45:37 +08:00
|
|
|
unlock ();
|
2002-10-18 01:45:09 +08:00
|
|
|
}
|
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
void
|
2004-02-03 05:00:07 +08:00
|
|
|
dtable::fixup_after_exec ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
first_fd_for_open = 0;
|
2000-10-25 22:17:27 +08:00
|
|
|
fhandler_base *fh;
|
2000-09-03 12:16:35 +08:00
|
|
|
for (size_t i = 0; i < size; i++)
|
2000-10-25 22:17:27 +08:00
|
|
|
if ((fh = fds[i]) != NULL)
|
2000-09-11 00:43:47 +08:00
|
|
|
{
|
2000-10-25 22:17:27 +08:00
|
|
|
fh->clear_readahead ();
|
2005-11-14 12:28:45 +08:00
|
|
|
fh->fixup_after_exec ();
|
2004-04-10 21:45:10 +08:00
|
|
|
if (fh->close_on_exec ())
|
2003-12-30 09:57:16 +08:00
|
|
|
{
|
|
|
|
if (fh->archetype)
|
2006-06-03 14:35:10 +08:00
|
|
|
{
|
|
|
|
debug_printf ("closing fd %d since it is an archetype", i);
|
2011-05-06 06:30:53 +08:00
|
|
|
fh->close_with_arch ();
|
2006-06-03 14:35:10 +08:00
|
|
|
}
|
2003-12-30 09:57:16 +08:00
|
|
|
release (i);
|
|
|
|
}
|
2009-08-18 23:21:47 +08:00
|
|
|
else if (fh->get_popen_pid ())
|
|
|
|
close (i);
|
2005-11-14 12:28:45 +08:00
|
|
|
else if (i == 0)
|
|
|
|
SetStdHandle (std_consts[i], fh->get_io_handle ());
|
|
|
|
else if (i <= 2)
|
|
|
|
SetStdHandle (std_consts[i], fh->get_output_handle ());
|
2000-09-11 00:43:47 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-08-12 12:48:44 +08:00
|
|
|
dtable::fixup_after_fork (HANDLE parent)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
fhandler_base *fh;
|
2000-02-18 03:38:33 +08:00
|
|
|
for (size_t i = 0; i < size; i++)
|
2000-09-03 12:16:35 +08:00
|
|
|
if ((fh = fds[i]) != NULL)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-04-10 21:45:10 +08:00
|
|
|
if (fh->close_on_exec () || fh->need_fork_fixup ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2001-09-05 04:48:45 +08:00
|
|
|
debug_printf ("fd %d (%s)", i, fh->get_name ());
|
2000-02-18 03:38:33 +08:00
|
|
|
fh->fixup_after_fork (parent);
|
|
|
|
}
|
2001-09-10 10:11:59 +08:00
|
|
|
if (i == 0)
|
|
|
|
SetStdHandle (std_consts[i], fh->get_io_handle ());
|
|
|
|
else if (i <= 2)
|
|
|
|
SetStdHandle (std_consts[i], fh->get_output_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-23 05:27:05 +08:00
|
|
|
static void
|
|
|
|
decode_tty (char *buf, WCHAR *w32)
|
2008-03-23 05:04:16 +08:00
|
|
|
{
|
|
|
|
int ttyn = wcstol (w32, NULL, 10);
|
2011-11-08 14:26:15 +08:00
|
|
|
__ptsname (buf, ttyn);
|
2008-03-23 05:04:16 +08:00
|
|
|
}
|
|
|
|
|
2008-03-23 05:27:05 +08:00
|
|
|
/* Try to derive posix filename from given handle. Return true if
|
|
|
|
the handle is associated with a cygwin tty. */
|
|
|
|
static bool
|
2002-05-28 09:55:40 +08:00
|
|
|
handle_to_fn (HANDLE h, char *posix_fn)
|
|
|
|
{
|
2008-03-11 21:17:52 +08:00
|
|
|
tmp_pathbuf tp;
|
2008-03-23 05:04:16 +08:00
|
|
|
ULONG len = 0;
|
|
|
|
WCHAR *maxmatchdos = NULL;
|
|
|
|
int maxmatchlen = 0;
|
2009-08-10 23:38:37 +08:00
|
|
|
OBJECT_NAME_INFORMATION *ntfn = (OBJECT_NAME_INFORMATION *) tp.w_get ();
|
|
|
|
|
|
|
|
NTSTATUS status = NtQueryObject (h, ObjectNameInformation, ntfn, 65536, &len);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
debug_printf ("NtQueryObject failed, %p", status);
|
|
|
|
// NT seems to do this on an unopened file
|
|
|
|
else if (!ntfn->Name.Buffer)
|
|
|
|
debug_printf ("nt->Name.Buffer == NULL");
|
2008-09-11 12:34:24 +08:00
|
|
|
else
|
2008-03-23 05:04:16 +08:00
|
|
|
{
|
2009-08-10 23:38:37 +08:00
|
|
|
WCHAR *w32 = ntfn->Name.Buffer;
|
|
|
|
size_t w32len = ntfn->Name.Length / sizeof (WCHAR);
|
|
|
|
w32[w32len] = L'\0';
|
2002-06-05 23:43:49 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
if (wcscasecmp (w32, DEV_NULL) == 0)
|
|
|
|
{
|
|
|
|
strcpy (posix_fn, "/dev/null");
|
|
|
|
return false;
|
|
|
|
}
|
2002-06-05 23:43:49 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
if (wcscasecmp (w32, DEV_SOCKET) == 0)
|
|
|
|
{
|
|
|
|
strcpy (posix_fn, ":sock:");
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-28 09:55:40 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
if (wcsncasecmp (w32, DEV_NAMED_PIPE, DEV_NAMED_PIPE_LEN) == 0)
|
|
|
|
{
|
|
|
|
w32 += DEV_NAMED_PIPE_LEN;
|
|
|
|
if (wcsncmp (w32, L"cygwin-", WCLEN (L"cygwin-")) != 0)
|
|
|
|
return false;
|
|
|
|
w32 += WCLEN (L"cygwin-");
|
2009-10-31 21:24:06 +08:00
|
|
|
/* Check for installation key and trailing dash. */
|
|
|
|
w32len = installation_key.Length / sizeof (WCHAR);
|
|
|
|
if (w32len && wcsncmp (w32, installation_key.Buffer, w32len) != 0)
|
|
|
|
return false;
|
|
|
|
w32 += w32len;
|
|
|
|
if (*w32 != L'-')
|
|
|
|
return false;
|
|
|
|
++w32;
|
2011-06-17 16:27:32 +08:00
|
|
|
bool istty = wcsncmp (w32, L"pty", WCLEN (L"pty")) == 0;
|
2009-08-10 23:38:37 +08:00
|
|
|
if (istty)
|
2011-06-17 16:27:32 +08:00
|
|
|
decode_tty (posix_fn, w32 + WCLEN (L"pty"));
|
2009-08-10 23:38:37 +08:00
|
|
|
else if (wcsncmp (w32, L"pipe", WCLEN (L"pipe")) == 0)
|
|
|
|
strcpy (posix_fn, "/dev/pipe");
|
|
|
|
return istty;
|
|
|
|
}
|
2002-09-19 11:30:20 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
WCHAR fnbuf[64 * 1024];
|
|
|
|
if (wcsncasecmp (w32, DEVICE_PREFIX, DEVICE_PREFIX_LEN) != 0
|
|
|
|
|| !QueryDosDeviceW (NULL, fnbuf, sizeof (fnbuf)))
|
|
|
|
{
|
|
|
|
sys_wcstombs (posix_fn, NT_MAX_PATH, w32, w32len);
|
|
|
|
return false;
|
|
|
|
}
|
2002-05-28 09:55:40 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
for (WCHAR *s = fnbuf; *s; s = wcschr (s, '\0') + 1)
|
|
|
|
{
|
|
|
|
WCHAR device[NT_MAX_PATH];
|
|
|
|
if (!QueryDosDeviceW (s, device, sizeof (device)))
|
|
|
|
continue;
|
|
|
|
if (wcschr (s, ':') == NULL)
|
|
|
|
continue;
|
|
|
|
WCHAR *q = wcsrchr (device, ';');
|
|
|
|
if (q)
|
2008-09-11 12:34:24 +08:00
|
|
|
{
|
2009-08-10 23:38:37 +08:00
|
|
|
WCHAR *r = wcschr (q, '\\');
|
|
|
|
if (r)
|
|
|
|
wcscpy (q, r + 1);
|
2008-09-11 12:34:24 +08:00
|
|
|
}
|
2009-08-10 23:38:37 +08:00
|
|
|
int devlen = wcslen (device);
|
|
|
|
if (device[devlen - 1] == L'\\')
|
|
|
|
device[--devlen] = L'\0';
|
|
|
|
if (devlen < maxmatchlen)
|
|
|
|
continue;
|
|
|
|
if (wcsncmp (device, w32, devlen) != 0||
|
|
|
|
(w32[devlen] != L'\0' && w32[devlen] != L'\\'))
|
|
|
|
continue;
|
|
|
|
maxmatchlen = devlen;
|
|
|
|
maxmatchdos = s;
|
|
|
|
debug_printf ("current match '%W' = '%W'\n", s, device);
|
|
|
|
}
|
2008-03-23 05:04:16 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
if (maxmatchlen)
|
|
|
|
{
|
|
|
|
WCHAR *p = wcschr (w32 + DEVICE_PREFIX_LEN, L'\\');
|
|
|
|
size_t n = wcslen (maxmatchdos);
|
|
|
|
WCHAR ch;
|
|
|
|
if (!p)
|
|
|
|
ch = L'\0';
|
|
|
|
else
|
2008-09-11 12:34:24 +08:00
|
|
|
{
|
2009-08-10 23:38:37 +08:00
|
|
|
if (maxmatchdos[n - 1] == L'\\')
|
|
|
|
n--;
|
|
|
|
w32 += maxmatchlen - n;
|
|
|
|
ch = L'\\';
|
2008-09-11 12:34:24 +08:00
|
|
|
}
|
2009-08-10 23:38:37 +08:00
|
|
|
memcpy (w32, maxmatchdos, n * sizeof (WCHAR));
|
|
|
|
w32[n] = ch;
|
|
|
|
}
|
|
|
|
else if (wcsncmp (w32, DEV_REMOTE, DEV_REMOTE_LEN) == 0)
|
|
|
|
{
|
|
|
|
w32 += DEV_REMOTE_LEN - 2;
|
|
|
|
*w32 = L'\\';
|
|
|
|
debug_printf ("remote drive");
|
|
|
|
}
|
|
|
|
else if (wcsncmp (w32, DEV_REMOTE1, DEV_REMOTE1_LEN) == 0)
|
|
|
|
{
|
|
|
|
w32 += DEV_REMOTE1_LEN - 2;
|
|
|
|
*w32 = L'\\';
|
|
|
|
debug_printf ("remote drive");
|
|
|
|
}
|
2008-03-23 05:04:16 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
cygwin_conv_path (CCP_WIN_W_TO_POSIX | CCP_ABSOLUTE, w32, posix_fn,
|
|
|
|
NT_MAX_PATH);
|
2002-06-03 01:48:05 +08:00
|
|
|
|
2009-08-10 23:38:37 +08:00
|
|
|
debug_printf ("derived path '%W', posix '%s'", w32, posix_fn);
|
|
|
|
return false;
|
2007-12-17 05:21:23 +08:00
|
|
|
}
|
2002-05-28 09:55:40 +08:00
|
|
|
|
2008-03-23 05:04:16 +08:00
|
|
|
strcpy (posix_fn, unknown_file);
|
2008-03-23 05:27:05 +08:00
|
|
|
return false;
|
2002-05-28 09:55:40 +08:00
|
|
|
}
|
2009-11-17 18:43:01 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
dtable::fixup_before_fork (DWORD target_proc_id)
|
|
|
|
{
|
|
|
|
lock ();
|
|
|
|
fhandler_base *fh;
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
if ((fh = fds[i]) != NULL)
|
|
|
|
{
|
2011-06-06 13:02:13 +08:00
|
|
|
debug_printf ("fd %d (%s)", i, fh->get_name ());
|
|
|
|
fh->fixup_before_fork_exec (target_proc_id);
|
2009-11-17 18:43:01 +08:00
|
|
|
}
|
|
|
|
unlock ();
|
2011-06-06 13:02:13 +08:00
|
|
|
}
|
|
|
|
|
2009-11-17 18:43:01 +08:00
|
|
|
void
|
|
|
|
dtable::fixup_before_exec (DWORD target_proc_id)
|
|
|
|
{
|
|
|
|
lock ();
|
|
|
|
fhandler_base *fh;
|
|
|
|
for (size_t i = 0; i < size; i++)
|
|
|
|
if ((fh = fds[i]) != NULL && !fh->close_on_exec ())
|
|
|
|
{
|
2011-06-06 13:02:13 +08:00
|
|
|
debug_printf ("fd %d (%s)", i, fh->get_name ());
|
|
|
|
fh->fixup_before_fork_exec (target_proc_id);
|
2009-11-17 18:43:01 +08:00
|
|
|
}
|
|
|
|
unlock ();
|
2011-06-06 13:02:13 +08:00
|
|
|
}
|