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