2000-02-18 03:38:33 +08:00
|
|
|
/* pinfo.cc: process table support
|
|
|
|
|
2005-01-07 00:36:40 +08:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005
|
|
|
|
Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <limits.h>
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include <stdarg.h>
|
2005-01-13 06:40:46 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "cygwin_version.h"
|
|
|
|
#include "perprocess.h"
|
|
|
|
#include "environ.h"
|
2000-10-15 09:37:07 +08:00
|
|
|
#include <assert.h>
|
2004-11-26 12:15:10 +08:00
|
|
|
#include <sys/wait.h>
|
2000-11-02 13:25:56 +08:00
|
|
|
#include <ntdef.h>
|
|
|
|
#include "ntdll.h"
|
2002-10-15 15:03:45 +08:00
|
|
|
#include "shared_info.h"
|
2003-09-16 11:39:55 +08:00
|
|
|
#include "cygheap.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2004-02-12 11:01:58 +08:00
|
|
|
#include "cygmalloc.h"
|
2004-02-14 03:34:32 +08:00
|
|
|
#include "cygtls.h"
|
2004-12-03 12:46:00 +08:00
|
|
|
#include "child_info.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-06-09 11:54:07 +08:00
|
|
|
static char NO_COPY pinfo_dummy[sizeof (_pinfo)] = {0};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
pinfo NO_COPY myself ((_pinfo *)&pinfo_dummy); // Avoid myself != NULL checks
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-01-11 23:31:04 +08:00
|
|
|
bool is_toplevel_proc;
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Initialize the process table.
|
|
|
|
This is done once when the dll is first loaded. */
|
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
void __stdcall
|
2004-09-12 11:47:57 +08:00
|
|
|
set_myself (HANDLE h)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-09-12 11:47:57 +08:00
|
|
|
if (!h)
|
|
|
|
cygheap->pid = cygwin_pid (GetCurrentProcessId ());
|
2005-01-26 08:15:11 +08:00
|
|
|
myself.init (cygheap->pid, PID_IN_USE, h ?: INVALID_HANDLE_VALUE);
|
2000-07-30 00:24:59 +08:00
|
|
|
myself->process_state |= PID_IN_USE;
|
2004-12-06 03:41:26 +08:00
|
|
|
myself->dwProcessId = GetCurrentProcessId ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-07-07 04:05:03 +08:00
|
|
|
GetModuleFileName (NULL, myself->progname, sizeof (myself->progname));
|
2005-09-23 05:10:07 +08:00
|
|
|
#ifndef DEBUGGING
|
2002-06-19 23:27:27 +08:00
|
|
|
if (!strace.active)
|
2005-09-23 05:10:07 +08:00
|
|
|
#endif
|
2002-06-19 23:27:27 +08:00
|
|
|
strace.hello ();
|
2004-09-12 11:47:57 +08:00
|
|
|
debug_printf ("myself->dwProcessId %u", myself->dwProcessId);
|
2004-11-26 12:15:10 +08:00
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
/* here if execed */
|
|
|
|
static pinfo NO_COPY myself_identity;
|
2005-01-26 08:15:11 +08:00
|
|
|
myself_identity.init (cygwin_pid (myself->dwProcessId), PID_EXECED, NULL);
|
2004-12-06 03:41:26 +08:00
|
|
|
myself->start_time = time (NULL); /* Register our starting time. */
|
|
|
|
myself->exec_sendsig = NULL;
|
|
|
|
myself->exec_dwProcessId = 0;
|
2004-11-26 12:15:10 +08:00
|
|
|
}
|
2004-12-06 03:41:26 +08:00
|
|
|
else if (!myself->wr_proc_pipe)
|
|
|
|
myself->start_time = time (NULL); /* Register our starting time. */
|
2004-12-25 02:31:23 +08:00
|
|
|
else if (cygheap->pid_handle)
|
2004-11-26 12:15:10 +08:00
|
|
|
{
|
2004-12-25 02:31:23 +08:00
|
|
|
ForceCloseHandle (cygheap->pid_handle);
|
|
|
|
cygheap->pid_handle = NULL;
|
2004-11-26 12:15:10 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the process table entry for the current task.
|
2002-01-29 10:02:03 +08:00
|
|
|
This is not called for forked tasks, only execed ones. */
|
2000-02-18 03:38:33 +08:00
|
|
|
void __stdcall
|
2000-10-17 07:55:58 +08:00
|
|
|
pinfo_init (char **envp, int envc)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-09-03 12:16:35 +08:00
|
|
|
if (envp)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-17 07:55:58 +08:00
|
|
|
environ_init (envp, envc);
|
2000-02-18 03:38:33 +08:00
|
|
|
/* spawn has already set up a pid structure for us so we'll use that */
|
|
|
|
myself->process_state |= PID_CYGPARENT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Invent our own pid. */
|
|
|
|
|
2004-09-12 11:47:57 +08:00
|
|
|
set_myself (NULL);
|
2000-07-30 00:24:59 +08:00
|
|
|
myself->ppid = 1;
|
|
|
|
myself->pgid = myself->sid = myself->pid;
|
2000-02-18 03:38:33 +08:00
|
|
|
myself->ctty = -1;
|
* (child_info.h, cygheap.h, dcrt0.cc, dir.cc, fhandler.cc, fhandler.h,
fhandler_clipboard.cc, fhandler_disk_file.cc, fhandler_dsp.cc,
fhandler_floppy.cc, fhandler_mem.cc, fhandler_random.cc,
fhandler_tape.cc, fhandler_zero.cc, grp.cc, mmap.cc, passwd.cc,
pinfo.cc, pinfo.h, pipe.cc, sec_acl.cc, sec_helper.cc, security.cc,
security.h, spawn.cc, syscalls.cc, thread.h, uinfo.cc, winsup.h):
Change usage of uid_t to __uid16_t, gid_t to __gid16_t and
off_t to __off32_t throughout. Use INVALID_UID, INVALID_GID and
INVALID_SEEK instead casting -1 to the appropriate type.
* winsup.h: Define INVALID_UID, INVALID_GID and INVALID_SEEK.
* include/cygwin/acl.h: Define internal __aclent16_t and __aclent32_t
types. Don't declare acl functions when compiling Cygwin.
* include/cygwin/grp.h: Declare getgrgid() and getgrnam() with
correct types for internal usage.
2002-02-10 21:38:51 +08:00
|
|
|
myself->uid = ILLEGAL_UID;
|
2003-09-14 01:14:15 +08:00
|
|
|
myself->gid = UNKNOWN_GID;
|
2000-10-17 07:55:58 +08:00
|
|
|
environ_init (NULL, 0); /* call after myself has been set up */
|
2005-01-26 06:45:11 +08:00
|
|
|
myself->nice = winprio_to_nice (GetPriorityClass (hMainProc));
|
|
|
|
debug_printf ("Set nice to %d", myself->nice);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
debug_printf ("pid %d, pgid %d", myself->pid, myself->pgid);
|
|
|
|
}
|
|
|
|
|
2005-01-11 23:31:04 +08:00
|
|
|
# define self (*this)
|
2000-10-15 09:37:07 +08:00
|
|
|
void
|
2005-01-17 12:12:08 +08:00
|
|
|
pinfo::maybe_set_exit_code_from_windows ()
|
2005-01-11 23:31:04 +08:00
|
|
|
{
|
|
|
|
DWORD x = 0xdeadbeef;
|
|
|
|
DWORD oexitcode = self->exitcode;
|
2005-09-20 10:06:57 +08:00
|
|
|
extern int sigExeced;
|
|
|
|
|
2005-01-17 01:00:27 +08:00
|
|
|
if (hProcess && !(self->exitcode & EXITCODE_SET))
|
2005-01-11 23:31:04 +08:00
|
|
|
{
|
2005-01-23 02:07:10 +08:00
|
|
|
WaitForSingleObject (hProcess, INFINITE); // just to be safe, in case
|
2005-05-02 11:50:11 +08:00
|
|
|
// process hasn't quite exited
|
2005-01-23 02:07:10 +08:00
|
|
|
// after closing pipe
|
2005-01-11 23:31:04 +08:00
|
|
|
GetExitCodeProcess (hProcess, &x);
|
2005-09-20 10:06:57 +08:00
|
|
|
self->exitcode = EXITCODE_SET | (sigExeced ?: (x & 0xff) << 8);
|
2005-01-11 23:31:04 +08:00
|
|
|
}
|
2005-01-23 05:17:53 +08:00
|
|
|
sigproc_printf ("pid %d, exit value - old %p, windows %p, cygwin %p",
|
|
|
|
self->pid, oexitcode, x, self->exitcode);
|
2005-01-11 23:31:04 +08:00
|
|
|
}
|
|
|
|
|
2005-02-11 23:24:15 +08:00
|
|
|
void
|
|
|
|
pinfo::zap_cwd ()
|
|
|
|
{
|
|
|
|
extern char windows_system_directory[];
|
|
|
|
/* Move to an innocuous location to avoid a race with other processes
|
|
|
|
that may want to manipulate the current directory before this
|
|
|
|
process has completely exited. */
|
2005-07-07 04:05:03 +08:00
|
|
|
SetCurrentDirectory (windows_system_directory);
|
2005-02-11 23:24:15 +08:00
|
|
|
}
|
|
|
|
|
2005-01-11 23:31:04 +08:00
|
|
|
void
|
|
|
|
pinfo::exit (DWORD n)
|
2000-10-15 09:37:07 +08:00
|
|
|
{
|
2005-10-18 07:27:00 +08:00
|
|
|
lock_process until_exit ();
|
2004-02-14 03:34:32 +08:00
|
|
|
cygthread::terminate ();
|
2005-10-18 07:27:00 +08:00
|
|
|
|
2005-01-17 01:00:27 +08:00
|
|
|
if (n != EXITCODE_NOSET)
|
2005-09-14 01:08:54 +08:00
|
|
|
self->exitcode = EXITCODE_SET | n;/* We're really exiting. Record the UNIX exit code. */
|
2005-09-20 10:06:57 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
exit_state = ES_EXEC_EXIT;
|
|
|
|
maybe_set_exit_code_from_windows ();
|
|
|
|
}
|
|
|
|
|
|
|
|
sigproc_terminate (ES_FINAL);
|
2005-09-24 07:37:52 +08:00
|
|
|
zap_cwd ();
|
2005-01-11 23:31:04 +08:00
|
|
|
|
|
|
|
/* FIXME: There is a potential race between an execed process and its
|
2005-09-23 11:35:41 +08:00
|
|
|
parent here. I hated to add a mutex just for that, though. */
|
2005-01-11 23:31:04 +08:00
|
|
|
struct rusage r;
|
|
|
|
fill_rusage (&r, hMainProc);
|
|
|
|
add_rusage (&self->rusage_self, &r);
|
2005-03-08 22:31:21 +08:00
|
|
|
int exitcode = self->exitcode & 0xffff;
|
|
|
|
if (!self->cygstarted)
|
|
|
|
exitcode >>= 8;
|
2005-09-24 07:37:52 +08:00
|
|
|
sigproc_printf ("Calling ExitProcess n %p, exitcode %p", n, exitcode);
|
|
|
|
ExitProcess (exitcode);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2005-01-11 23:31:04 +08:00
|
|
|
# undef self
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
void
|
2005-01-23 05:17:53 +08:00
|
|
|
pinfo::init (pid_t n, DWORD flag, HANDLE h0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-04-29 07:59:44 +08:00
|
|
|
shared_locations shloc;
|
2005-01-26 08:15:11 +08:00
|
|
|
h = NULL;
|
2005-03-08 13:05:02 +08:00
|
|
|
if (myself && !(flag & PID_EXECED)
|
|
|
|
&& (n == myself->pid || (DWORD) n == myself->dwProcessId))
|
2000-07-30 00:24:59 +08:00
|
|
|
{
|
2000-08-26 11:48:37 +08:00
|
|
|
procinfo = myself;
|
2000-07-30 00:24:59 +08:00
|
|
|
destroy = 0;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-10-15 04:25:52 +08:00
|
|
|
void *mapaddr;
|
2005-02-27 04:50:25 +08:00
|
|
|
int createit = flag & (PID_IN_USE | PID_EXECED);
|
2005-01-26 08:15:11 +08:00
|
|
|
DWORD access = FILE_MAP_READ
|
|
|
|
| (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW)
|
|
|
|
? FILE_MAP_WRITE : 0);
|
|
|
|
if (!h0)
|
2005-04-29 07:59:44 +08:00
|
|
|
shloc = (flag & (PID_IN_USE | PID_EXECED)) ? SH_JUSTCREATE : SH_JUSTOPEN;
|
2002-10-15 04:25:52 +08:00
|
|
|
else
|
|
|
|
{
|
2005-04-29 07:59:44 +08:00
|
|
|
shloc = SH_MYSELF;
|
2005-01-26 08:15:11 +08:00
|
|
|
if (h0 == INVALID_HANDLE_VALUE)
|
|
|
|
h0 = NULL;
|
2002-10-15 04:25:52 +08:00
|
|
|
}
|
|
|
|
|
2005-01-26 08:15:11 +08:00
|
|
|
procinfo = NULL;
|
2005-06-08 03:31:42 +08:00
|
|
|
PSECURITY_ATTRIBUTES sa_buf = (PSECURITY_ATTRIBUTES) alloca (1024);
|
2005-04-29 07:59:44 +08:00
|
|
|
PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf, cygheap->user.sid(),
|
|
|
|
well_known_world_sid,
|
|
|
|
FILE_MAP_READ);
|
|
|
|
|
2005-01-26 08:15:11 +08:00
|
|
|
for (int i = 0; i < 20; i++)
|
2000-10-15 09:37:07 +08:00
|
|
|
{
|
2005-04-29 07:59:44 +08:00
|
|
|
DWORD mapsize;
|
|
|
|
if (flag & PID_EXECED)
|
|
|
|
mapsize = PINFO_REDIR_SIZE;
|
|
|
|
else
|
|
|
|
mapsize = sizeof (_pinfo);
|
|
|
|
|
|
|
|
procinfo = (_pinfo *) open_shared ("cygpid", n, h0, mapsize, shloc,
|
|
|
|
sec_attribs, access);
|
2005-01-26 08:15:11 +08:00
|
|
|
if (!h0)
|
|
|
|
{
|
2005-04-29 07:59:44 +08:00
|
|
|
if (createit)
|
|
|
|
__seterrno ();
|
|
|
|
return;
|
2000-10-15 09:37:07 +08:00
|
|
|
}
|
2005-01-23 05:17:53 +08:00
|
|
|
|
|
|
|
if (!procinfo)
|
2004-07-25 03:18:58 +08:00
|
|
|
{
|
2005-01-23 05:17:53 +08:00
|
|
|
if (exit_state)
|
2004-07-25 03:18:58 +08:00
|
|
|
return;
|
|
|
|
|
2005-04-29 07:59:44 +08:00
|
|
|
switch (GetLastError ())
|
|
|
|
{
|
|
|
|
case ERROR_INVALID_HANDLE:
|
|
|
|
api_fatal ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
|
|
|
|
case ERROR_INVALID_ADDRESS:
|
|
|
|
mapaddr = NULL;
|
|
|
|
}
|
2005-07-29 22:33:50 +08:00
|
|
|
debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
|
2005-07-29 22:25:28 +08:00
|
|
|
low_priority_sleep (0);
|
2005-01-23 05:17:53 +08:00
|
|
|
continue;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-04-29 07:59:44 +08:00
|
|
|
bool created = shloc != SH_JUSTOPEN;
|
|
|
|
|
2001-11-02 05:15:53 +08:00
|
|
|
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
|
|
|
|
&& cygwin_pid (procinfo->dwProcessId) != procinfo->pid)
|
2000-10-20 12:20:21 +08:00
|
|
|
{
|
2005-01-23 05:17:53 +08:00
|
|
|
set_errno (ESRCH);
|
|
|
|
break;
|
2000-10-20 12:20:21 +08:00
|
|
|
}
|
|
|
|
|
2000-10-15 09:37:07 +08:00
|
|
|
if (procinfo->process_state & PID_EXECED)
|
|
|
|
{
|
2005-02-27 04:50:25 +08:00
|
|
|
assert (i == 0);
|
2000-10-15 09:37:07 +08:00
|
|
|
pid_t realpid = procinfo->pid;
|
|
|
|
debug_printf ("execed process windows pid %d, cygwin pid %d", n, realpid);
|
|
|
|
if (realpid == n)
|
|
|
|
api_fatal ("retrieval of execed process info for pid %d failed due to recursion.", n);
|
2005-01-23 05:17:53 +08:00
|
|
|
|
2005-01-26 08:15:11 +08:00
|
|
|
n = realpid;
|
|
|
|
CloseHandle (h0);
|
|
|
|
h0 = NULL;
|
2005-01-23 05:17:53 +08:00
|
|
|
goto loop;
|
2000-10-15 09:37:07 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-12-22 11:16:36 +08:00
|
|
|
/* In certain pathological cases, it is possible for the shared memory
|
|
|
|
region to exist for a while after a process has exited. This should
|
|
|
|
only be a brief occurrence, so rather than introduce some kind of
|
|
|
|
locking mechanism, just loop. */
|
2005-01-23 05:17:53 +08:00
|
|
|
if (!created && createit && (procinfo->process_state & PID_EXITED))
|
2005-09-23 05:10:07 +08:00
|
|
|
{
|
2005-12-22 11:16:36 +08:00
|
|
|
debug_printf ("looping because pid %d, procinfo->pid %d, "
|
|
|
|
"procinfo->dwProcessid %u has PID_EXITED set",
|
2005-09-23 05:10:07 +08:00
|
|
|
n, procinfo->pid, procinfo->dwProcessId);
|
|
|
|
goto loop;
|
|
|
|
}
|
2000-10-15 09:37:07 +08:00
|
|
|
|
|
|
|
if (!created)
|
|
|
|
/* nothing */;
|
2000-10-21 12:53:49 +08:00
|
|
|
else if (!(flag & PID_EXECED))
|
2005-01-17 01:00:27 +08:00
|
|
|
procinfo->pid = n;
|
2000-07-30 00:24:59 +08:00
|
|
|
else
|
|
|
|
{
|
2000-08-26 11:48:37 +08:00
|
|
|
procinfo->process_state |= PID_IN_USE | PID_EXECED;
|
2000-11-03 12:27:03 +08:00
|
|
|
procinfo->pid = myself->pid;
|
2000-07-30 00:24:59 +08:00
|
|
|
}
|
2004-11-26 12:15:10 +08:00
|
|
|
|
2005-01-23 05:17:53 +08:00
|
|
|
h = h0; /* Success! */
|
2000-10-15 09:37:07 +08:00
|
|
|
break;
|
2005-01-23 05:17:53 +08:00
|
|
|
|
|
|
|
loop:
|
|
|
|
release ();
|
2005-02-27 04:50:25 +08:00
|
|
|
if (h0)
|
|
|
|
low_priority_sleep (0);
|
2005-01-23 05:17:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (h)
|
2005-01-26 08:15:11 +08:00
|
|
|
{
|
|
|
|
destroy = 1;
|
|
|
|
ProtectHandle1 (h, pinfo_shared_handle);
|
|
|
|
}
|
2005-01-23 05:17:53 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
h = h0;
|
|
|
|
release ();
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
2000-10-09 10:53:44 +08:00
|
|
|
|
2003-09-27 09:58:23 +08:00
|
|
|
void
|
|
|
|
pinfo::set_acl()
|
|
|
|
{
|
2005-06-08 03:31:42 +08:00
|
|
|
PACL acl_buf = (PACL) alloca (1024);
|
2003-09-27 09:58:23 +08:00
|
|
|
SECURITY_DESCRIPTOR sd;
|
2003-11-29 04:55:59 +08:00
|
|
|
|
2005-06-08 03:31:42 +08:00
|
|
|
sec_acl (acl_buf, true, true, cygheap->user.sid (),
|
2003-09-27 09:58:23 +08:00
|
|
|
well_known_world_sid, FILE_MAP_READ);
|
2003-11-29 04:55:59 +08:00
|
|
|
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
|
|
|
|
debug_printf ("InitializeSecurityDescriptor %E");
|
2005-06-08 03:31:42 +08:00
|
|
|
else if (!SetSecurityDescriptorDacl (&sd, TRUE, acl_buf, FALSE))
|
2003-11-29 04:55:59 +08:00
|
|
|
debug_printf ("SetSecurityDescriptorDacl %E");
|
|
|
|
else if (!SetKernelObjectSecurity (h, DACL_SECURITY_INFORMATION, &sd))
|
2003-09-27 09:58:23 +08:00
|
|
|
debug_printf ("SetKernelObjectSecurity %E");
|
|
|
|
}
|
|
|
|
|
2005-11-14 12:28:45 +08:00
|
|
|
const char *
|
|
|
|
_pinfo::_ctty (char *buf)
|
|
|
|
{
|
|
|
|
if (ctty == TTY_CONSOLE)
|
|
|
|
strcpy (buf, "ctty /dev/console");
|
|
|
|
else if (ctty < 0)
|
|
|
|
strcpy (buf, "no ctty");
|
|
|
|
else
|
|
|
|
__small_sprintf (buf, "ctty /dev/tty%d", ctty);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
void
|
2003-12-11 14:12:41 +08:00
|
|
|
_pinfo::set_ctty (tty_min *tc, int flags, fhandler_tty_slave *arch)
|
2003-12-08 06:37:12 +08:00
|
|
|
{
|
2005-11-18 00:36:00 +08:00
|
|
|
debug_printf ("old %s", __ctty ());
|
2003-12-08 06:37:12 +08:00
|
|
|
if ((ctty < 0 || ctty == tc->ntty) && !(flags & O_NOCTTY))
|
|
|
|
{
|
|
|
|
ctty = tc->ntty;
|
2005-11-18 00:36:00 +08:00
|
|
|
syscall_printf ("attached %s sid %d, pid %d, tty->pgid %d, tty->sid %d",
|
|
|
|
__ctty (), sid, pid, pgid, tc->getsid ());
|
2003-12-08 06:37:12 +08:00
|
|
|
|
|
|
|
pinfo p (tc->getsid ());
|
2005-02-27 04:50:25 +08:00
|
|
|
if (sid == pid && (!p || p->pid == pid || !p->exists ()))
|
2003-12-08 06:37:12 +08:00
|
|
|
{
|
2005-11-18 00:36:00 +08:00
|
|
|
paranoid_printf ("resetting %s sid. Was %d, now %d. pgid was %d, now %d.",
|
|
|
|
__ctty (), tc->getsid (), sid, tc->getpgid (), pgid);
|
2003-12-08 06:37:12 +08:00
|
|
|
/* We are the session leader */
|
|
|
|
tc->setsid (sid);
|
|
|
|
tc->setpgid (pgid);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sid = tc->getsid ();
|
|
|
|
if (tc->getpgid () == 0)
|
|
|
|
tc->setpgid (pgid);
|
2003-12-11 14:12:41 +08:00
|
|
|
if (cygheap->ctty != arch)
|
|
|
|
{
|
2003-12-17 07:28:03 +08:00
|
|
|
debug_printf ("cygheap->ctty %p, arch %p", cygheap->ctty, arch);
|
2003-12-11 14:19:36 +08:00
|
|
|
if (!cygheap->ctty)
|
2003-12-11 14:12:41 +08:00
|
|
|
syscall_printf ("ctty NULL");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
syscall_printf ("ctty %p, usecount %d", cygheap->ctty,
|
|
|
|
cygheap->ctty->usecount);
|
2003-12-27 10:20:07 +08:00
|
|
|
cygheap->ctty->close ();
|
2003-12-11 14:12:41 +08:00
|
|
|
}
|
|
|
|
cygheap->ctty = arch;
|
|
|
|
if (arch)
|
2003-12-17 07:28:03 +08:00
|
|
|
{
|
|
|
|
arch->usecount++;
|
2005-11-24 10:34:31 +08:00
|
|
|
/* guard ctty arch */
|
|
|
|
cygheap->manage_console_count ("_pinfo::set_ctty", 1);
|
2005-11-14 12:28:45 +08:00
|
|
|
report_tty_counts (cygheap->ctty, "ctty", "");
|
2003-12-17 07:28:03 +08:00
|
|
|
}
|
2003-12-11 14:12:41 +08:00
|
|
|
}
|
2003-12-08 06:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-27 12:30:08 +08:00
|
|
|
/* Test to determine if a process really exists and is processing signals.
|
|
|
|
*/
|
|
|
|
bool __stdcall
|
|
|
|
_pinfo::exists ()
|
|
|
|
{
|
|
|
|
return this && !(process_state & PID_EXITED);
|
|
|
|
}
|
|
|
|
|
2002-10-31 05:05:18 +08:00
|
|
|
bool
|
|
|
|
_pinfo::alive ()
|
|
|
|
{
|
|
|
|
HANDLE h = OpenProcess (PROCESS_QUERY_INFORMATION, false, dwProcessId);
|
|
|
|
if (h)
|
|
|
|
CloseHandle (h);
|
|
|
|
return !!h;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern char **__argv;
|
|
|
|
|
2005-10-18 07:27:00 +08:00
|
|
|
DWORD WINAPI
|
|
|
|
commune_process (void *arg)
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
2005-10-18 07:27:00 +08:00
|
|
|
siginfo_t& si = *((siginfo_t *) arg);
|
2005-04-03 16:45:21 +08:00
|
|
|
char path[CYG_MAX_PATH];
|
2002-10-31 05:05:18 +08:00
|
|
|
DWORD nr;
|
2005-09-29 06:56:47 +08:00
|
|
|
HANDLE& tothem = si._si_commune._si_write_handle;
|
|
|
|
HANDLE process_sync =
|
|
|
|
OpenSemaphore (SYNCHRONIZE, false, shared_name (path, "commune", si.si_pid));
|
|
|
|
if (process_sync) // FIXME: this test shouldn't be necessary
|
|
|
|
ProtectHandle (process_sync);
|
2002-10-31 05:05:18 +08:00
|
|
|
|
2005-10-18 07:27:00 +08:00
|
|
|
lock_process now (false);
|
2005-10-04 01:23:54 +08:00
|
|
|
|
2005-09-29 06:56:47 +08:00
|
|
|
switch (si._si_commune._si_code)
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
|
|
|
case PICOM_CMDLINE:
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
sigproc_printf ("processing PICOM_CMDLINE");
|
2002-10-31 05:05:18 +08:00
|
|
|
unsigned n = 1;
|
2003-09-05 09:55:01 +08:00
|
|
|
extern int __argc_safe;
|
|
|
|
const char *argv[__argc_safe + 1];
|
2004-06-07 12:26:32 +08:00
|
|
|
|
2003-09-05 09:55:01 +08:00
|
|
|
for (int i = 0; i < __argc_safe; i++)
|
|
|
|
{
|
2003-12-04 00:35:52 +08:00
|
|
|
if (IsBadStringPtr (__argv[i], INT32_MAX))
|
2003-09-05 09:55:01 +08:00
|
|
|
argv[i] = "";
|
|
|
|
else
|
|
|
|
argv[i] = __argv[i];
|
|
|
|
n += strlen (argv[i]) + 1;
|
|
|
|
}
|
|
|
|
argv[__argc_safe] = NULL;
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
|
|
|
/*__seterrno ();*/ // this is run from the signal thread, so don't set errno
|
|
|
|
sigproc_printf ("WriteFile sizeof argv failed, %E");
|
|
|
|
}
|
|
|
|
else
|
2003-09-05 09:55:01 +08:00
|
|
|
for (const char **a = argv; *a; a++)
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, *a, strlen (*a) + 1, &nr, NULL))
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
2003-09-05 09:55:01 +08:00
|
|
|
sigproc_printf ("WriteFile arg %d failed, %E", a - argv);
|
2002-10-31 05:05:18 +08:00
|
|
|
break;
|
|
|
|
}
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, "", 1, &nr, NULL))
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
{
|
|
|
|
sigproc_printf ("WriteFile null failed, %E");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2005-01-29 19:23:07 +08:00
|
|
|
case PICOM_CWD:
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
sigproc_printf ("processing PICOM_CWD");
|
2005-01-31 18:28:55 +08:00
|
|
|
unsigned int n = strlen (cygheap->cwd.get (path, 1, 1,
|
|
|
|
CYG_MAX_PATH)) + 1;
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile sizeof cwd failed, %E");
|
2005-09-29 06:56:47 +08:00
|
|
|
else if (!WriteFile (tothem, path, n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile cwd failed, %E");
|
2005-01-29 19:23:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PICOM_ROOT:
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
sigproc_printf ("processing PICOM_ROOT");
|
2005-09-29 06:56:47 +08:00
|
|
|
unsigned n;
|
2005-01-29 19:23:07 +08:00
|
|
|
if (cygheap->root.exists ())
|
2005-01-31 18:28:55 +08:00
|
|
|
n = strlen (strcpy (path, cygheap->root.posix_path ())) + 1;
|
2005-01-29 19:23:07 +08:00
|
|
|
else
|
2005-01-31 18:28:55 +08:00
|
|
|
n = strlen (strcpy (path, "/")) + 1;
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile sizeof root failed, %E");
|
2005-09-29 06:56:47 +08:00
|
|
|
else if (!WriteFile (tothem, path, n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile root failed, %E");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PICOM_FDS:
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
sigproc_printf ("processing PICOM_FDS");
|
2005-01-31 18:28:55 +08:00
|
|
|
unsigned int n = 0;
|
|
|
|
int fd;
|
|
|
|
cygheap_fdenum cfd;
|
|
|
|
while ((fd = cfd.next ()) >= 0)
|
|
|
|
n += sizeof (int);
|
|
|
|
cfd.rewind ();
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile sizeof fds failed, %E");
|
|
|
|
else
|
|
|
|
while ((fd = cfd.next ()) >= 0)
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, &fd, sizeof fd, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
{
|
|
|
|
sigproc_printf ("WriteFile fd %d failed, %E", fd);
|
|
|
|
break;
|
|
|
|
}
|
2005-05-02 11:50:11 +08:00
|
|
|
break;
|
2005-01-31 18:28:55 +08:00
|
|
|
}
|
2005-02-06 19:15:29 +08:00
|
|
|
case PICOM_PIPE_FHANDLER:
|
2005-10-02 08:13:41 +08:00
|
|
|
{
|
|
|
|
sigproc_printf ("processing PICOM_FDS");
|
|
|
|
HANDLE hdl = si._si_commune._si_pipe_fhandler;
|
|
|
|
unsigned int n = 0;
|
|
|
|
cygheap_fdenum cfd;
|
|
|
|
while (cfd.next () >= 0)
|
|
|
|
if (cfd->get_handle () == hdl)
|
|
|
|
{
|
|
|
|
fhandler_pipe *fh = cfd;
|
|
|
|
n = sizeof *fh;
|
|
|
|
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
|
|
|
sigproc_printf ("WriteFile sizeof hdl failed, %E");
|
|
|
|
else if (!WriteFile (tothem, fh, n, &nr, NULL))
|
|
|
|
sigproc_printf ("WriteFile hdl failed, %E");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!n && !WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
|
|
|
sigproc_printf ("WriteFile sizeof hdl failed, %E");
|
|
|
|
break;
|
|
|
|
}
|
2005-01-31 18:28:55 +08:00
|
|
|
case PICOM_FD:
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
sigproc_printf ("processing PICOM_FD");
|
2005-09-29 06:56:47 +08:00
|
|
|
int fd = si._si_commune._si_fd;
|
2005-02-06 19:15:29 +08:00
|
|
|
unsigned int n = 0;
|
2005-01-31 18:28:55 +08:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
2005-02-01 23:11:47 +08:00
|
|
|
n = strlen (strcpy (path, "")) + 1;
|
2005-01-31 18:28:55 +08:00
|
|
|
else
|
|
|
|
n = strlen (cfd->get_proc_fd_name (path)) + 1;
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!WriteFile (tothem, &n, sizeof n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile sizeof fd failed, %E");
|
2005-09-29 06:56:47 +08:00
|
|
|
else if (!WriteFile (tothem, path, n, &nr, NULL))
|
2005-01-31 18:28:55 +08:00
|
|
|
sigproc_printf ("WriteFile fd failed, %E");
|
2005-05-02 11:50:11 +08:00
|
|
|
break;
|
2005-01-29 19:23:07 +08:00
|
|
|
}
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
case PICOM_FIFO:
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
sigproc_printf ("processing PICOM_FIFO");
|
2005-09-29 06:56:47 +08:00
|
|
|
fhandler_fifo *fh = cygheap->fdtab.find_fifo (si._si_commune._si_str);
|
2004-03-22 01:41:40 +08:00
|
|
|
HANDLE it[2];
|
|
|
|
if (fh == NULL)
|
|
|
|
it[0] = it[1] = NULL;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
it[0] = fh->get_handle ();
|
|
|
|
it[1] = fh->get_output_handle ();
|
|
|
|
}
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
|
2005-09-29 06:56:47 +08:00
|
|
|
debug_printf ("fifo %sfound %p, %p", fh ? "" : "not ", it[0], it[1]);
|
|
|
|
if (!WriteFile (tothem, it, sizeof (it), &nr, NULL))
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
{
|
|
|
|
/*__seterrno ();*/ // this is run from the signal thread, so don't set errno
|
|
|
|
sigproc_printf ("WriteFile read handle failed, %E");
|
|
|
|
}
|
2005-09-29 06:56:47 +08:00
|
|
|
WaitForSingleObject (process_sync, INFINITE);
|
|
|
|
process_sync = NULL;
|
|
|
|
if (fh)
|
|
|
|
fh->close_one_end ();
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
break;
|
2002-10-31 05:05:18 +08:00
|
|
|
}
|
|
|
|
}
|
2005-09-29 06:56:47 +08:00
|
|
|
if (process_sync)
|
|
|
|
{
|
2005-10-02 08:13:41 +08:00
|
|
|
DWORD res = WaitForSingleObject (process_sync, 5000);
|
|
|
|
if (res != WAIT_OBJECT_0)
|
|
|
|
sigproc_printf ("WFSO failed - %d, %E", res);
|
|
|
|
else
|
|
|
|
sigproc_printf ("synchronized with pid %d", si.si_pid);
|
2005-09-29 06:56:47 +08:00
|
|
|
ForceCloseHandle (process_sync);
|
|
|
|
}
|
|
|
|
CloseHandle (tothem);
|
2005-10-18 07:27:00 +08:00
|
|
|
_my_tls._ctinfo->auto_release ();
|
|
|
|
return 0;
|
2002-10-31 05:05:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
commune_result
|
2005-09-29 06:56:47 +08:00
|
|
|
_pinfo::commune_request (__uint32_t code, ...)
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
|
|
|
DWORD nr;
|
|
|
|
commune_result res;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
va_list args;
|
2005-09-29 06:56:47 +08:00
|
|
|
siginfo_t si = {0};
|
|
|
|
HANDLE& hp = si._si_commune._si_process_handle;
|
|
|
|
HANDLE& fromthem = si._si_commune._si_read_handle;
|
|
|
|
HANDLE request_sync = NULL;
|
|
|
|
bool locked = false;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
|
|
|
|
va_start (args, code);
|
2002-11-05 11:39:25 +08:00
|
|
|
|
|
|
|
res.s = NULL;
|
|
|
|
res.n = 0;
|
|
|
|
|
2004-01-04 04:57:11 +08:00
|
|
|
if (!this || !pid)
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
|
|
|
set_errno (ESRCH);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2005-09-29 06:56:47 +08:00
|
|
|
si._si_commune._si_code = code;
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case PICOM_PIPE_FHANDLER:
|
|
|
|
si._si_commune._si_pipe_fhandler = va_arg (args, HANDLE);
|
2005-09-29 03:22:25 +08:00
|
|
|
break;
|
2002-10-31 05:05:18 +08:00
|
|
|
|
2005-09-29 06:56:47 +08:00
|
|
|
case PICOM_FD:
|
|
|
|
si._si_commune._si_fd = va_arg (args, int);
|
|
|
|
break;
|
2005-09-29 03:22:25 +08:00
|
|
|
|
2005-09-29 06:56:47 +08:00
|
|
|
case PICOM_FIFO:
|
|
|
|
si._si_commune._si_str = va_arg (args, char *);
|
|
|
|
break;
|
2005-09-29 03:22:25 +08:00
|
|
|
}
|
|
|
|
|
2005-10-18 07:27:00 +08:00
|
|
|
lock_process now ();
|
2005-09-29 06:56:47 +08:00
|
|
|
locked = true;
|
|
|
|
char name_buf[CYG_MAX_PATH];
|
|
|
|
request_sync = CreateSemaphore (&sec_none_nih, 0, LONG_MAX,
|
|
|
|
shared_name (name_buf, "commune", myself->pid));
|
|
|
|
if (!request_sync)
|
|
|
|
goto err;
|
|
|
|
ProtectHandle (request_sync);
|
|
|
|
|
|
|
|
si.si_signo = __SIGCOMMUNE;
|
|
|
|
if (sig_send (this, si))
|
2005-10-02 08:13:41 +08:00
|
|
|
{
|
|
|
|
ForceCloseHandle (request_sync); /* don't signal semaphore since there was apparently no receiving process */
|
|
|
|
request_sync = NULL;
|
|
|
|
goto err;
|
|
|
|
}
|
2002-10-31 05:05:18 +08:00
|
|
|
|
|
|
|
size_t n;
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case PICOM_CMDLINE:
|
2005-01-29 19:23:07 +08:00
|
|
|
case PICOM_CWD:
|
|
|
|
case PICOM_ROOT:
|
2005-01-31 18:28:55 +08:00
|
|
|
case PICOM_FDS:
|
2005-09-29 06:56:47 +08:00
|
|
|
case PICOM_FD:
|
|
|
|
case PICOM_PIPE_FHANDLER:
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
if (!ReadFile (fromthem, &n, sizeof n, &nr, NULL) || nr != sizeof n)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto err;
|
|
|
|
}
|
2005-02-06 19:15:29 +08:00
|
|
|
if (!n)
|
2005-05-02 11:50:11 +08:00
|
|
|
res.s = NULL;
|
2005-02-06 19:15:29 +08:00
|
|
|
else
|
2005-05-02 11:50:11 +08:00
|
|
|
{
|
2005-08-24 12:38:39 +08:00
|
|
|
res.s = (char *) cmalloc (HEAP_COMMUNE, n);
|
2005-02-06 19:15:29 +08:00
|
|
|
char *p;
|
2005-08-24 12:38:39 +08:00
|
|
|
for (p = res.s; n && ReadFile (fromthem, p, n, &nr, NULL); p += nr, n -= nr)
|
2005-02-06 19:15:29 +08:00
|
|
|
continue;
|
2005-08-25 01:45:11 +08:00
|
|
|
if (n)
|
2005-02-06 19:15:29 +08:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto err;
|
|
|
|
}
|
2005-08-25 01:45:11 +08:00
|
|
|
res.n = p - res.s;
|
2005-05-02 11:50:11 +08:00
|
|
|
}
|
2002-10-31 05:05:18 +08:00
|
|
|
break;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
case PICOM_FIFO:
|
|
|
|
{
|
|
|
|
DWORD x = ReadFile (fromthem, res.handles, sizeof (res.handles), &nr, NULL);
|
2005-09-29 06:56:47 +08:00
|
|
|
if (!x || nr != sizeof (res.handles))
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
{
|
2005-09-29 06:56:47 +08:00
|
|
|
__seterrno ();
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
goto err;
|
|
|
|
}
|
2005-09-29 06:56:47 +08:00
|
|
|
for (int i = 0; i < 2; i++)
|
|
|
|
if (!DuplicateHandle (hp, res.handles[i], hMainProc, &res.handles[i],
|
|
|
|
0, false, DUPLICATE_SAME_ACCESS))
|
|
|
|
{
|
|
|
|
if (i)
|
|
|
|
CloseHandle (res.handles[0]);
|
|
|
|
res.handles[0] = res.handles[1] = NULL; /* FIXME: possibly left a handle open in child? */
|
|
|
|
goto err;
|
|
|
|
}
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-10-31 05:05:18 +08:00
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err:
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
memset (&res, 0, sizeof (res));
|
|
|
|
|
2002-10-31 05:05:18 +08:00
|
|
|
out:
|
2005-09-29 06:56:47 +08:00
|
|
|
if (request_sync)
|
|
|
|
{
|
|
|
|
LONG res;
|
|
|
|
ReleaseSemaphore (request_sync, 1, &res);
|
|
|
|
ForceCloseHandle (request_sync);
|
|
|
|
}
|
|
|
|
if (hp)
|
|
|
|
CloseHandle (hp);
|
|
|
|
if (fromthem)
|
|
|
|
CloseHandle (fromthem);
|
2002-10-31 05:05:18 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-02-06 19:15:29 +08:00
|
|
|
fhandler_pipe *
|
|
|
|
_pinfo::pipe_fhandler (HANDLE hdl, size_t &n)
|
|
|
|
{
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid == myself->pid)
|
|
|
|
return NULL;
|
2005-09-29 06:56:47 +08:00
|
|
|
commune_result cr = commune_request (PICOM_PIPE_FHANDLER, hdl);
|
2005-02-06 19:15:29 +08:00
|
|
|
n = cr.n;
|
|
|
|
return (fhandler_pipe *) cr.s;
|
|
|
|
}
|
|
|
|
|
2005-01-31 18:28:55 +08:00
|
|
|
char *
|
|
|
|
_pinfo::fd (int fd, size_t &n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 06:56:47 +08:00
|
|
|
commune_result cr = commune_request (PICOM_FD, fd);
|
2005-01-31 18:28:55 +08:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
2005-08-24 12:38:39 +08:00
|
|
|
s = cstrdup ("");
|
2005-01-31 18:28:55 +08:00
|
|
|
else
|
2005-08-24 12:38:39 +08:00
|
|
|
s = cfd->get_proc_fd_name ((char *) cmalloc (HEAP_COMMUNE, CYG_MAX_PATH));
|
2005-01-31 18:28:55 +08:00
|
|
|
n = strlen (s) + 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
_pinfo::fds (size_t &n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 06:56:47 +08:00
|
|
|
commune_result cr = commune_request (PICOM_FDS);
|
2005-01-31 18:28:55 +08:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = 0;
|
|
|
|
int fd;
|
2005-10-24 23:42:14 +08:00
|
|
|
cygheap_fdenum cfd (true);
|
2005-01-31 18:28:55 +08:00
|
|
|
while ((fd = cfd.next ()) >= 0)
|
|
|
|
n += sizeof (int);
|
|
|
|
cfd.rewind ();
|
2005-08-24 12:38:39 +08:00
|
|
|
s = (char *) cmalloc (HEAP_COMMUNE, n);
|
2005-01-31 18:28:55 +08:00
|
|
|
int *p = (int *) s;
|
|
|
|
while ((fd = cfd.next ()) >= 0 && (char *) p - s < (int) n)
|
|
|
|
*p++ = fd;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2005-01-29 19:23:07 +08:00
|
|
|
char *
|
|
|
|
_pinfo::root (size_t& n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 06:56:47 +08:00
|
|
|
commune_result cr = commune_request (PICOM_ROOT);
|
2005-01-29 19:23:07 +08:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cygheap->root.exists ())
|
2005-08-24 12:38:39 +08:00
|
|
|
s = cstrdup (cygheap->root.posix_path ());
|
2005-01-29 19:23:07 +08:00
|
|
|
else
|
2005-08-24 12:38:39 +08:00
|
|
|
s = cstrdup ("/");
|
2005-01-29 19:23:07 +08:00
|
|
|
n = strlen (s) + 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
_pinfo::cwd (size_t& n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 06:56:47 +08:00
|
|
|
commune_result cr = commune_request (PICOM_CWD);
|
2005-01-29 19:23:07 +08:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-24 12:38:39 +08:00
|
|
|
s = (char *) cmalloc (HEAP_COMMUNE, CYG_MAX_PATH);
|
2005-01-29 19:23:07 +08:00
|
|
|
cygheap->cwd.get (s, 1, 1, CYG_MAX_PATH);
|
|
|
|
n = strlen (s) + 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2002-10-31 05:05:18 +08:00
|
|
|
char *
|
2003-03-09 03:22:08 +08:00
|
|
|
_pinfo::cmdline (size_t& n)
|
2002-10-31 05:05:18 +08:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 06:56:47 +08:00
|
|
|
commune_result cr = commune_request (PICOM_CMDLINE);
|
2002-10-31 05:05:18 +08:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = 1;
|
|
|
|
for (char **a = __argv; *a; a++)
|
2002-12-17 02:56:33 +08:00
|
|
|
n += strlen (*a) + 1;
|
2002-10-31 05:05:18 +08:00
|
|
|
char *p;
|
2005-08-24 12:38:39 +08:00
|
|
|
p = s = (char *) cmalloc (HEAP_COMMUNE, n);
|
2002-10-31 05:05:18 +08:00
|
|
|
for (char **a = __argv; *a; a++)
|
|
|
|
{
|
|
|
|
strcpy (p, *a);
|
|
|
|
p = strchr (p, '\0') + 1;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-11-26 12:15:10 +08:00
|
|
|
/* This is the workhorse which waits for the write end of the pipe
|
2004-12-25 02:31:23 +08:00
|
|
|
created during new process creation. If the pipe is closed or a zero
|
|
|
|
is received on the pipe, it is assumed that the cygwin pid has exited.
|
|
|
|
Otherwise, various "signals" can be sent to the parent to inform the
|
|
|
|
parent to perform a certain action. */
|
2004-11-26 12:15:10 +08:00
|
|
|
static DWORD WINAPI
|
|
|
|
proc_waiter (void *arg)
|
|
|
|
{
|
2005-01-17 12:12:08 +08:00
|
|
|
pinfo vchild = *(pinfo *) arg;
|
|
|
|
((pinfo *) arg)->waiter_ready = true;
|
2004-11-26 12:15:10 +08:00
|
|
|
|
|
|
|
siginfo_t si;
|
|
|
|
si.si_signo = SIGCHLD;
|
2005-09-26 21:47:27 +08:00
|
|
|
si.si_code = CLD_EXITED;
|
2004-11-26 12:15:10 +08:00
|
|
|
si.si_pid = vchild->pid;
|
|
|
|
si.si_errno = 0;
|
|
|
|
#if 0 // FIXME: This is tricky to get right
|
|
|
|
si.si_utime = pchildren[rc]->rusage_self.ru_utime;
|
|
|
|
si.si_stime = pchildren[rc].rusage_self.ru_stime;
|
|
|
|
#else
|
|
|
|
si.si_utime = 0;
|
|
|
|
si.si_stime = 0;
|
|
|
|
#endif
|
|
|
|
pid_t pid = vchild->pid;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DWORD nb;
|
|
|
|
char buf = '\0';
|
2005-01-11 23:31:04 +08:00
|
|
|
|
2004-11-26 12:15:10 +08:00
|
|
|
if (!ReadFile (vchild.rd_proc_pipe, &buf, 1, &nb, NULL)
|
|
|
|
&& GetLastError () != ERROR_BROKEN_PIPE)
|
|
|
|
{
|
|
|
|
system_printf ("error on read of child wait pipe %p, %E", vchild.rd_proc_pipe);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
si.si_uid = vchild->uid;
|
|
|
|
|
|
|
|
switch (buf)
|
|
|
|
{
|
2004-12-03 12:46:00 +08:00
|
|
|
case __ALERT_ALIVE:
|
|
|
|
continue;
|
2004-11-26 12:15:10 +08:00
|
|
|
case 0:
|
|
|
|
/* Child exited. Do some cleanup and signal myself. */
|
|
|
|
CloseHandle (vchild.rd_proc_pipe);
|
|
|
|
vchild.rd_proc_pipe = NULL;
|
2005-01-17 12:12:08 +08:00
|
|
|
vchild.maybe_set_exit_code_from_windows ();
|
2004-11-26 12:15:10 +08:00
|
|
|
if (WIFEXITED (vchild->exitcode))
|
2005-09-26 21:47:27 +08:00
|
|
|
si.si_code = CLD_EXITED;
|
2004-11-26 12:15:10 +08:00
|
|
|
else if (WCOREDUMP (vchild->exitcode))
|
2005-09-26 21:47:27 +08:00
|
|
|
si.si_code = CLD_DUMPED;
|
2004-11-26 12:15:10 +08:00
|
|
|
else
|
2005-09-26 21:47:27 +08:00
|
|
|
si.si_code = CLD_KILLED;
|
2004-11-26 12:15:10 +08:00
|
|
|
si.si_status = vchild->exitcode;
|
2005-01-17 12:12:08 +08:00
|
|
|
vchild->process_state = PID_EXITED;
|
|
|
|
/* This should always be last. Do not use vchild-> beyond this point */
|
2004-11-26 12:15:10 +08:00
|
|
|
break;
|
|
|
|
case SIGTTIN:
|
|
|
|
case SIGTTOU:
|
|
|
|
case SIGTSTP:
|
|
|
|
case SIGSTOP:
|
2004-12-06 03:41:26 +08:00
|
|
|
if (ISSTATE (myself, PID_NOCLDSTOP)) // FIXME: No need for this flag to be in _pinfo any longer
|
|
|
|
continue;
|
2004-11-26 12:15:10 +08:00
|
|
|
/* Child stopped. Signal myself. */
|
2005-09-26 21:47:27 +08:00
|
|
|
si.si_code = CLD_STOPPED;
|
2004-11-26 12:15:10 +08:00
|
|
|
break;
|
|
|
|
case SIGCONT:
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
system_printf ("unknown value %d on proc pipe", buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Special case: If the "child process" that died is us, then we're
|
|
|
|
execing. Just call proc_subproc directly and then exit this loop.
|
|
|
|
We're done here. */
|
2004-12-06 08:29:41 +08:00
|
|
|
if (hExeced)
|
2004-11-26 12:15:10 +08:00
|
|
|
{
|
|
|
|
/* execing. no signals available now. */
|
|
|
|
proc_subproc (PROC_CLEARWAIT, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send a SIGCHLD to myself. We do this here, rather than in proc_subproc
|
|
|
|
to avoid the proc_subproc lock since the signal thread will eventually
|
|
|
|
be calling proc_subproc and could unnecessarily block. */
|
|
|
|
sig_send (myself_nowait, si);
|
|
|
|
|
|
|
|
/* If we're just stopped or got a continue signal, keep looping.
|
|
|
|
Otherwise, return this thread to the pool. */
|
|
|
|
if (buf != '\0')
|
|
|
|
sigproc_printf ("looping");
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sigproc_printf ("exiting wait thread for pid %d", pid);
|
2004-12-23 00:59:03 +08:00
|
|
|
vchild.wait_thread = NULL;
|
2004-12-23 22:57:08 +08:00
|
|
|
_my_tls._ctinfo->auto_release (); /* automatically return the cygthread to the cygthread pool */
|
2004-11-26 12:15:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-25 02:31:23 +08:00
|
|
|
bool
|
|
|
|
_pinfo::dup_proc_pipe (HANDLE hProcess)
|
|
|
|
{
|
2005-01-04 22:57:42 +08:00
|
|
|
DWORD flags = DUPLICATE_SAME_ACCESS;
|
|
|
|
/* Grr. Can't set DUPLICATE_CLOSE_SOURCE for exec case because we could be
|
|
|
|
execing a non-cygwin process and we need to set the exit value before the
|
|
|
|
parent sees it. */
|
2005-01-11 23:31:04 +08:00
|
|
|
if (this != myself || is_toplevel_proc)
|
2005-01-04 22:57:42 +08:00
|
|
|
flags |= DUPLICATE_CLOSE_SOURCE;
|
2004-12-25 02:31:23 +08:00
|
|
|
bool res = DuplicateHandle (hMainProc, wr_proc_pipe, hProcess, &wr_proc_pipe,
|
2005-01-04 22:57:42 +08:00
|
|
|
0, FALSE, flags);
|
2005-09-28 21:55:04 +08:00
|
|
|
if (!res && WaitForSingleObject (hProcess, 0) != WAIT_OBJECT_0)
|
2005-10-19 22:19:37 +08:00
|
|
|
system_printf ("DuplicateHandle failed, pid %d, hProcess %p, %E", pid, hProcess);
|
2004-12-25 02:31:23 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wr_proc_pipe_owner = dwProcessId;
|
|
|
|
sigproc_printf ("closed wr_proc_pipe %p for pid %d(%u)", wr_proc_pipe,
|
|
|
|
pid, dwProcessId);
|
2005-09-28 21:55:04 +08:00
|
|
|
res = true;
|
2004-12-25 02:31:23 +08:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-11-26 12:15:10 +08:00
|
|
|
/* function to set up the process pipe and kick off proc_waiter */
|
|
|
|
int
|
|
|
|
pinfo::wait ()
|
|
|
|
{
|
|
|
|
/* FIXME: execed processes should be able to wait for pids that were started
|
|
|
|
by the process which execed them. */
|
2004-12-25 02:31:23 +08:00
|
|
|
if (!CreatePipe (&rd_proc_pipe, &((*this)->wr_proc_pipe), &sec_none_nih, 16))
|
2004-11-26 12:15:10 +08:00
|
|
|
{
|
|
|
|
system_printf ("Couldn't create pipe tracker for pid %d, %E",
|
|
|
|
(*this)->pid);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-25 02:31:23 +08:00
|
|
|
|
|
|
|
if (!(*this)->dup_proc_pipe (hProcess))
|
2004-11-26 12:15:10 +08:00
|
|
|
{
|
2004-12-25 02:31:23 +08:00
|
|
|
system_printf ("Couldn't duplicate pipe topid %d(%p), %E", (*this)->pid, hProcess);
|
2004-11-26 12:15:10 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
preserve (); /* Preserve the shared memory associated with the pinfo */
|
|
|
|
|
2005-01-17 12:12:08 +08:00
|
|
|
waiter_ready = false;
|
2004-11-26 12:15:10 +08:00
|
|
|
/* Fire up a new thread to track the subprocess */
|
2005-10-18 07:27:00 +08:00
|
|
|
cygthread *h = new cygthread (proc_waiter, 0, this, "proc_waiter");
|
2004-11-26 12:15:10 +08:00
|
|
|
if (!h)
|
|
|
|
sigproc_printf ("tracking thread creation failed for pid %d", (*this)->pid);
|
|
|
|
else
|
|
|
|
{
|
2004-12-06 05:29:37 +08:00
|
|
|
wait_thread = h;
|
2004-11-26 12:15:10 +08:00
|
|
|
sigproc_printf ("created tracking thread for pid %d, winpid %p, rd_pipe %p",
|
|
|
|
(*this)->pid, (*this)->dwProcessId, rd_proc_pipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-12-25 02:31:23 +08:00
|
|
|
void
|
|
|
|
_pinfo::sync_proc_pipe ()
|
|
|
|
{
|
|
|
|
if (wr_proc_pipe && wr_proc_pipe != INVALID_HANDLE_VALUE)
|
|
|
|
while (wr_proc_pipe_owner != GetCurrentProcessId ())
|
|
|
|
low_priority_sleep (0);
|
|
|
|
}
|
|
|
|
|
2004-11-26 12:15:10 +08:00
|
|
|
/* function to send a "signal" to the parent when something interesting happens
|
|
|
|
in the child. */
|
2004-12-03 12:46:00 +08:00
|
|
|
bool
|
2004-12-25 02:31:23 +08:00
|
|
|
_pinfo::alert_parent (char sig)
|
2004-11-26 12:15:10 +08:00
|
|
|
{
|
2004-12-03 12:46:00 +08:00
|
|
|
DWORD nb = 0;
|
2005-10-19 22:19:37 +08:00
|
|
|
|
|
|
|
/* Send something to our parent. If the parent has gone away, close the pipe.
|
|
|
|
Don't send if this is an exec stub.
|
|
|
|
|
|
|
|
FIXME: Is there a race here if we run this while another thread is attempting
|
|
|
|
to exec()? */
|
|
|
|
if (wr_proc_pipe == INVALID_HANDLE_VALUE || !myself->wr_proc_pipe || hExeced)
|
2004-12-03 12:46:00 +08:00
|
|
|
/* no parent */;
|
2004-11-26 12:15:10 +08:00
|
|
|
else
|
|
|
|
{
|
2004-12-25 02:31:23 +08:00
|
|
|
sync_proc_pipe ();
|
|
|
|
if (WriteFile (wr_proc_pipe, &sig, 1, &nb, NULL))
|
|
|
|
/* all is well */;
|
|
|
|
else if (GetLastError () != ERROR_BROKEN_PIPE)
|
|
|
|
debug_printf ("sending %d notification to parent failed, %E", sig);
|
|
|
|
else
|
|
|
|
{
|
2005-01-17 12:12:08 +08:00
|
|
|
ppid = 1;
|
2004-12-25 02:31:23 +08:00
|
|
|
HANDLE closeit = wr_proc_pipe;
|
|
|
|
wr_proc_pipe = INVALID_HANDLE_VALUE;
|
|
|
|
CloseHandle (closeit);
|
|
|
|
}
|
2004-11-26 12:15:10 +08:00
|
|
|
}
|
2004-12-03 12:46:00 +08:00
|
|
|
return (bool) nb;
|
2004-11-26 12:15:10 +08:00
|
|
|
}
|
|
|
|
|
2000-08-26 11:48:37 +08:00
|
|
|
void
|
|
|
|
pinfo::release ()
|
|
|
|
{
|
2005-01-23 05:17:53 +08:00
|
|
|
if (procinfo)
|
2000-08-26 11:48:37 +08:00
|
|
|
{
|
2005-02-27 04:50:25 +08:00
|
|
|
void *unmap_procinfo = procinfo;
|
2000-10-20 12:20:21 +08:00
|
|
|
procinfo = NULL;
|
2005-02-27 04:50:25 +08:00
|
|
|
UnmapViewOfFile (unmap_procinfo);
|
2005-01-23 05:17:53 +08:00
|
|
|
}
|
|
|
|
if (h)
|
|
|
|
{
|
2005-02-27 04:50:25 +08:00
|
|
|
HANDLE close_h = h;
|
2000-08-26 11:48:37 +08:00
|
|
|
h = NULL;
|
2005-02-27 04:50:25 +08:00
|
|
|
ForceCloseHandle1 (close_h, pinfo_shared_handle);
|
2000-08-26 11:48:37 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* DOCTOOL-START
|
|
|
|
|
|
|
|
<sect1 id="func-cygwin-winpid-to-pid">
|
|
|
|
<title>cygwin_winpid_to_pid</title>
|
|
|
|
|
2004-02-23 07:21:20 +08:00
|
|
|
<funcsynopsis><funcprototype>
|
2000-02-18 03:38:33 +08:00
|
|
|
<funcdef>extern "C" pid_t
|
|
|
|
<function>cygwin_winpid_to_pid</function>
|
|
|
|
</funcdef>
|
|
|
|
<paramdef>int <parameter>winpid</parameter></paramdef>
|
2004-02-23 07:21:20 +08:00
|
|
|
</funcprototype></funcsynopsis>
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
<para>Given a windows pid, converts to the corresponding Cygwin
|
|
|
|
pid, if any. Returns -1 if windows pid does not correspond to
|
|
|
|
a cygwin pid.</para>
|
|
|
|
<example>
|
|
|
|
<title>Example use of cygwin_winpid_to_pid</title>
|
|
|
|
<programlisting>
|
|
|
|
extern "C" cygwin_winpid_to_pid (int winpid);
|
|
|
|
pid_t mypid;
|
|
|
|
mypid = cygwin_winpid_to_pid (windows_pid);
|
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</sect1>
|
|
|
|
|
|
|
|
DOCTOOL-END */
|
|
|
|
|
|
|
|
extern "C" pid_t
|
|
|
|
cygwin_winpid_to_pid (int winpid)
|
|
|
|
{
|
2002-01-29 10:02:03 +08:00
|
|
|
pinfo p (cygwin_pid (winpid));
|
2000-07-30 00:24:59 +08:00
|
|
|
if (p)
|
|
|
|
return p->pid;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
set_errno (ESRCH);
|
|
|
|
return (pid_t) -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <tlhelp32.h>
|
|
|
|
|
2000-11-02 13:25:56 +08:00
|
|
|
#define slop_pidlist 200
|
|
|
|
#define size_pidlist(i) (sizeof (pidlist[0]) * ((i) + 1))
|
2000-11-05 14:42:23 +08:00
|
|
|
#define size_pinfolist(i) (sizeof (pinfolist[0]) * ((i) + 1))
|
2005-12-22 11:16:36 +08:00
|
|
|
class _onreturn
|
|
|
|
{
|
|
|
|
HANDLE& h;
|
|
|
|
HANDLE dummy_handle;
|
|
|
|
public:
|
|
|
|
~_onreturn ()
|
|
|
|
{
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
CloseHandle (h);
|
|
|
|
h = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void no_close_p_handle () {h = dummy_handle;}
|
|
|
|
_onreturn (): h (dummy_handle), dummy_handle (NULL) {}
|
|
|
|
void set (HANDLE& _h) {h = _h;}
|
|
|
|
};
|
2000-11-02 13:25:56 +08:00
|
|
|
|
2000-11-05 14:42:23 +08:00
|
|
|
inline void
|
|
|
|
winpids::add (DWORD& nelem, bool winpid, DWORD pid)
|
|
|
|
{
|
2005-12-22 11:16:36 +08:00
|
|
|
_onreturn onreturn;
|
|
|
|
bool perform_copy = make_copy;
|
2000-11-05 14:42:23 +08:00
|
|
|
pid_t cygpid = cygwin_pid (pid);
|
2005-12-22 11:16:36 +08:00
|
|
|
|
2000-11-05 14:42:23 +08:00
|
|
|
if (nelem >= npidlist)
|
|
|
|
{
|
|
|
|
npidlist += slop_pidlist;
|
2001-10-14 01:23:35 +08:00
|
|
|
pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist + 1));
|
|
|
|
pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist + 1));
|
2000-11-05 14:42:23 +08:00
|
|
|
}
|
|
|
|
|
2005-12-13 02:43:31 +08:00
|
|
|
pinfo& p = pinfolist[nelem];
|
|
|
|
|
2005-12-22 11:16:36 +08:00
|
|
|
/* Open a the process to prevent a subsequent exit from invalidating the
|
|
|
|
shared memory region. */
|
|
|
|
p.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, false, pid);
|
|
|
|
|
2005-12-13 02:43:31 +08:00
|
|
|
p.init (cygpid, PID_NOREDIR | pinfo_access, NULL);
|
2005-12-22 11:16:36 +08:00
|
|
|
|
|
|
|
/* If we couldn't open the process then we don't have rights to it and should
|
|
|
|
make a copy of the shared memory area if it exists (it may not).
|
|
|
|
Otherwise, if p is "false" then we couldn't open the shared memory region
|
|
|
|
for the given pid, so close the handle to that process since we don't need to
|
|
|
|
protect this pid while the shared memory is open.
|
|
|
|
If p is true and we've opened the handle then things look good but we want
|
|
|
|
to track the handle to eventually close it if things fall apart subsequently.
|
|
|
|
*/
|
|
|
|
if (!p.hProcess)
|
|
|
|
perform_copy = true;
|
|
|
|
else if (!p)
|
|
|
|
CloseHandle (p.hProcess);
|
|
|
|
else
|
|
|
|
onreturn.set (p.hProcess);
|
|
|
|
|
|
|
|
/* If we're just looking for winpids then don't do any special cygwin "stuff* */
|
2000-11-05 14:42:23 +08:00
|
|
|
if (winpid)
|
2003-09-17 09:15:56 +08:00
|
|
|
goto out;
|
2000-11-05 14:42:23 +08:00
|
|
|
|
2005-12-22 11:16:36 +08:00
|
|
|
/* !p means that we couldn't find shared memory for this pid. Probably means
|
|
|
|
that it isn't a cygwin process. */
|
2005-12-13 02:43:31 +08:00
|
|
|
if (!p)
|
2003-09-17 09:15:56 +08:00
|
|
|
{
|
|
|
|
if (!pinfo_access)
|
|
|
|
return;
|
2005-12-13 02:43:31 +08:00
|
|
|
p.init (cygpid, PID_NOREDIR, NULL);
|
|
|
|
if (!p)
|
2003-09-17 09:15:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scan list of previously recorded pids to make sure that this pid hasn't
|
|
|
|
shown up before. This can happen when a process execs. */
|
|
|
|
for (unsigned i = 0; i < nelem; i++)
|
2005-12-13 02:43:31 +08:00
|
|
|
if (pinfolist[i]->pid == p->pid)
|
2003-09-17 09:15:56 +08:00
|
|
|
{
|
2005-12-13 02:43:31 +08:00
|
|
|
if ((_pinfo *) p != (_pinfo *) myself)
|
|
|
|
p.release ();
|
2003-09-17 09:15:56 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2005-12-22 11:16:36 +08:00
|
|
|
/* Exit here.
|
|
|
|
|
|
|
|
If p is "false" then, eventually any opened process handle will be closed and
|
|
|
|
the function will exit without adding anything to the pid list.
|
|
|
|
|
|
|
|
If p is "true" then we've discovered a cygwin process.
|
|
|
|
|
|
|
|
Handle "myself" differently. Don't copy it and close/zero the handle we
|
|
|
|
just opened to it.
|
|
|
|
If not performing a copy, then keep the process handle open for the duration
|
|
|
|
of the life of the procinfo region to potential races when a new process uses
|
|
|
|
this pid.
|
|
|
|
Otherwise, malloc some memory for a copy of the shared memory.
|
|
|
|
|
|
|
|
If the malloc failed, then "oh well". Just keep the shared memory around
|
|
|
|
and eventually close the handle when the winpids goes out of scope.
|
|
|
|
|
|
|
|
If malloc succeeds, copy the procinfo we just grabbed into the new region,
|
|
|
|
release the shared memory and allow the handle to be closed when this
|
|
|
|
function returns.
|
|
|
|
|
|
|
|
Oh, and add the pid to the list and bump the number of elements. */
|
|
|
|
|
|
|
|
if (p)
|
2005-12-13 02:43:31 +08:00
|
|
|
{
|
2005-12-22 11:16:36 +08:00
|
|
|
if (p == (_pinfo *) myself)
|
|
|
|
/* handle specially. Close the handle but (eventually) don't
|
|
|
|
deallocate procinfo in release call */;
|
|
|
|
else if (!perform_copy)
|
|
|
|
onreturn.no_close_p_handle (); /* Don't close the handle until release */
|
|
|
|
else
|
2005-12-13 02:43:31 +08:00
|
|
|
{
|
2005-12-22 11:16:36 +08:00
|
|
|
_pinfo *pnew = (_pinfo *) malloc (sizeof (*p.procinfo));
|
|
|
|
if (!pnew)
|
|
|
|
onreturn.no_close_p_handle ();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*pnew = *p.procinfo;
|
|
|
|
if ((_pinfo *) p != (_pinfo *) myself)
|
|
|
|
p.release ();
|
|
|
|
p.procinfo = pnew;
|
|
|
|
p.destroy = false;
|
|
|
|
}
|
2005-12-13 02:43:31 +08:00
|
|
|
}
|
|
|
|
}
|
2005-12-22 13:26:14 +08:00
|
|
|
if (p || winpid)
|
|
|
|
pidlist[nelem++] = pid;
|
2000-11-05 14:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
|
|
|
winpids::enumNT (bool winpid)
|
2000-11-02 13:25:56 +08:00
|
|
|
{
|
2001-09-06 12:41:59 +08:00
|
|
|
static DWORD szprocs;
|
2000-11-02 13:25:56 +08:00
|
|
|
static SYSTEM_PROCESSES *procs;
|
|
|
|
|
|
|
|
DWORD nelem = 0;
|
|
|
|
if (!szprocs)
|
2001-10-14 01:23:35 +08:00
|
|
|
procs = (SYSTEM_PROCESSES *) malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs)));
|
2000-11-02 13:25:56 +08:00
|
|
|
|
|
|
|
NTSTATUS res;
|
|
|
|
for (;;)
|
|
|
|
{
|
2002-05-30 15:45:30 +08:00
|
|
|
res = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
|
2000-11-02 13:25:56 +08:00
|
|
|
procs, szprocs, NULL);
|
|
|
|
if (res == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (res == STATUS_INFO_LENGTH_MISMATCH)
|
2001-04-29 10:54:36 +08:00
|
|
|
procs = (SYSTEM_PROCESSES *) realloc (procs, szprocs += 200 * sizeof (*procs));
|
2000-11-02 13:25:56 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
system_printf ("error %p reading system process information", res);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSTEM_PROCESSES *px = procs;
|
|
|
|
for (;;)
|
|
|
|
{
|
2000-11-04 13:54:57 +08:00
|
|
|
if (px->ProcessId)
|
2000-11-05 14:42:23 +08:00
|
|
|
add (nelem, winpid, px->ProcessId);
|
|
|
|
if (!px->NextEntryDelta)
|
|
|
|
break;
|
2000-11-02 13:25:56 +08:00
|
|
|
px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nelem;
|
|
|
|
}
|
|
|
|
|
2000-11-05 14:42:23 +08:00
|
|
|
DWORD
|
|
|
|
winpids::enum9x (bool winpid)
|
2000-07-30 00:24:59 +08:00
|
|
|
{
|
2000-11-02 13:25:56 +08:00
|
|
|
DWORD nelem = 0;
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2001-06-12 01:57:10 +08:00
|
|
|
HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
|
2000-07-30 00:24:59 +08:00
|
|
|
if (!h)
|
2000-11-02 13:25:56 +08:00
|
|
|
{
|
|
|
|
system_printf ("Couldn't create process snapshot, %E");
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-30 00:24:59 +08:00
|
|
|
|
|
|
|
PROCESSENTRY32 proc;
|
|
|
|
proc.dwSize = sizeof (proc);
|
2000-11-02 13:25:56 +08:00
|
|
|
|
2001-06-12 01:57:10 +08:00
|
|
|
if (Process32First (h, &proc))
|
2000-07-30 00:24:59 +08:00
|
|
|
do
|
2000-11-02 13:25:56 +08:00
|
|
|
{
|
2000-11-05 14:42:23 +08:00
|
|
|
if (proc.th32ProcessID)
|
|
|
|
add (nelem, winpid, proc.th32ProcessID);
|
2000-11-02 13:25:56 +08:00
|
|
|
}
|
2001-06-12 01:57:10 +08:00
|
|
|
while (Process32Next (h, &proc));
|
2000-11-02 13:25:56 +08:00
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
CloseHandle (h);
|
2000-11-02 13:25:56 +08:00
|
|
|
return nelem;
|
2000-07-30 00:24:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2002-11-29 15:05:26 +08:00
|
|
|
winpids::set (bool winpid)
|
2000-07-30 00:24:59 +08:00
|
|
|
{
|
2004-02-12 11:01:58 +08:00
|
|
|
__malloc_lock ();
|
2000-11-05 14:42:23 +08:00
|
|
|
npids = (this->*enum_processes) (winpid);
|
2001-10-14 01:23:35 +08:00
|
|
|
if (pidlist)
|
|
|
|
pidlist[npids] = 0;
|
2004-02-12 11:01:58 +08:00
|
|
|
__malloc_unlock ();
|
2000-07-30 00:24:59 +08:00
|
|
|
}
|
|
|
|
|
2000-11-05 14:42:23 +08:00
|
|
|
DWORD
|
|
|
|
winpids::enum_init (bool winpid)
|
2000-07-30 00:24:59 +08:00
|
|
|
{
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (wincap.is_winnt ())
|
2000-11-05 14:42:23 +08:00
|
|
|
enum_processes = &winpids::enumNT;
|
2000-07-30 00:24:59 +08:00
|
|
|
else
|
2001-06-12 01:57:10 +08:00
|
|
|
enum_processes = &winpids::enum9x;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-11-05 14:42:23 +08:00
|
|
|
return (this->*enum_processes) (winpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
winpids::release ()
|
|
|
|
{
|
2005-12-13 02:43:31 +08:00
|
|
|
_pinfo *p;
|
2000-11-05 14:42:23 +08:00
|
|
|
for (unsigned i = 0; i < npids; i++)
|
2005-12-22 11:16:36 +08:00
|
|
|
if (pinfolist[i] == (_pinfo *) myself)
|
|
|
|
continue;
|
2005-12-22 13:11:44 +08:00
|
|
|
else if (pinfolist[i].hProcess)
|
2005-12-22 11:16:36 +08:00
|
|
|
{
|
|
|
|
if (pinfolist[i])
|
|
|
|
pinfolist[i].release ();
|
2005-12-22 13:11:44 +08:00
|
|
|
CloseHandle (pinfolist[i].hProcess);
|
2005-12-22 11:16:36 +08:00
|
|
|
}
|
|
|
|
else if ((p = pinfolist[i]))
|
|
|
|
{
|
|
|
|
pinfolist[i].procinfo = NULL;
|
|
|
|
free (p);
|
|
|
|
}
|
2000-11-05 14:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
winpids::~winpids ()
|
|
|
|
{
|
|
|
|
if (npidlist)
|
|
|
|
{
|
|
|
|
release ();
|
|
|
|
free (pidlist);
|
|
|
|
free (pinfolist);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|