2000-09-08 04:56:55 +02:00
|
|
|
/* pinfo.h: process table info
|
|
|
|
|
|
|
|
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-07-29 18:24:59 +02:00
|
|
|
|
2012-01-11 20:07:11 +01:00
|
|
|
#pragma once
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
#include <sys/resource.h>
|
2000-10-17 01:55:58 +02:00
|
|
|
#include "thread.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
|
2002-10-30 22:05:18 +01:00
|
|
|
struct commune_result
|
|
|
|
{
|
|
|
|
char *s;
|
2013-04-23 11:44:36 +02:00
|
|
|
DWORD n;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
HANDLE handles[2];
|
2002-10-30 22:05:18 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum picom
|
|
|
|
{
|
2005-09-29 00:56:47 +02:00
|
|
|
PICOM_EXTRASTR = 0x80000000,
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
PICOM_CMDLINE = 1,
|
2007-07-07 19:00:33 +02:00
|
|
|
PICOM_CWD = 2,
|
|
|
|
PICOM_ROOT = 3,
|
|
|
|
PICOM_FDS = 4,
|
|
|
|
PICOM_FD = 5,
|
2017-01-10 16:03:09 +01:00
|
|
|
PICOM_PIPE_FHANDLER = 6,
|
|
|
|
PICOM_ENVIRON = 7
|
2002-10-30 22:05:18 +01:00
|
|
|
};
|
|
|
|
|
2011-05-28 20:17:09 +02:00
|
|
|
#define EXITCODE_SET 0x8000000
|
|
|
|
#define EXITCODE_NOSET 0x4000000
|
|
|
|
#define EXITCODE_RETRY 0x2000000
|
|
|
|
#define EXITCODE_OK 0x1000000
|
|
|
|
#define EXITCODE_FORK_FAILED 0x0800000
|
2004-12-27 01:35:19 +01:00
|
|
|
|
2005-02-06 12:15:29 +01:00
|
|
|
class fhandler_pipe;
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
class _pinfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/* Cygwin pid */
|
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
/* Various flags indicating the state of the process. See PID_
|
2008-03-27 02:50:40 +01:00
|
|
|
constants in <sys/cygwin.h>. */
|
2000-07-29 18:24:59 +02:00
|
|
|
DWORD process_state;
|
|
|
|
|
2013-12-18 05:28:46 +01:00
|
|
|
pid_t ppid; /* Parent process id. */
|
|
|
|
|
2004-11-26 05:15:10 +01:00
|
|
|
DWORD exitcode; /* set when process exits */
|
2000-07-29 18:24:59 +02:00
|
|
|
|
2004-11-26 05:15:10 +01:00
|
|
|
#define PINFO_REDIR_SIZE ((char *) &myself.procinfo->exitcode - (char *) myself.procinfo)
|
2000-10-09 04:53:44 +02:00
|
|
|
|
2004-11-26 05:15:10 +01:00
|
|
|
/* > 0 if started by a cygwin process */
|
|
|
|
DWORD cygstarted;
|
2000-11-06 07:36:32 +01:00
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
/* dwProcessId contains the processid used for sending signals. It
|
2005-09-29 00:56:47 +02:00
|
|
|
will be reset in a child process when it is capable of receiving
|
|
|
|
signals. */
|
2000-07-29 18:24:59 +02:00
|
|
|
DWORD dwProcessId;
|
|
|
|
|
2011-05-24 12:03:34 +02:00
|
|
|
/* Used to spawn a child for fork(), among other things. The other
|
|
|
|
members of _pinfo take only a bit over 200 bytes. So cut off a
|
|
|
|
couple of bytes from progname to allow the _pinfo structure not
|
|
|
|
to exceed 64K. Otherwise it blocks another 64K block of VM for
|
|
|
|
the process. */
|
|
|
|
WCHAR progname[NT_MAX_PATH - 512];
|
2000-07-29 18:24:59 +02:00
|
|
|
|
|
|
|
/* User information.
|
|
|
|
The information is derived from the GetUserName system call,
|
|
|
|
with the name looked up in /etc/passwd and assigned a default value
|
|
|
|
if not found. This data resides in the shared data area (allowing
|
|
|
|
tasks to store whatever they want here) so it's for informational
|
|
|
|
purposes only. */
|
2013-04-23 11:44:36 +02:00
|
|
|
uid_t uid; /* User ID */
|
|
|
|
gid_t gid; /* Group ID */
|
|
|
|
pid_t pgid; /* Process group ID */
|
|
|
|
pid_t sid; /* Session ID */
|
|
|
|
int ctty; /* Control tty */
|
2000-10-25 05:54:50 +02:00
|
|
|
bool has_pgid_children;/* True if we've forked or spawned children with our GID. */
|
2000-07-29 18:24:59 +02:00
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
/* Resources used by process. */
|
|
|
|
long start_time;
|
|
|
|
struct rusage rusage_self;
|
|
|
|
struct rusage rusage_children;
|
2005-01-25 23:45:11 +01:00
|
|
|
int nice;
|
2000-10-15 03:37:07 +02:00
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
/* Non-zero if process was stopped by a signal. */
|
|
|
|
char stopsig;
|
2002-12-12 04:09:38 +01:00
|
|
|
|
2000-10-25 05:54:50 +02:00
|
|
|
inline void set_has_pgid_children ()
|
|
|
|
{
|
|
|
|
if (pgid == pid)
|
|
|
|
has_pgid_children = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void set_has_pgid_children (bool val) {has_pgid_children = val;}
|
|
|
|
|
2005-09-29 00:56:47 +02:00
|
|
|
commune_result commune_request (__uint32_t, ...);
|
2002-10-30 22:05:18 +01:00
|
|
|
bool alive ();
|
2016-01-11 12:35:41 +01:00
|
|
|
fhandler_pipe *pipe_fhandler (int64_t, size_t &);
|
2005-01-31 11:28:55 +01:00
|
|
|
char *fd (int fd, size_t &);
|
|
|
|
char *fds (size_t &);
|
2005-01-29 12:23:07 +01:00
|
|
|
char *root (size_t &);
|
|
|
|
char *cwd (size_t &);
|
2003-03-08 18:56:13 +01:00
|
|
|
char *cmdline (size_t &);
|
2017-01-10 16:03:09 +01:00
|
|
|
char *environ (size_t &);
|
2013-04-23 11:44:36 +02:00
|
|
|
char *win_heap_info (size_t &);
|
2011-10-16 00:37:30 +02:00
|
|
|
bool set_ctty (class fhandler_termios *, int);
|
2004-12-24 19:31:23 +01:00
|
|
|
bool alert_parent (char);
|
2013-01-21 05:34:52 +01:00
|
|
|
int __reg2 kill (siginfo_t&);
|
|
|
|
bool __reg1 exists ();
|
2005-11-14 05:28:45 +01:00
|
|
|
const char *_ctty (char *);
|
2002-10-30 22:05:18 +01:00
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
/* signals */
|
|
|
|
HANDLE sendsig;
|
2004-12-05 20:41:26 +01:00
|
|
|
HANDLE exec_sendsig;
|
|
|
|
DWORD exec_dwProcessId;
|
2004-11-26 05:15:10 +01:00
|
|
|
public:
|
2011-11-14 02:29:49 +01:00
|
|
|
friend class pinfo_minimal;
|
2000-07-29 18:24:59 +02:00
|
|
|
};
|
|
|
|
|
2005-10-18 01:27:00 +02:00
|
|
|
DWORD WINAPI commune_process (void *);
|
|
|
|
|
2004-12-03 05:46:00 +01:00
|
|
|
enum parent_alerter
|
|
|
|
{
|
|
|
|
__ALERT_REPARENT = 111, // arbitrary non-signal value
|
|
|
|
__ALERT_ALIVE = 112
|
|
|
|
};
|
|
|
|
|
2011-11-14 02:29:49 +01:00
|
|
|
class pinfo_minimal
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
public:
|
2004-11-26 05:15:10 +01:00
|
|
|
HANDLE hProcess;
|
2011-11-14 02:29:49 +01:00
|
|
|
HANDLE rd_proc_pipe;
|
|
|
|
pinfo_minimal (): h (NULL), hProcess (NULL), rd_proc_pipe (NULL) {}
|
2012-03-21 16:54:50 +01:00
|
|
|
void set_rd_proc_pipe (HANDLE& h) {rd_proc_pipe = h;}
|
2011-11-14 02:29:49 +01:00
|
|
|
friend class pinfo;
|
|
|
|
};
|
|
|
|
|
|
|
|
class pinfo: public pinfo_minimal
|
|
|
|
{
|
|
|
|
bool destroy;
|
|
|
|
_pinfo *procinfo;
|
|
|
|
public:
|
2005-01-17 05:12:08 +01:00
|
|
|
bool waiter_ready;
|
2004-12-05 22:29:37 +01:00
|
|
|
class cygthread *wait_thread;
|
2011-11-14 02:29:49 +01:00
|
|
|
|
2013-01-21 05:34:52 +01:00
|
|
|
void __reg3 init (pid_t, DWORD, HANDLE);
|
2011-11-14 02:29:49 +01:00
|
|
|
pinfo (_pinfo *x = NULL): pinfo_minimal (), destroy (false), procinfo (x),
|
|
|
|
waiter_ready (false), wait_thread (NULL) {}
|
|
|
|
pinfo (pid_t n, DWORD flag = 0): pinfo_minimal (), destroy (false),
|
|
|
|
procinfo (NULL), waiter_ready (false),
|
2011-12-18 00:39:47 +01:00
|
|
|
wait_thread (NULL)
|
2011-11-14 02:29:49 +01:00
|
|
|
{
|
|
|
|
init (n, flag, NULL);
|
|
|
|
}
|
|
|
|
pinfo (HANDLE, pinfo_minimal&, pid_t);
|
2013-01-21 05:34:52 +01:00
|
|
|
void __reg2 thisproc (HANDLE);
|
2011-11-14 02:29:49 +01:00
|
|
|
inline void _pinfo_release ();
|
2000-08-26 05:48:37 +02:00
|
|
|
void release ();
|
2013-01-21 05:34:52 +01:00
|
|
|
bool __reg1 wait ();
|
2000-07-29 18:24:59 +02:00
|
|
|
~pinfo ()
|
|
|
|
{
|
2000-08-26 05:48:37 +02:00
|
|
|
if (destroy && procinfo)
|
2000-07-29 18:24:59 +02:00
|
|
|
release ();
|
|
|
|
}
|
2013-01-21 05:34:52 +01:00
|
|
|
void __reg2 exit (DWORD n) __attribute__ ((noreturn, ));
|
|
|
|
void __reg1 maybe_set_exit_code_from_windows ();
|
|
|
|
void __reg2 set_exit_code (DWORD n);
|
2000-08-26 05:48:37 +02:00
|
|
|
_pinfo *operator -> () const {return procinfo;}
|
|
|
|
int operator == (pinfo *x) const {return x->procinfo == procinfo;}
|
|
|
|
int operator == (pinfo &x) const {return x.procinfo == procinfo;}
|
2003-12-17 23:47:32 +01:00
|
|
|
int operator == (_pinfo *x) const {return x == procinfo;}
|
2000-08-26 05:48:37 +02:00
|
|
|
int operator == (void *x) const {return procinfo == x;}
|
|
|
|
_pinfo *operator * () const {return procinfo;}
|
|
|
|
operator _pinfo * () const {return procinfo;}
|
2013-04-23 11:44:36 +02:00
|
|
|
int operator !() const {return !procinfo;}
|
2004-11-26 05:15:10 +01:00
|
|
|
void preserve () { destroy = false; }
|
2011-11-14 02:29:49 +01:00
|
|
|
void allow_remove () { destroy = true; }
|
2012-01-11 20:07:11 +01:00
|
|
|
#ifndef SIG_BAD_MASK // kludge to ensure that sigproc.h included
|
|
|
|
// int reattach () {system_printf ("reattach is not here"); return 0;}
|
|
|
|
// int remember (bool) {system_printf ("remember is not here"); return 0;}
|
2002-08-19 16:59:27 +02:00
|
|
|
#else
|
2011-11-04 18:07:21 +01:00
|
|
|
int reattach ()
|
2011-10-26 21:42:39 +02:00
|
|
|
{
|
2013-04-23 11:44:36 +02:00
|
|
|
int res = proc_subproc (PROC_REATTACH_CHILD, (uintptr_t) this);
|
2011-11-04 18:07:21 +01:00
|
|
|
destroy = res ? false : true;
|
|
|
|
return res;
|
2011-10-26 21:42:39 +02:00
|
|
|
}
|
2004-12-23 15:57:08 +01:00
|
|
|
int remember (bool detach)
|
2002-08-19 16:59:27 +02:00
|
|
|
{
|
2004-12-23 15:57:08 +01:00
|
|
|
int res = proc_subproc (detach ? PROC_DETACHED_CHILD : PROC_ADDCHILD,
|
2013-04-23 11:44:36 +02:00
|
|
|
(uintptr_t) this);
|
2002-08-19 16:59:27 +02:00
|
|
|
destroy = res ? false : true;
|
|
|
|
return res;
|
|
|
|
}
|
2002-06-02 08:07:01 +02:00
|
|
|
#endif
|
2000-08-24 06:07:50 +02:00
|
|
|
HANDLE shared_handle () {return h;}
|
2005-02-11 16:24:15 +01:00
|
|
|
void set_acl ();
|
2004-12-24 19:31:23 +01:00
|
|
|
friend class _pinfo;
|
2005-12-12 19:43:31 +01:00
|
|
|
friend class winpids;
|
2013-03-29 17:19:11 +01:00
|
|
|
private:
|
|
|
|
DWORD status_exit (DWORD);
|
2000-07-29 18:24:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define ISSTATE(p, f) (!!((p)->process_state & f))
|
|
|
|
#define NOTSTATE(p, f) (!((p)->process_state & f))
|
|
|
|
|
|
|
|
class winpids
|
|
|
|
{
|
2005-12-12 19:43:31 +01:00
|
|
|
bool make_copy;
|
2000-11-02 06:25:56 +01:00
|
|
|
DWORD npidlist;
|
2005-12-12 19:43:31 +01:00
|
|
|
DWORD *pidlist;
|
2000-11-05 07:42:23 +01:00
|
|
|
pinfo *pinfolist;
|
2003-09-17 03:15:56 +02:00
|
|
|
DWORD pinfo_access; // access type for pinfo open
|
2007-02-22 11:54:47 +01:00
|
|
|
DWORD enum_processes (bool winpid);
|
2000-11-05 07:42:23 +01:00
|
|
|
DWORD enum_init (bool winpid);
|
|
|
|
void add (DWORD& nelem, bool, DWORD pid);
|
2000-07-29 18:24:59 +02:00
|
|
|
public:
|
|
|
|
DWORD npids;
|
2005-12-12 19:43:31 +01:00
|
|
|
inline void reset () { release (); npids = 0;}
|
2002-11-29 08:05:26 +01:00
|
|
|
void set (bool winpid);
|
2007-02-22 11:54:47 +01:00
|
|
|
winpids (): make_copy (true) {}
|
|
|
|
winpids (DWORD acc): make_copy (false), npidlist (0), pidlist (NULL),
|
|
|
|
pinfolist (NULL), pinfo_access (acc), npids (0)
|
2003-09-17 03:15:56 +02:00
|
|
|
{
|
|
|
|
set (0);
|
|
|
|
}
|
2000-11-05 07:42:23 +01:00
|
|
|
inline DWORD& winpid (int i) const {return pidlist[i];}
|
|
|
|
inline _pinfo *operator [] (int i) const {return (_pinfo *) pinfolist[i];}
|
|
|
|
~winpids ();
|
|
|
|
void release ();
|
2000-07-29 18:24:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
extern __inline pid_t
|
|
|
|
cygwin_pid (pid_t pid)
|
|
|
|
{
|
2007-02-22 19:01:13 +01:00
|
|
|
return pid;
|
2000-07-29 18:24:59 +02:00
|
|
|
}
|
2000-08-24 06:07:50 +02:00
|
|
|
|
2000-10-17 01:55:58 +02:00
|
|
|
void __stdcall pinfo_init (char **, int);
|
2000-08-22 07:10:20 +02:00
|
|
|
extern pinfo myself;
|
2000-09-08 04:56:55 +02:00
|
|
|
|
2011-05-05 21:43:04 +02:00
|
|
|
/* Helper class to allow convenient setting and unsetting a process_state
|
|
|
|
flag in myself. This is used in certain fhandler read/write methods
|
|
|
|
to set the PID_TTYIN/PID_TTYOU flags in myself->process_state. */
|
|
|
|
class push_process_state
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int flag;
|
|
|
|
public:
|
|
|
|
push_process_state (int add_flag)
|
|
|
|
{
|
|
|
|
flag = add_flag;
|
|
|
|
myself->process_state |= flag;
|
|
|
|
}
|
|
|
|
void pop () { myself->process_state &= ~(flag); }
|
|
|
|
~push_process_state () { pop (); }
|
|
|
|
};
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
#define _P_VFORK 0
|
2003-09-20 02:31:13 +02:00
|
|
|
#define _P_SYSTEM 512
|
2011-11-14 02:29:49 +01:00
|
|
|
/* Add this flag in calls to child_info_spawn::worker if the calling function
|
|
|
|
is one of 'p' type functions: execlp, execvp, spawnlp, spawnvp. Per POSIX,
|
|
|
|
only these p-type functions fall back to call /bin/sh if the file is not a
|
2011-01-20 12:09:21 +01:00
|
|
|
binary. The setting of _P_PATH_TYPE_EXEC is used as a bool value in
|
|
|
|
av::fixup to decide if the file should be evaluated as a script, or if
|
|
|
|
ENOEXEC should be returned. */
|
|
|
|
#define _P_PATH_TYPE_EXEC 0x1000
|
|
|
|
|
|
|
|
/* Helper macro to mask actual mode and drop additional flags defined above. */
|
|
|
|
#define _P_MODE(x) ((x) & 0xfff)
|
2003-09-20 02:31:13 +02:00
|
|
|
|
2005-11-14 05:28:45 +01:00
|
|
|
#define __ctty() _ctty ((char *) alloca (sizeof ("ctty /dev/tty") + 20))
|
|
|
|
#define myctty() myself->__ctty ()
|
|
|
|
|
2000-09-08 04:56:55 +02:00
|
|
|
/* For mmaps across fork(). */
|
2002-03-11 18:57:22 +01:00
|
|
|
int __stdcall fixup_mmaps_after_fork (HANDLE parent);
|
2002-02-28 15:30:38 +01:00
|
|
|
/* for shm areas across fork (). */
|
|
|
|
int __stdcall fixup_shms_after_fork ();
|
2000-09-08 04:56:55 +02:00
|
|
|
|
|
|
|
void __stdcall fill_rusage (struct rusage *, HANDLE);
|
|
|
|
void __stdcall add_rusage (struct rusage *, struct rusage *);
|