2000-02-17 20:38:33 +01:00
|
|
|
/* pinfo.cc: process table support
|
|
|
|
|
2006-01-02 14:01:42 +01:00
|
|
|
Copyright 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
|
2011-04-18 13:26:37 +02:00
|
|
|
2006, 2007, 2008, 2009, 2010, 2011 Red Hat, Inc.
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2008-04-07 18:15:45 +02:00
|
|
|
#include "miscfuncs.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <stdlib.h>
|
2005-01-12 23:40:46 +01:00
|
|
|
#include "cygerrno.h"
|
2001-07-26 21:22:24 +02:00
|
|
|
#include "security.h"
|
2001-10-01 06:10:07 +02:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 02:37:18 +02:00
|
|
|
#include "fhandler.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "dtable.h"
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-08 04:56:55 +02:00
|
|
|
#include "perprocess.h"
|
|
|
|
#include "environ.h"
|
2000-10-15 03:37:07 +02:00
|
|
|
#include <assert.h>
|
2000-11-02 06:25:56 +01:00
|
|
|
#include "ntdll.h"
|
2002-10-15 09:03:45 +02:00
|
|
|
#include "shared_info.h"
|
2003-09-16 05:39:55 +02:00
|
|
|
#include "cygheap.h"
|
2004-02-12 04:01:58 +01:00
|
|
|
#include "cygmalloc.h"
|
2004-02-13 20:34:32 +01:00
|
|
|
#include "cygtls.h"
|
2008-03-07 12:24:51 +01:00
|
|
|
#include "tls_pbuf.h"
|
2004-12-03 05:46:00 +01:00
|
|
|
#include "child_info.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2008-12-19 20:09:51 +01:00
|
|
|
class pinfo_basic: public _pinfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
pinfo_basic();
|
|
|
|
};
|
|
|
|
|
|
|
|
pinfo_basic::pinfo_basic()
|
|
|
|
{
|
|
|
|
pid = dwProcessId = GetCurrentProcessId ();
|
2010-05-18 16:30:51 +02:00
|
|
|
GetModuleFileNameW (NULL, progname, sizeof (progname));
|
2008-12-19 20:09:51 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2008-12-19 20:09:51 +01:00
|
|
|
pinfo_basic myself_initial NO_COPY;
|
|
|
|
|
|
|
|
pinfo NO_COPY myself (static_cast<_pinfo *> (&myself_initial)); // Avoid myself != NULL checks
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2005-01-11 16:31:04 +01:00
|
|
|
bool is_toplevel_proc;
|
|
|
|
|
2006-05-22 06:50:54 +02:00
|
|
|
/* Setup the pinfo structure for this process. There may already be a
|
|
|
|
_pinfo for this "pid" if h != NULL. */
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2008-12-31 22:33:34 +01:00
|
|
|
void
|
2008-12-20 18:32:31 +01:00
|
|
|
pinfo::thisproc (HANDLE h)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2008-12-20 18:32:31 +01:00
|
|
|
procinfo = NULL;
|
|
|
|
|
2004-09-12 05:47:57 +02:00
|
|
|
if (!h)
|
2008-12-19 20:09:51 +01:00
|
|
|
cygheap->pid = cygwin_pid (myself_initial.pid);
|
|
|
|
|
2008-12-20 18:32:31 +01:00
|
|
|
init (cygheap->pid, PID_IN_USE, h ?: INVALID_HANDLE_VALUE);
|
|
|
|
procinfo->process_state |= PID_IN_USE;
|
|
|
|
procinfo->dwProcessId = myself_initial.pid;
|
2010-09-01 23:06:36 +02:00
|
|
|
procinfo->sendsig = myself_initial.sendsig;
|
2010-05-18 16:30:51 +02:00
|
|
|
wcscpy (procinfo->progname, myself_initial.progname);
|
2005-12-29 21:46:34 +01:00
|
|
|
strace.hello ();
|
2008-12-20 18:32:31 +01:00
|
|
|
debug_printf ("myself->dwProcessId %u", procinfo->dwProcessId);
|
2004-11-26 05:15:10 +01:00
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
/* here if execed */
|
|
|
|
static pinfo NO_COPY myself_identity;
|
2008-12-20 18:32:31 +01:00
|
|
|
myself_identity.init (cygwin_pid (procinfo->dwProcessId), PID_EXECED, NULL);
|
|
|
|
procinfo->exec_sendsig = NULL;
|
|
|
|
procinfo->exec_dwProcessId = 0;
|
2004-11-26 05:15:10 +01:00
|
|
|
}
|
2006-12-18 22:28:31 +01:00
|
|
|
else if (!child_proc_info) /* child_proc_info is only set when this process
|
|
|
|
was started by another cygwin process */
|
2008-12-20 18:32:31 +01:00
|
|
|
procinfo->start_time = time (NULL); /* Register our starting time. */
|
2004-12-24 19:31:23 +01:00
|
|
|
else if (cygheap->pid_handle)
|
2004-11-26 05:15:10 +01:00
|
|
|
{
|
2004-12-24 19:31:23 +01:00
|
|
|
ForceCloseHandle (cygheap->pid_handle);
|
|
|
|
cygheap->pid_handle = NULL;
|
2004-11-26 05:15:10 +01:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the process table entry for the current task.
|
2002-01-29 03:02:03 +01:00
|
|
|
This is not called for forked tasks, only execed ones. */
|
2000-02-17 20:38:33 +01:00
|
|
|
void __stdcall
|
2000-10-17 01:55:58 +02:00
|
|
|
pinfo_init (char **envp, int envc)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-09-03 06:16:35 +02:00
|
|
|
if (envp)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2000-10-17 01:55:58 +02:00
|
|
|
environ_init (envp, envc);
|
2000-02-17 20:38:33 +01: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. */
|
|
|
|
|
2008-12-20 18:32:31 +01:00
|
|
|
myself.thisproc (NULL);
|
2000-07-29 18:24:59 +02:00
|
|
|
myself->ppid = 1;
|
|
|
|
myself->pgid = myself->sid = myself->pid;
|
2000-02-17 20:38:33 +01: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 14:38:51 +01:00
|
|
|
myself->uid = ILLEGAL_UID;
|
2003-09-13 19:14:15 +02:00
|
|
|
myself->gid = UNKNOWN_GID;
|
2000-10-17 01:55:58 +02:00
|
|
|
environ_init (NULL, 0); /* call after myself has been set up */
|
2009-12-18 21:32:04 +01:00
|
|
|
myself->nice = winprio_to_nice (GetPriorityClass (GetCurrentProcess ()));
|
2005-01-25 23:45:11 +01:00
|
|
|
debug_printf ("Set nice to %d", myself->nice);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
2010-09-01 23:06:36 +02:00
|
|
|
myself->process_state |= PID_ACTIVE;
|
2011-05-05 17:03:54 +02:00
|
|
|
myself->process_state &= ~(PID_INITIALIZING | PID_EXITED | PID_REAPED);
|
2000-02-17 20:38:33 +01:00
|
|
|
debug_printf ("pid %d, pgid %d", myself->pid, myself->pgid);
|
|
|
|
}
|
|
|
|
|
2008-03-27 02:50:40 +01:00
|
|
|
static DWORD
|
|
|
|
status_exit (DWORD x)
|
|
|
|
{
|
|
|
|
const char *find_first_notloaded_dll (path_conv &);
|
|
|
|
switch (x)
|
|
|
|
{
|
|
|
|
case STATUS_DLL_NOT_FOUND:
|
|
|
|
{
|
|
|
|
char posix_prog[NT_MAX_PATH];
|
2010-05-18 16:30:51 +02:00
|
|
|
UNICODE_STRING uc;
|
|
|
|
RtlInitUnicodeString(&uc, myself->progname);
|
|
|
|
path_conv pc (&uc, PC_NOWARN);
|
2008-03-27 02:50:40 +01:00
|
|
|
mount_table->conv_to_posix_path (pc.get_win32 (), posix_prog, 1);
|
|
|
|
small_printf ("%s: error while loading shared libraries: %s: cannot open shared object file: No such file or directory\n",
|
|
|
|
posix_prog, find_first_notloaded_dll (pc));
|
2011-11-05 19:29:51 +01:00
|
|
|
x = 127 << 8;
|
2008-03-27 02:50:40 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-10-07 17:47:38 +02:00
|
|
|
case STATUS_ILLEGAL_DLL_PSEUDO_RELOCATION: /* custom error value */
|
|
|
|
/* We've already printed the error message in pseudo-reloc.c */
|
2011-11-05 19:29:51 +01:00
|
|
|
x = 127 << 8;
|
|
|
|
break;
|
|
|
|
case STATUS_ACCESS_VIOLATION:
|
|
|
|
x = SIGSEGV;
|
2009-10-07 17:47:38 +02:00
|
|
|
break;
|
2011-11-05 19:47:39 +01:00
|
|
|
case STATUS_ILLEGAL_INSTRUCTION:
|
|
|
|
x = SIGILL;
|
|
|
|
break;
|
2008-03-27 02:50:40 +01:00
|
|
|
default:
|
2010-12-12 06:48:29 +01:00
|
|
|
debug_printf ("*** STATUS_%p\n", x);
|
2011-11-05 19:29:51 +01:00
|
|
|
x = 127 << 8;
|
2008-03-27 02:50:40 +01:00
|
|
|
}
|
2011-11-05 19:29:51 +01:00
|
|
|
return EXITCODE_SET | x;
|
2008-03-27 02:50:40 +01:00
|
|
|
}
|
|
|
|
|
2005-01-11 16:31:04 +01:00
|
|
|
# define self (*this)
|
2009-10-06 23:51:17 +02:00
|
|
|
void
|
|
|
|
pinfo::set_exit_code (DWORD x)
|
|
|
|
{
|
|
|
|
if (x >= 0xc0000000UL)
|
2011-11-05 19:29:51 +01:00
|
|
|
self->exitcode = status_exit (x);
|
|
|
|
else
|
|
|
|
self->exitcode = EXITCODE_SET | (sigExeced ?: (x & 0xff) << 8);
|
2009-10-06 23:51:17 +02:00
|
|
|
}
|
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
void
|
2005-01-17 05:12:08 +01:00
|
|
|
pinfo::maybe_set_exit_code_from_windows ()
|
2005-01-11 16:31:04 +01:00
|
|
|
{
|
|
|
|
DWORD x = 0xdeadbeef;
|
|
|
|
DWORD oexitcode = self->exitcode;
|
2005-09-20 04:06:57 +02:00
|
|
|
|
2005-01-16 18:00:27 +01:00
|
|
|
if (hProcess && !(self->exitcode & EXITCODE_SET))
|
2005-01-11 16:31:04 +01:00
|
|
|
{
|
2008-03-27 02:50:40 +01:00
|
|
|
WaitForSingleObject (hProcess, INFINITE); /* just to be safe, in case
|
|
|
|
process hasn't quite exited
|
|
|
|
after closing pipe */
|
2005-01-11 16:31:04 +01:00
|
|
|
GetExitCodeProcess (hProcess, &x);
|
2009-10-06 23:51:17 +02:00
|
|
|
set_exit_code (x);
|
2005-01-11 16:31:04 +01:00
|
|
|
}
|
2005-01-22 22:17:53 +01:00
|
|
|
sigproc_printf ("pid %d, exit value - old %p, windows %p, cygwin %p",
|
|
|
|
self->pid, oexitcode, x, self->exitcode);
|
2005-01-11 16:31:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pinfo::exit (DWORD n)
|
2000-10-15 03:37:07 +02:00
|
|
|
{
|
2005-12-26 20:34:59 +01:00
|
|
|
minimal_printf ("winpid %d, exit %d", GetCurrentProcessId (), n);
|
2005-10-18 01:27:00 +02:00
|
|
|
lock_process until_exit ();
|
2004-02-13 20:34:32 +01:00
|
|
|
cygthread::terminate ();
|
2005-10-18 01:27:00 +02:00
|
|
|
|
2005-01-16 18:00:27 +01:00
|
|
|
if (n != EXITCODE_NOSET)
|
2005-09-13 19:08:54 +02:00
|
|
|
self->exitcode = EXITCODE_SET | n;/* We're really exiting. Record the UNIX exit code. */
|
2005-09-20 04:06:57 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
exit_state = ES_EXEC_EXIT;
|
|
|
|
maybe_set_exit_code_from_windows ();
|
|
|
|
}
|
|
|
|
|
|
|
|
sigproc_terminate (ES_FINAL);
|
2011-05-28 20:17:09 +02:00
|
|
|
if (myself->ctty > 0 && !iscons_dev (myself->ctty))
|
2010-10-23 20:55:01 +02:00
|
|
|
{
|
2010-10-23 20:57:43 +02:00
|
|
|
lock_ttys here;
|
2011-05-28 20:17:09 +02:00
|
|
|
tty *t = cygwin_shared->tty[device::minor(myself->ctty)];
|
2010-10-23 20:55:01 +02:00
|
|
|
if (!t->slave_alive ())
|
|
|
|
t->setpgid (0);
|
|
|
|
}
|
2005-01-11 16:31:04 +01:00
|
|
|
|
|
|
|
/* FIXME: There is a potential race between an execed process and its
|
2005-09-23 05:35:41 +02:00
|
|
|
parent here. I hated to add a mutex just for that, though. */
|
2005-01-11 16:31:04 +01:00
|
|
|
struct rusage r;
|
2009-12-18 21:32:04 +01:00
|
|
|
fill_rusage (&r, GetCurrentProcess ());
|
2005-01-11 16:31:04 +01:00
|
|
|
add_rusage (&self->rusage_self, &r);
|
2005-03-08 15:31:21 +01:00
|
|
|
int exitcode = self->exitcode & 0xffff;
|
|
|
|
if (!self->cygstarted)
|
2006-01-02 04:14:56 +01:00
|
|
|
exitcode = ((exitcode & 0xff) << 8) | ((exitcode >> 8) & 0xff);
|
2005-09-24 01:37:52 +02:00
|
|
|
sigproc_printf ("Calling ExitProcess n %p, exitcode %p", n, exitcode);
|
|
|
|
ExitProcess (exitcode);
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
2005-01-11 16:31:04 +01:00
|
|
|
# undef self
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
void
|
2005-01-22 22:17:53 +01:00
|
|
|
pinfo::init (pid_t n, DWORD flag, HANDLE h0)
|
2000-02-17 20:38:33 +01:00
|
|
|
{
|
2005-04-29 01:59:44 +02:00
|
|
|
shared_locations shloc;
|
2005-01-26 01:15:11 +01:00
|
|
|
h = NULL;
|
2005-03-08 06:05:02 +01:00
|
|
|
if (myself && !(flag & PID_EXECED)
|
|
|
|
&& (n == myself->pid || (DWORD) n == myself->dwProcessId))
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
2000-08-26 05:48:37 +02:00
|
|
|
procinfo = myself;
|
2000-07-29 18:24:59 +02:00
|
|
|
destroy = 0;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2002-10-14 22:25:52 +02:00
|
|
|
void *mapaddr;
|
2005-02-26 21:50:25 +01:00
|
|
|
int createit = flag & (PID_IN_USE | PID_EXECED);
|
2005-01-26 01:15:11 +01:00
|
|
|
DWORD access = FILE_MAP_READ
|
|
|
|
| (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW)
|
|
|
|
? FILE_MAP_WRITE : 0);
|
|
|
|
if (!h0)
|
2005-04-29 01:59:44 +02:00
|
|
|
shloc = (flag & (PID_IN_USE | PID_EXECED)) ? SH_JUSTCREATE : SH_JUSTOPEN;
|
2002-10-14 22:25:52 +02:00
|
|
|
else
|
|
|
|
{
|
2005-04-29 01:59:44 +02:00
|
|
|
shloc = SH_MYSELF;
|
2005-01-26 01:15:11 +01:00
|
|
|
if (h0 == INVALID_HANDLE_VALUE)
|
|
|
|
h0 = NULL;
|
2002-10-14 22:25:52 +02:00
|
|
|
}
|
|
|
|
|
2005-01-26 01:15:11 +01:00
|
|
|
procinfo = NULL;
|
2005-06-07 21:31:42 +02:00
|
|
|
PSECURITY_ATTRIBUTES sa_buf = (PSECURITY_ATTRIBUTES) alloca (1024);
|
2005-04-29 01:59:44 +02:00
|
|
|
PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf, cygheap->user.sid(),
|
|
|
|
well_known_world_sid,
|
|
|
|
FILE_MAP_READ);
|
|
|
|
|
2005-01-26 01:15:11 +01:00
|
|
|
for (int i = 0; i < 20; i++)
|
2000-10-15 03:37:07 +02:00
|
|
|
{
|
2005-04-29 01:59:44 +02:00
|
|
|
DWORD mapsize;
|
|
|
|
if (flag & PID_EXECED)
|
|
|
|
mapsize = PINFO_REDIR_SIZE;
|
|
|
|
else
|
|
|
|
mapsize = sizeof (_pinfo);
|
|
|
|
|
2010-03-09 22:26:55 +01:00
|
|
|
procinfo = (_pinfo *) open_shared (L"cygpid", n, h0, mapsize, &shloc,
|
2005-04-29 01:59:44 +02:00
|
|
|
sec_attribs, access);
|
2005-01-26 01:15:11 +01:00
|
|
|
if (!h0)
|
|
|
|
{
|
2005-04-29 01:59:44 +02:00
|
|
|
if (createit)
|
|
|
|
__seterrno ();
|
|
|
|
return;
|
2000-10-15 03:37:07 +02:00
|
|
|
}
|
2005-01-22 22:17:53 +01:00
|
|
|
|
|
|
|
if (!procinfo)
|
2004-07-24 21:18:58 +02:00
|
|
|
{
|
2005-01-22 22:17:53 +01:00
|
|
|
if (exit_state)
|
2004-07-24 21:18:58 +02:00
|
|
|
return;
|
|
|
|
|
2005-04-29 01:59:44 +02: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 16:33:50 +02:00
|
|
|
debug_printf ("MapViewOfFileEx h0 %p, i %d failed, %E", h0, i);
|
2010-03-13 00:13:48 +01:00
|
|
|
yield ();
|
2005-01-22 22:17:53 +01:00
|
|
|
continue;
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2005-04-29 01:59:44 +02:00
|
|
|
bool created = shloc != SH_JUSTOPEN;
|
|
|
|
|
2001-11-01 22:15:53 +01:00
|
|
|
if ((procinfo->process_state & PID_INITIALIZING) && (flag & PID_NOREDIR)
|
|
|
|
&& cygwin_pid (procinfo->dwProcessId) != procinfo->pid)
|
2000-10-20 06:20:21 +02:00
|
|
|
{
|
2005-01-22 22:17:53 +01:00
|
|
|
set_errno (ESRCH);
|
|
|
|
break;
|
2000-10-20 06:20:21 +02:00
|
|
|
}
|
|
|
|
|
2000-10-15 03:37:07 +02:00
|
|
|
if (procinfo->process_state & PID_EXECED)
|
|
|
|
{
|
2005-02-26 21:50:25 +01:00
|
|
|
assert (i == 0);
|
2000-10-15 03:37:07 +02: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-22 22:17:53 +01:00
|
|
|
|
2005-01-26 01:15:11 +01:00
|
|
|
n = realpid;
|
|
|
|
CloseHandle (h0);
|
|
|
|
h0 = NULL;
|
2005-01-22 22:17:53 +01:00
|
|
|
goto loop;
|
2000-10-15 03:37:07 +02:00
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2005-12-22 04:16:36 +01: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. */
|
2011-05-05 17:03:54 +02:00
|
|
|
if (!created && createit && (procinfo->process_state & (PID_EXITED | PID_REAPED)))
|
2005-09-22 23:10:07 +02:00
|
|
|
{
|
2005-12-22 04:16:36 +01:00
|
|
|
debug_printf ("looping because pid %d, procinfo->pid %d, "
|
2011-05-05 17:03:54 +02:00
|
|
|
"procinfo->dwProcessid %u has PID_EXITED|PID_REAPED set",
|
2005-09-22 23:10:07 +02:00
|
|
|
n, procinfo->pid, procinfo->dwProcessId);
|
|
|
|
goto loop;
|
|
|
|
}
|
2000-10-15 03:37:07 +02:00
|
|
|
|
|
|
|
if (!created)
|
|
|
|
/* nothing */;
|
2000-10-21 06:53:49 +02:00
|
|
|
else if (!(flag & PID_EXECED))
|
2005-01-16 18:00:27 +01:00
|
|
|
procinfo->pid = n;
|
2000-07-29 18:24:59 +02:00
|
|
|
else
|
|
|
|
{
|
2000-08-26 05:48:37 +02:00
|
|
|
procinfo->process_state |= PID_IN_USE | PID_EXECED;
|
2000-11-03 05:27:03 +01:00
|
|
|
procinfo->pid = myself->pid;
|
2000-07-29 18:24:59 +02:00
|
|
|
}
|
2004-11-26 05:15:10 +01:00
|
|
|
|
2005-01-22 22:17:53 +01:00
|
|
|
h = h0; /* Success! */
|
2000-10-15 03:37:07 +02:00
|
|
|
break;
|
2005-01-22 22:17:53 +01:00
|
|
|
|
|
|
|
loop:
|
|
|
|
release ();
|
2005-02-26 21:50:25 +01:00
|
|
|
if (h0)
|
2010-03-13 00:13:48 +01:00
|
|
|
yield ();
|
2005-01-22 22:17:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (h)
|
2005-01-26 01:15:11 +01:00
|
|
|
{
|
|
|
|
destroy = 1;
|
|
|
|
ProtectHandle1 (h, pinfo_shared_handle);
|
|
|
|
}
|
2005-01-22 22:17:53 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
h = h0;
|
|
|
|
release ();
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
}
|
2000-10-09 04:53:44 +02:00
|
|
|
|
2003-09-27 03:58:23 +02:00
|
|
|
void
|
|
|
|
pinfo::set_acl()
|
|
|
|
{
|
2005-06-07 21:31:42 +02:00
|
|
|
PACL acl_buf = (PACL) alloca (1024);
|
2003-09-27 03:58:23 +02:00
|
|
|
SECURITY_DESCRIPTOR sd;
|
2007-07-19 10:36:32 +02:00
|
|
|
NTSTATUS status;
|
2003-11-28 21:55:59 +01:00
|
|
|
|
2005-06-07 21:31:42 +02:00
|
|
|
sec_acl (acl_buf, true, true, cygheap->user.sid (),
|
2003-09-27 03:58:23 +02:00
|
|
|
well_known_world_sid, FILE_MAP_READ);
|
2011-04-28 11:30:36 +02:00
|
|
|
RtlCreateSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
|
2011-04-28 17:54:47 +02:00
|
|
|
status = RtlSetDaclSecurityDescriptor (&sd, TRUE, acl_buf, FALSE);
|
|
|
|
if (!NT_SUCCESS (status))
|
|
|
|
debug_printf ("RtlSetDaclSecurityDescriptor %p", status);
|
2007-07-19 10:36:32 +02:00
|
|
|
else if ((status = NtSetSecurityObject (h, DACL_SECURITY_INFORMATION, &sd)))
|
2011-04-28 17:54:47 +02:00
|
|
|
debug_printf ("NtSetSecurityObject %p", status);
|
2003-09-27 03:58:23 +02:00
|
|
|
}
|
|
|
|
|
2005-11-14 05:28:45 +01:00
|
|
|
const char *
|
|
|
|
_pinfo::_ctty (char *buf)
|
|
|
|
{
|
2011-05-28 20:17:09 +02:00
|
|
|
if (ctty <= 0)
|
2005-11-14 05:28:45 +01:00
|
|
|
strcpy (buf, "no ctty");
|
|
|
|
else
|
2011-05-28 20:17:09 +02:00
|
|
|
{
|
|
|
|
device d;
|
|
|
|
d.parse (ctty);
|
|
|
|
__small_sprintf (buf, "ctty %s", d.name);
|
|
|
|
}
|
2005-11-14 05:28:45 +01:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2011-10-16 00:37:30 +02:00
|
|
|
bool
|
|
|
|
_pinfo::set_ctty (fhandler_termios *fh, int flags)
|
2003-12-07 23:37:12 +01:00
|
|
|
{
|
2011-10-22 18:26:30 +02:00
|
|
|
debug_printf ("fh %p", fh);
|
|
|
|
debug_printf ("tc %p", fh->tc ());
|
|
|
|
if (!this || !fh->tc ()) try_to_debug ();
|
2011-10-16 00:37:30 +02:00
|
|
|
tty_min& tc = *fh->tc ();
|
|
|
|
debug_printf ("old %s, ctty device number %p, tc.ntty device number %p flags & O_NOCTTY %p", __ctty (), ctty, tc.ntty, flags & O_NOCTTY);
|
|
|
|
if (fh && &tc && (ctty <= 0 || ctty == tc.ntty) && !(flags & O_NOCTTY))
|
2003-12-07 23:37:12 +01:00
|
|
|
{
|
2011-10-16 00:37:30 +02:00
|
|
|
ctty = tc.ntty;
|
2011-05-06 00:30:53 +02:00
|
|
|
if (cygheap->ctty != fh->archetype)
|
|
|
|
{
|
2011-05-28 20:17:09 +02:00
|
|
|
debug_printf ("cygheap->ctty %p, archetype %p", cygheap->ctty, fh->archetype);
|
2011-05-06 00:30:53 +02:00
|
|
|
if (!cygheap->ctty)
|
|
|
|
syscall_printf ("ctty was NULL");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
syscall_printf ("ctty %p, usecount %d", cygheap->ctty,
|
|
|
|
cygheap->ctty->archetype_usecount (0));
|
|
|
|
cygheap->ctty->close ();
|
|
|
|
}
|
|
|
|
cygheap->ctty = (fhandler_termios *) fh->archetype;
|
|
|
|
if (cygheap->ctty)
|
|
|
|
{
|
|
|
|
fh->archetype_usecount (1);
|
|
|
|
/* guard ctty fh */
|
|
|
|
cygheap->manage_console_count ("_pinfo::set_ctty", 1);
|
|
|
|
report_tty_counts (cygheap->ctty, "ctty", "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-06-03 22:32:07 +02:00
|
|
|
lock_ttys here;
|
|
|
|
syscall_printf ("attaching %s sid %d, pid %d, pgid %d, tty->pgid %d, tty->sid %d",
|
2011-10-16 00:37:30 +02:00
|
|
|
__ctty (), sid, pid, pgid, tc.getpgid (), tc.getsid ());
|
2011-06-04 02:12:29 +02:00
|
|
|
if (!cygwin_finished_initializing && !myself->cygstarted
|
2011-10-16 00:37:30 +02:00
|
|
|
&& myself->pgid == myself->pid && tc.getpgid () && tc.getsid ())
|
2011-06-04 02:12:29 +02:00
|
|
|
{
|
2011-10-16 00:37:30 +02:00
|
|
|
myself->pgid = tc.getpgid ();
|
|
|
|
myself->sid = tc.getsid ();
|
2011-06-04 02:12:29 +02:00
|
|
|
}
|
2003-12-07 23:37:12 +01:00
|
|
|
|
2011-10-16 00:37:30 +02:00
|
|
|
pinfo p (tc.getsid ());
|
2005-02-26 21:50:25 +01:00
|
|
|
if (sid == pid && (!p || p->pid == pid || !p->exists ()))
|
2003-12-07 23:37:12 +01:00
|
|
|
{
|
2006-06-03 22:32:07 +02:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
debug_printf ("resetting %s sid. Was %d, now %d. pgid was %d, now %d.",
|
2011-10-16 00:37:30 +02:00
|
|
|
__ctty (), tc.getsid (), sid, tc.getpgid (), pgid);
|
2006-06-03 22:32:07 +02:00
|
|
|
#else
|
2005-11-17 17:36:00 +01:00
|
|
|
paranoid_printf ("resetting %s sid. Was %d, now %d. pgid was %d, now %d.",
|
2011-10-16 00:37:30 +02:00
|
|
|
__ctty (), tc.getsid (), sid, tc.getpgid (), pgid);
|
2006-06-03 22:32:07 +02:00
|
|
|
#endif
|
2003-12-07 23:37:12 +01:00
|
|
|
/* We are the session leader */
|
2011-10-16 00:37:30 +02:00
|
|
|
tc.setsid (sid);
|
|
|
|
tc.setpgid (pgid);
|
2003-12-07 23:37:12 +01:00
|
|
|
}
|
|
|
|
else
|
2011-10-16 00:37:30 +02:00
|
|
|
sid = tc.getsid ();
|
|
|
|
if (tc.getpgid () == 0)
|
|
|
|
tc.setpgid (pgid);
|
2003-12-07 23:37:12 +01:00
|
|
|
}
|
2011-10-16 00:37:30 +02:00
|
|
|
debug_printf ("cygheap->ctty now %p, archetype %p", cygheap->ctty, fh->archetype);
|
|
|
|
return ctty > 0;
|
2003-12-07 23:37:12 +01:00
|
|
|
}
|
|
|
|
|
2005-02-27 05:30:08 +01:00
|
|
|
/* Test to determine if a process really exists and is processing signals.
|
|
|
|
*/
|
|
|
|
bool __stdcall
|
|
|
|
_pinfo::exists ()
|
|
|
|
{
|
2011-05-05 16:46:14 +02:00
|
|
|
return this && !(process_state & (PID_EXITED | PID_REAPED));
|
2005-02-27 05:30:08 +01:00
|
|
|
}
|
|
|
|
|
2002-10-30 22:05:18 +01:00
|
|
|
bool
|
|
|
|
_pinfo::alive ()
|
|
|
|
{
|
|
|
|
HANDLE h = OpenProcess (PROCESS_QUERY_INFORMATION, false, dwProcessId);
|
|
|
|
if (h)
|
|
|
|
CloseHandle (h);
|
|
|
|
return !!h;
|
|
|
|
}
|
|
|
|
|
2005-10-18 01:27:00 +02:00
|
|
|
DWORD WINAPI
|
|
|
|
commune_process (void *arg)
|
2002-10-30 22:05:18 +01:00
|
|
|
{
|
2005-10-18 01:27:00 +02:00
|
|
|
siginfo_t& si = *((siginfo_t *) arg);
|
2008-03-07 12:24:51 +01:00
|
|
|
tmp_pathbuf tp;
|
|
|
|
char *path = tp.c_get ();
|
2002-10-30 22:05:18 +01:00
|
|
|
DWORD nr;
|
2005-09-29 00:56:47 +02: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-30 22:05:18 +01:00
|
|
|
|
2007-02-20 01:16:18 +01:00
|
|
|
lock_process now ();
|
2006-03-20 02:59:23 +01:00
|
|
|
if (si._si_commune._si_code & PICOM_EXTRASTR)
|
|
|
|
si._si_commune._si_str = (char *) (&si + 1);
|
2005-10-03 19:23:54 +02:00
|
|
|
|
2005-09-29 00:56:47 +02:00
|
|
|
switch (si._si_commune._si_code)
|
2002-10-30 22:05:18 +01:00
|
|
|
{
|
|
|
|
case PICOM_CMDLINE:
|
|
|
|
{
|
2005-10-02 02:13:41 +02:00
|
|
|
sigproc_printf ("processing PICOM_CMDLINE");
|
2006-07-19 18:00:28 +02:00
|
|
|
unsigned n = 0;
|
2003-09-05 03:55:01 +02:00
|
|
|
const char *argv[__argc_safe + 1];
|
2004-06-07 06:26:32 +02:00
|
|
|
|
2003-09-05 03:55:01 +02:00
|
|
|
for (int i = 0; i < __argc_safe; i++)
|
|
|
|
{
|
2003-12-03 17:35:52 +01:00
|
|
|
if (IsBadStringPtr (__argv[i], INT32_MAX))
|
2003-09-05 03:55:01 +02:00
|
|
|
argv[i] = "";
|
|
|
|
else
|
|
|
|
argv[i] = __argv[i];
|
|
|
|
n += strlen (argv[i]) + 1;
|
|
|
|
}
|
|
|
|
argv[__argc_safe] = NULL;
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
2002-10-30 22:05:18 +01:00
|
|
|
{
|
|
|
|
/*__seterrno ();*/ // this is run from the signal thread, so don't set errno
|
2011-08-13 12:28:15 +02:00
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof argv failed, %E");
|
2002-10-30 22:05:18 +01:00
|
|
|
}
|
|
|
|
else
|
2003-09-05 03:55:01 +02:00
|
|
|
for (const char **a = argv; *a; a++)
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, *a, strlen (*a) + 1, &nr, 1000L))
|
2002-10-30 22:05:18 +01:00
|
|
|
{
|
2011-08-13 12:28:15 +02:00
|
|
|
sigproc_printf ("WritePipeOverlapped arg %d failed, %E",
|
|
|
|
a - argv);
|
2002-10-30 22:05:18 +01: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 02:37:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-01-29 12:23:07 +01:00
|
|
|
case PICOM_CWD:
|
|
|
|
{
|
2005-10-02 02:13:41 +02:00
|
|
|
sigproc_printf ("processing PICOM_CWD");
|
2008-02-14 17:47:11 +01:00
|
|
|
unsigned int n = strlen (cygheap->cwd.get (path, 1, 1, NT_MAX_PATH)) + 1;
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof cwd failed, %E");
|
|
|
|
else if (!WritePipeOverlapped (tothem, path, n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped cwd failed, %E");
|
2005-01-29 12:23:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PICOM_ROOT:
|
|
|
|
{
|
2005-10-02 02:13:41 +02:00
|
|
|
sigproc_printf ("processing PICOM_ROOT");
|
2005-09-29 00:56:47 +02:00
|
|
|
unsigned n;
|
2005-01-29 12:23:07 +01:00
|
|
|
if (cygheap->root.exists ())
|
2005-01-31 11:28:55 +01:00
|
|
|
n = strlen (strcpy (path, cygheap->root.posix_path ())) + 1;
|
2005-01-29 12:23:07 +01:00
|
|
|
else
|
2005-01-31 11:28:55 +01:00
|
|
|
n = strlen (strcpy (path, "/")) + 1;
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof root failed, %E");
|
|
|
|
else if (!WritePipeOverlapped (tothem, path, n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped root failed, %E");
|
2005-01-31 11:28:55 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PICOM_FDS:
|
|
|
|
{
|
2005-10-02 02:13:41 +02:00
|
|
|
sigproc_printf ("processing PICOM_FDS");
|
2005-01-31 11:28:55 +01:00
|
|
|
unsigned int n = 0;
|
|
|
|
int fd;
|
|
|
|
cygheap_fdenum cfd;
|
|
|
|
while ((fd = cfd.next ()) >= 0)
|
|
|
|
n += sizeof (int);
|
|
|
|
cfd.rewind ();
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof fds failed, %E");
|
2005-01-31 11:28:55 +01:00
|
|
|
else
|
|
|
|
while ((fd = cfd.next ()) >= 0)
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &fd, sizeof fd, &nr, 1000L))
|
2005-01-31 11:28:55 +01:00
|
|
|
{
|
2011-08-13 12:28:15 +02:00
|
|
|
sigproc_printf ("WritePipeOverlapped fd %d failed, %E", fd);
|
2005-01-31 11:28:55 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-05-02 05:50:11 +02:00
|
|
|
break;
|
2005-01-31 11:28:55 +01:00
|
|
|
}
|
2005-02-06 12:15:29 +01:00
|
|
|
case PICOM_PIPE_FHANDLER:
|
2005-10-02 02:13:41 +02: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;
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E");
|
|
|
|
else if (!WritePipeOverlapped (tothem, fh, n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped hdl failed, %E");
|
2005-10-02 02:13:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!n && !WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof hdl failed, %E");
|
2005-10-02 02:13:41 +02:00
|
|
|
break;
|
|
|
|
}
|
2005-01-31 11:28:55 +01:00
|
|
|
case PICOM_FD:
|
|
|
|
{
|
2005-10-02 02:13:41 +02:00
|
|
|
sigproc_printf ("processing PICOM_FD");
|
2005-09-29 00:56:47 +02:00
|
|
|
int fd = si._si_commune._si_fd;
|
2005-02-06 12:15:29 +01:00
|
|
|
unsigned int n = 0;
|
2005-01-31 11:28:55 +01:00
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
2005-02-01 16:11:47 +01:00
|
|
|
n = strlen (strcpy (path, "")) + 1;
|
2005-01-31 11:28:55 +01:00
|
|
|
else
|
|
|
|
n = strlen (cfd->get_proc_fd_name (path)) + 1;
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!WritePipeOverlapped (tothem, &n, sizeof n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped sizeof fd failed, %E");
|
|
|
|
else if (!WritePipeOverlapped (tothem, path, n, &nr, 1000L))
|
|
|
|
sigproc_printf ("WritePipeOverlapped fd failed, %E");
|
2005-05-02 05:50:11 +02:00
|
|
|
break;
|
2005-01-29 12:23:07 +01:00
|
|
|
}
|
2002-10-30 22:05:18 +01:00
|
|
|
}
|
2005-09-29 00:56:47 +02:00
|
|
|
if (process_sync)
|
|
|
|
{
|
2005-10-02 02:13:41 +02: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 00:56:47 +02:00
|
|
|
ForceCloseHandle (process_sync);
|
|
|
|
}
|
|
|
|
CloseHandle (tothem);
|
2005-10-18 01:27:00 +02:00
|
|
|
_my_tls._ctinfo->auto_release ();
|
|
|
|
return 0;
|
2002-10-30 22:05:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
commune_result
|
2005-09-29 00:56:47 +02:00
|
|
|
_pinfo::commune_request (__uint32_t code, ...)
|
2002-10-30 22:05:18 +01: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 02:37:18 +02:00
|
|
|
va_list args;
|
2005-09-29 00:56:47 +02: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 02:37:18 +02:00
|
|
|
|
2002-11-05 04:39:25 +01:00
|
|
|
res.s = NULL;
|
|
|
|
res.n = 0;
|
|
|
|
|
2004-01-03 21:57:11 +01:00
|
|
|
if (!this || !pid)
|
2002-10-30 22:05:18 +01:00
|
|
|
{
|
|
|
|
set_errno (ESRCH);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2009-10-14 06:17:05 +02:00
|
|
|
va_start (args, code);
|
2005-09-29 00:56:47 +02: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-28 21:22:25 +02:00
|
|
|
break;
|
2002-10-30 22:05:18 +01:00
|
|
|
|
2005-09-29 00:56:47 +02:00
|
|
|
case PICOM_FD:
|
|
|
|
si._si_commune._si_fd = va_arg (args, int);
|
|
|
|
break;
|
2005-09-28 21:22:25 +02:00
|
|
|
|
2005-09-29 00:56:47 +02:00
|
|
|
break;
|
2005-09-28 21:22:25 +02:00
|
|
|
}
|
2009-10-14 06:17:05 +02:00
|
|
|
va_end (args);
|
2005-09-28 21:22:25 +02:00
|
|
|
|
2005-09-29 00:56:47 +02:00
|
|
|
locked = true;
|
2007-12-06 19:24:06 +01:00
|
|
|
char name_buf[MAX_PATH];
|
2005-09-29 00:56:47 +02:00
|
|
|
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 02:13:41 +02:00
|
|
|
{
|
|
|
|
ForceCloseHandle (request_sync); /* don't signal semaphore since there was apparently no receiving process */
|
|
|
|
request_sync = NULL;
|
|
|
|
goto err;
|
|
|
|
}
|
2002-10-30 22:05:18 +01:00
|
|
|
|
|
|
|
size_t n;
|
|
|
|
switch (code)
|
|
|
|
{
|
|
|
|
case PICOM_CMDLINE:
|
2005-01-29 12:23:07 +01:00
|
|
|
case PICOM_CWD:
|
|
|
|
case PICOM_ROOT:
|
2005-01-31 11:28:55 +01:00
|
|
|
case PICOM_FDS:
|
2005-09-29 00:56:47 +02:00
|
|
|
case PICOM_FD:
|
|
|
|
case PICOM_PIPE_FHANDLER:
|
2011-08-13 12:28:15 +02:00
|
|
|
if (!ReadPipeOverlapped (fromthem, &n, sizeof n, &nr, 500L)
|
|
|
|
|| nr != sizeof 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
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto err;
|
|
|
|
}
|
2005-02-06 12:15:29 +01:00
|
|
|
if (!n)
|
2005-05-02 05:50:11 +02:00
|
|
|
res.s = NULL;
|
2005-02-06 12:15:29 +01:00
|
|
|
else
|
2005-05-02 05:50:11 +02:00
|
|
|
{
|
2007-11-26 22:30:49 +01:00
|
|
|
res.s = (char *) cmalloc_abort (HEAP_COMMUNE, n);
|
2005-02-06 12:15:29 +01:00
|
|
|
char *p;
|
2011-08-13 12:28:15 +02:00
|
|
|
for (p = res.s;
|
|
|
|
n && ReadPipeOverlapped (fromthem, p, n, &nr, 500L);
|
|
|
|
p += nr, n -= nr)
|
2005-02-06 12:15:29 +01:00
|
|
|
continue;
|
2005-08-24 19:45:11 +02:00
|
|
|
if (n)
|
2005-02-06 12:15:29 +01:00
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
goto err;
|
|
|
|
}
|
2005-08-24 19:45:11 +02:00
|
|
|
res.n = p - res.s;
|
2005-05-02 05:50:11 +02:00
|
|
|
}
|
2002-10-30 22:05:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
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 02:37:18 +02:00
|
|
|
memset (&res, 0, sizeof (res));
|
|
|
|
|
2002-10-30 22:05:18 +01:00
|
|
|
out:
|
2005-09-29 00:56:47 +02:00
|
|
|
if (request_sync)
|
|
|
|
{
|
|
|
|
LONG res;
|
|
|
|
ReleaseSemaphore (request_sync, 1, &res);
|
|
|
|
ForceCloseHandle (request_sync);
|
|
|
|
}
|
|
|
|
if (hp)
|
|
|
|
CloseHandle (hp);
|
|
|
|
if (fromthem)
|
|
|
|
CloseHandle (fromthem);
|
2002-10-30 22:05:18 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-02-06 12:15:29 +01: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 00:56:47 +02:00
|
|
|
commune_result cr = commune_request (PICOM_PIPE_FHANDLER, hdl);
|
2005-02-06 12:15:29 +01:00
|
|
|
n = cr.n;
|
|
|
|
return (fhandler_pipe *) cr.s;
|
|
|
|
}
|
|
|
|
|
2005-01-31 11:28:55 +01:00
|
|
|
char *
|
|
|
|
_pinfo::fd (int fd, size_t &n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 00:56:47 +02:00
|
|
|
commune_result cr = commune_request (PICOM_FD, fd);
|
2005-01-31 11:28:55 +01:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cygheap_fdget cfd (fd);
|
|
|
|
if (cfd < 0)
|
2005-08-24 06:38:39 +02:00
|
|
|
s = cstrdup ("");
|
2005-01-31 11:28:55 +01:00
|
|
|
else
|
2008-02-14 17:47:11 +01:00
|
|
|
s = cfd->get_proc_fd_name ((char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH));
|
2005-01-31 11:28:55 +01: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 00:56:47 +02:00
|
|
|
commune_result cr = commune_request (PICOM_FDS);
|
2005-01-31 11:28:55 +01:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
n = 0;
|
|
|
|
int fd;
|
2005-10-24 17:42:14 +02:00
|
|
|
cygheap_fdenum cfd (true);
|
2005-01-31 11:28:55 +01:00
|
|
|
while ((fd = cfd.next ()) >= 0)
|
|
|
|
n += sizeof (int);
|
|
|
|
cfd.rewind ();
|
2007-11-26 22:30:49 +01:00
|
|
|
s = (char *) cmalloc_abort (HEAP_COMMUNE, n);
|
2005-01-31 11:28:55 +01:00
|
|
|
int *p = (int *) s;
|
|
|
|
while ((fd = cfd.next ()) >= 0 && (char *) p - s < (int) n)
|
|
|
|
*p++ = fd;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2005-01-29 12:23:07 +01:00
|
|
|
char *
|
|
|
|
_pinfo::root (size_t& n)
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 00:56:47 +02:00
|
|
|
commune_result cr = commune_request (PICOM_ROOT);
|
2005-01-29 12:23:07 +01:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (cygheap->root.exists ())
|
2005-08-24 06:38:39 +02:00
|
|
|
s = cstrdup (cygheap->root.posix_path ());
|
2005-01-29 12:23:07 +01:00
|
|
|
else
|
2005-08-24 06:38:39 +02:00
|
|
|
s = cstrdup ("/");
|
2005-01-29 12:23:07 +01: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 00:56:47 +02:00
|
|
|
commune_result cr = commune_request (PICOM_CWD);
|
2005-01-29 12:23:07 +01:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-02-14 17:47:11 +01:00
|
|
|
s = (char *) cmalloc_abort (HEAP_COMMUNE, NT_MAX_PATH);
|
|
|
|
cygheap->cwd.get (s, 1, 1, NT_MAX_PATH);
|
2005-01-29 12:23:07 +01:00
|
|
|
n = strlen (s) + 1;
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2002-10-30 22:05:18 +01:00
|
|
|
char *
|
2003-03-08 20:22:08 +01:00
|
|
|
_pinfo::cmdline (size_t& n)
|
2002-10-30 22:05:18 +01:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
if (!this || !pid)
|
|
|
|
return NULL;
|
|
|
|
if (pid != myself->pid)
|
|
|
|
{
|
2005-09-29 00:56:47 +02:00
|
|
|
commune_result cr = commune_request (PICOM_CMDLINE);
|
2002-10-30 22:05:18 +01:00
|
|
|
s = cr.s;
|
|
|
|
n = cr.n;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-19 18:00:28 +02:00
|
|
|
n = 0;
|
2002-10-30 22:05:18 +01:00
|
|
|
for (char **a = __argv; *a; a++)
|
2002-12-16 19:56:33 +01:00
|
|
|
n += strlen (*a) + 1;
|
2002-10-30 22:05:18 +01:00
|
|
|
char *p;
|
2007-11-26 22:30:49 +01:00
|
|
|
p = s = (char *) cmalloc_abort (HEAP_COMMUNE, n);
|
2002-10-30 22:05:18 +01:00
|
|
|
for (char **a = __argv; *a; a++)
|
|
|
|
{
|
|
|
|
strcpy (p, *a);
|
|
|
|
p = strchr (p, '\0') + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2004-11-26 05:15:10 +01:00
|
|
|
/* This is the workhorse which waits for the write end of the pipe
|
2004-12-24 19:31:23 +01: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 05:15:10 +01:00
|
|
|
static DWORD WINAPI
|
|
|
|
proc_waiter (void *arg)
|
|
|
|
{
|
2005-01-17 05:12:08 +01:00
|
|
|
pinfo vchild = *(pinfo *) arg;
|
|
|
|
((pinfo *) arg)->waiter_ready = true;
|
2004-11-26 05:15:10 +01:00
|
|
|
|
2006-02-06 19:24:11 +01:00
|
|
|
siginfo_t si = {0};
|
2004-11-26 05:15:10 +01:00
|
|
|
si.si_signo = SIGCHLD;
|
2005-09-26 15:47:27 +02:00
|
|
|
si.si_code = CLD_EXITED;
|
2004-11-26 05:15:10 +01:00
|
|
|
si.si_pid = vchild->pid;
|
|
|
|
#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;
|
|
|
|
#endif
|
|
|
|
pid_t pid = vchild->pid;
|
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
DWORD nb;
|
|
|
|
char buf = '\0';
|
2005-01-11 16:31:04 +01:00
|
|
|
|
2004-11-26 05:15:10 +01: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 05:46:00 +01:00
|
|
|
case __ALERT_ALIVE:
|
|
|
|
continue;
|
2004-11-26 05:15:10 +01:00
|
|
|
case 0:
|
|
|
|
/* Child exited. Do some cleanup and signal myself. */
|
|
|
|
CloseHandle (vchild.rd_proc_pipe);
|
|
|
|
vchild.rd_proc_pipe = NULL;
|
2005-01-17 05:12:08 +01:00
|
|
|
vchild.maybe_set_exit_code_from_windows ();
|
2004-11-26 05:15:10 +01:00
|
|
|
if (WIFEXITED (vchild->exitcode))
|
2005-09-26 15:47:27 +02:00
|
|
|
si.si_code = CLD_EXITED;
|
2004-11-26 05:15:10 +01:00
|
|
|
else if (WCOREDUMP (vchild->exitcode))
|
2005-09-26 15:47:27 +02:00
|
|
|
si.si_code = CLD_DUMPED;
|
2004-11-26 05:15:10 +01:00
|
|
|
else
|
2005-09-26 15:47:27 +02:00
|
|
|
si.si_code = CLD_KILLED;
|
2004-11-26 05:15:10 +01:00
|
|
|
si.si_status = vchild->exitcode;
|
2005-01-17 05:12:08 +01:00
|
|
|
vchild->process_state = PID_EXITED;
|
|
|
|
/* This should always be last. Do not use vchild-> beyond this point */
|
2004-11-26 05:15:10 +01:00
|
|
|
break;
|
|
|
|
case SIGTTIN:
|
|
|
|
case SIGTTOU:
|
|
|
|
case SIGTSTP:
|
|
|
|
case SIGSTOP:
|
2004-12-05 20:41:26 +01:00
|
|
|
if (ISSTATE (myself, PID_NOCLDSTOP)) // FIXME: No need for this flag to be in _pinfo any longer
|
|
|
|
continue;
|
2004-11-26 05:15:10 +01:00
|
|
|
/* Child stopped. Signal myself. */
|
2005-09-26 15:47:27 +02:00
|
|
|
si.si_code = CLD_STOPPED;
|
2004-11-26 05:15:10 +01: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 01:29:41 +01:00
|
|
|
if (hExeced)
|
2004-11-26 05:15:10 +01: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-22 17:59:03 +01:00
|
|
|
vchild.wait_thread = NULL;
|
2004-12-23 15:57:08 +01:00
|
|
|
_my_tls._ctinfo->auto_release (); /* automatically return the cygthread to the cygthread pool */
|
2004-11-26 05:15:10 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-21 02:37:25 +01:00
|
|
|
HANDLE
|
2004-12-24 19:31:23 +01:00
|
|
|
_pinfo::dup_proc_pipe (HANDLE hProcess)
|
|
|
|
{
|
2005-01-04 15:57:42 +01:00
|
|
|
DWORD flags = DUPLICATE_SAME_ACCESS;
|
2006-03-18 20:17:21 +01:00
|
|
|
HANDLE orig_wr_proc_pipe = wr_proc_pipe;
|
|
|
|
/* Can't set DUPLICATE_CLOSE_SOURCE for exec case because we could be
|
2005-01-04 15:57:42 +01:00
|
|
|
execing a non-cygwin process and we need to set the exit value before the
|
|
|
|
parent sees it. */
|
2005-01-11 16:31:04 +01:00
|
|
|
if (this != myself || is_toplevel_proc)
|
2005-01-04 15:57:42 +01:00
|
|
|
flags |= DUPLICATE_CLOSE_SOURCE;
|
2009-12-18 21:32:04 +01:00
|
|
|
bool res = DuplicateHandle (GetCurrentProcess (), wr_proc_pipe,
|
|
|
|
hProcess, &wr_proc_pipe, 0, FALSE, flags);
|
2005-09-28 15:55:04 +02:00
|
|
|
if (!res && WaitForSingleObject (hProcess, 0) != WAIT_OBJECT_0)
|
2006-03-21 02:37:25 +01:00
|
|
|
{
|
|
|
|
wr_proc_pipe = orig_wr_proc_pipe;
|
|
|
|
system_printf ("DuplicateHandle failed, pid %d, hProcess %p, wr_proc_pipe %p, %E",
|
|
|
|
pid, hProcess, wr_proc_pipe);
|
|
|
|
}
|
2004-12-24 19:31:23 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
wr_proc_pipe_owner = dwProcessId;
|
2006-03-18 20:17:21 +01:00
|
|
|
sigproc_printf ("duped wr_proc_pipe %p for pid %d(%u)", wr_proc_pipe,
|
2004-12-24 19:31:23 +01:00
|
|
|
pid, dwProcessId);
|
|
|
|
}
|
2006-03-21 02:37:25 +01:00
|
|
|
return orig_wr_proc_pipe;
|
2004-12-24 19:31:23 +01:00
|
|
|
}
|
|
|
|
|
2004-11-26 05:15:10 +01:00
|
|
|
/* function to set up the process pipe and kick off proc_waiter */
|
|
|
|
int
|
|
|
|
pinfo::wait ()
|
|
|
|
{
|
2011-10-26 21:42:39 +02:00
|
|
|
/* If rd_proc_pipe that means we're in an execed process which already has
|
|
|
|
grabbed the read end of the pipe from the previous cygwin process running
|
|
|
|
with this pid. */
|
|
|
|
if (!rd_proc_pipe)
|
|
|
|
{
|
|
|
|
/* FIXME: execed processes should be able to wait for pids that were started
|
|
|
|
by the process which execed them. */
|
|
|
|
if (!CreatePipe (&rd_proc_pipe, &((*this)->wr_proc_pipe), &sec_none_nih, 16))
|
|
|
|
{
|
|
|
|
system_printf ("Couldn't create pipe tracker for pid %d, %E",
|
|
|
|
(*this)->pid);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-24 19:31:23 +01:00
|
|
|
|
2011-10-26 21:42:39 +02:00
|
|
|
if (!(*this)->dup_proc_pipe (hProcess))
|
|
|
|
{
|
|
|
|
system_printf ("Couldn't duplicate pipe topid %d(%p), %E", (*this)->pid, hProcess);
|
|
|
|
return 0;
|
|
|
|
}
|
2004-11-26 05:15:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
preserve (); /* Preserve the shared memory associated with the pinfo */
|
|
|
|
|
2005-01-17 05:12:08 +01:00
|
|
|
waiter_ready = false;
|
2004-11-26 05:15:10 +01:00
|
|
|
/* Fire up a new thread to track the subprocess */
|
2010-09-01 20:24:11 +02:00
|
|
|
cygthread *h = new cygthread (proc_waiter, this, "proc_waiter");
|
2004-11-26 05:15:10 +01:00
|
|
|
if (!h)
|
|
|
|
sigproc_printf ("tracking thread creation failed for pid %d", (*this)->pid);
|
|
|
|
else
|
|
|
|
{
|
2004-12-05 22:29:37 +01:00
|
|
|
wait_thread = h;
|
2004-11-26 05:15:10 +01: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-24 19:31:23 +01:00
|
|
|
void
|
|
|
|
_pinfo::sync_proc_pipe ()
|
|
|
|
{
|
|
|
|
if (wr_proc_pipe && wr_proc_pipe != INVALID_HANDLE_VALUE)
|
|
|
|
while (wr_proc_pipe_owner != GetCurrentProcessId ())
|
2010-03-13 00:13:48 +01:00
|
|
|
yield ();
|
2004-12-24 19:31:23 +01:00
|
|
|
}
|
|
|
|
|
2004-11-26 05:15:10 +01:00
|
|
|
/* function to send a "signal" to the parent when something interesting happens
|
|
|
|
in the child. */
|
2004-12-03 05:46:00 +01:00
|
|
|
bool
|
2004-12-24 19:31:23 +01:00
|
|
|
_pinfo::alert_parent (char sig)
|
2004-11-26 05:15:10 +01:00
|
|
|
{
|
2004-12-03 05:46:00 +01:00
|
|
|
DWORD nb = 0;
|
2005-10-19 16:19:37 +02: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 05:46:00 +01:00
|
|
|
/* no parent */;
|
2004-11-26 05:15:10 +01:00
|
|
|
else
|
|
|
|
{
|
2004-12-24 19:31:23 +01: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 05:12:08 +01:00
|
|
|
ppid = 1;
|
2004-12-24 19:31:23 +01:00
|
|
|
HANDLE closeit = wr_proc_pipe;
|
|
|
|
wr_proc_pipe = INVALID_HANDLE_VALUE;
|
|
|
|
CloseHandle (closeit);
|
|
|
|
}
|
2004-11-26 05:15:10 +01:00
|
|
|
}
|
2004-12-03 05:46:00 +01:00
|
|
|
return (bool) nb;
|
2004-11-26 05:15:10 +01:00
|
|
|
}
|
|
|
|
|
2000-08-26 05:48:37 +02:00
|
|
|
void
|
|
|
|
pinfo::release ()
|
|
|
|
{
|
2005-01-22 22:17:53 +01:00
|
|
|
if (procinfo)
|
2000-08-26 05:48:37 +02:00
|
|
|
{
|
2005-02-26 21:50:25 +01:00
|
|
|
void *unmap_procinfo = procinfo;
|
2000-10-20 06:20:21 +02:00
|
|
|
procinfo = NULL;
|
2005-02-26 21:50:25 +01:00
|
|
|
UnmapViewOfFile (unmap_procinfo);
|
2005-01-22 22:17:53 +01:00
|
|
|
}
|
|
|
|
if (h)
|
|
|
|
{
|
2005-02-26 21:50:25 +01:00
|
|
|
HANDLE close_h = h;
|
2000-08-26 05:48:37 +02:00
|
|
|
h = NULL;
|
2005-02-26 21:50:25 +01:00
|
|
|
ForceCloseHandle1 (close_h, pinfo_shared_handle);
|
2000-08-26 05:48:37 +02:00
|
|
|
}
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
|
|
|
|
/* DOCTOOL-START
|
|
|
|
|
|
|
|
<sect1 id="func-cygwin-winpid-to-pid">
|
|
|
|
<title>cygwin_winpid_to_pid</title>
|
|
|
|
|
2004-02-23 00:21:20 +01:00
|
|
|
<funcsynopsis><funcprototype>
|
2000-02-17 20:38:33 +01:00
|
|
|
<funcdef>extern "C" pid_t
|
|
|
|
<function>cygwin_winpid_to_pid</function>
|
|
|
|
</funcdef>
|
|
|
|
<paramdef>int <parameter>winpid</parameter></paramdef>
|
2004-02-23 00:21:20 +01:00
|
|
|
</funcprototype></funcsynopsis>
|
2000-02-17 20:38:33 +01: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 03:02:03 +01:00
|
|
|
pinfo p (cygwin_pid (winpid));
|
2000-07-29 18:24:59 +02:00
|
|
|
if (p)
|
|
|
|
return p->pid;
|
2000-02-17 20:38:33 +01:00
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
set_errno (ESRCH);
|
|
|
|
return (pid_t) -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-02 06:25:56 +01:00
|
|
|
#define slop_pidlist 200
|
|
|
|
#define size_pidlist(i) (sizeof (pidlist[0]) * ((i) + 1))
|
2000-11-05 07:42:23 +01:00
|
|
|
#define size_pinfolist(i) (sizeof (pinfolist[0]) * ((i) + 1))
|
2005-12-22 04:16:36 +01:00
|
|
|
class _onreturn
|
|
|
|
{
|
2005-12-23 23:50:20 +01:00
|
|
|
HANDLE *h;
|
2005-12-22 04:16:36 +01:00
|
|
|
public:
|
|
|
|
~_onreturn ()
|
|
|
|
{
|
2006-08-10 22:25:54 +02:00
|
|
|
if (h && *h)
|
2005-12-22 04:16:36 +01:00
|
|
|
{
|
2005-12-23 23:50:20 +01:00
|
|
|
CloseHandle (*h);
|
|
|
|
*h = NULL;
|
2006-08-10 22:25:54 +02:00
|
|
|
h = NULL;
|
2005-12-22 04:16:36 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-23 23:50:20 +01:00
|
|
|
void no_close_p_handle () {h = NULL;}
|
|
|
|
_onreturn (HANDLE& _h): h (&_h) {}
|
2005-12-22 04:16:36 +01:00
|
|
|
};
|
2000-11-02 06:25:56 +01:00
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
inline void
|
|
|
|
winpids::add (DWORD& nelem, bool winpid, DWORD pid)
|
|
|
|
{
|
|
|
|
pid_t cygpid = cygwin_pid (pid);
|
2005-12-22 04:16:36 +01:00
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
if (nelem >= npidlist)
|
|
|
|
{
|
|
|
|
npidlist += slop_pidlist;
|
2001-10-13 19:23:35 +02:00
|
|
|
pidlist = (DWORD *) realloc (pidlist, size_pidlist (npidlist + 1));
|
|
|
|
pinfolist = (pinfo *) realloc (pinfolist, size_pinfolist (npidlist + 1));
|
2000-11-05 07:42:23 +01:00
|
|
|
}
|
|
|
|
|
2005-12-12 19:43:31 +01:00
|
|
|
pinfo& p = pinfolist[nelem];
|
|
|
|
|
2005-12-22 04:16:36 +01: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-23 23:50:20 +01:00
|
|
|
_onreturn onreturn (p.hProcess);
|
2005-12-22 04:16:36 +01: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).
|
|
|
|
*/
|
2005-12-23 23:50:20 +01:00
|
|
|
bool perform_copy;
|
2005-12-22 04:16:36 +01:00
|
|
|
if (!p.hProcess)
|
|
|
|
perform_copy = true;
|
|
|
|
else
|
2005-12-23 23:50:20 +01:00
|
|
|
perform_copy = make_copy;
|
|
|
|
|
|
|
|
p.init (cygpid, PID_NOREDIR | pinfo_access, NULL);
|
2005-12-22 04:16:36 +01:00
|
|
|
|
|
|
|
/* If we're just looking for winpids then don't do any special cygwin "stuff* */
|
2000-11-05 07:42:23 +01:00
|
|
|
if (winpid)
|
2003-09-17 03:15:56 +02:00
|
|
|
goto out;
|
2000-11-05 07:42:23 +01:00
|
|
|
|
2005-12-22 04:16:36 +01:00
|
|
|
/* !p means that we couldn't find shared memory for this pid. Probably means
|
|
|
|
that it isn't a cygwin process. */
|
2005-12-12 19:43:31 +01:00
|
|
|
if (!p)
|
2003-09-17 03:15:56 +02:00
|
|
|
{
|
|
|
|
if (!pinfo_access)
|
|
|
|
return;
|
2005-12-12 19:43:31 +01:00
|
|
|
p.init (cygpid, PID_NOREDIR, NULL);
|
|
|
|
if (!p)
|
2003-09-17 03:15:56 +02: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-12 19:43:31 +01:00
|
|
|
if (pinfolist[i]->pid == p->pid)
|
2003-09-17 03:15:56 +02:00
|
|
|
{
|
2005-12-12 19:43:31 +01:00
|
|
|
if ((_pinfo *) p != (_pinfo *) myself)
|
|
|
|
p.release ();
|
2003-09-17 03:15:56 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2005-12-22 04:16:36 +01: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.
|
2005-12-22 06:57:54 +01:00
|
|
|
|
2005-12-22 04:16:36 +01:00
|
|
|
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.
|
2005-12-22 06:57:54 +01:00
|
|
|
|
2005-12-22 04:16:36 +01:00
|
|
|
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-12 19:43:31 +01:00
|
|
|
{
|
2005-12-22 04:16:36 +01: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-12 19:43:31 +01:00
|
|
|
{
|
2005-12-22 04:16:36 +01: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-12 19:43:31 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-22 06:26:14 +01:00
|
|
|
if (p || winpid)
|
2011-08-11 09:28:42 +02:00
|
|
|
pidlist[nelem++] = !p ? pid : p->dwProcessId;
|
2000-11-05 07:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DWORD
|
2007-02-22 11:54:47 +01:00
|
|
|
winpids::enum_processes (bool winpid)
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
|
|
|
DWORD nelem = 0;
|
2011-08-11 09:28:42 +02:00
|
|
|
DWORD cygwin_pid_nelem = 0;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG context;
|
|
|
|
struct fdbi
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
2011-08-11 09:28:42 +02:00
|
|
|
DIRECTORY_BASIC_INFORMATION dbi;
|
|
|
|
WCHAR buf[2][NAME_MAX + 1];
|
|
|
|
} f;
|
|
|
|
HANDLE dir = get_shared_parent_dir ();
|
|
|
|
BOOLEAN restart = TRUE;
|
2000-11-02 06:25:56 +01:00
|
|
|
|
2011-08-11 09:28:42 +02:00
|
|
|
do
|
|
|
|
{
|
|
|
|
status = NtQueryDirectoryObject (dir, &f, sizeof f, TRUE, restart,
|
|
|
|
&context, NULL);
|
|
|
|
if (NT_SUCCESS (status))
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
2011-08-11 09:28:42 +02:00
|
|
|
restart = FALSE;
|
|
|
|
f.dbi.ObjectName.Buffer[f.dbi.ObjectName.Length / sizeof (WCHAR)]
|
|
|
|
= L'\0';
|
|
|
|
if (wcsncmp (f.dbi.ObjectName.Buffer, L"cygpid.", 7) == 0)
|
|
|
|
{
|
|
|
|
DWORD pid = wcstoul (f.dbi.ObjectName.Buffer + 7, NULL, 10);
|
|
|
|
add (nelem, false, pid);
|
|
|
|
}
|
2000-11-02 06:25:56 +01:00
|
|
|
}
|
|
|
|
}
|
2011-08-11 09:28:42 +02:00
|
|
|
while (NT_SUCCESS (status));
|
|
|
|
cygwin_pid_nelem = nelem;
|
2000-11-02 06:25:56 +01:00
|
|
|
|
2011-08-11 09:28:42 +02:00
|
|
|
if (winpid)
|
2000-11-02 06:25:56 +01:00
|
|
|
{
|
2011-08-11 09:28:42 +02:00
|
|
|
static DWORD szprocs;
|
|
|
|
static SYSTEM_PROCESSES *procs;
|
|
|
|
|
|
|
|
if (!szprocs)
|
|
|
|
procs = (SYSTEM_PROCESSES *) malloc (sizeof (*procs) + (szprocs = 200 * sizeof (*procs)));
|
|
|
|
|
|
|
|
NTSTATUS res;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
res = NtQuerySystemInformation (SystemProcessesAndThreadsInformation,
|
|
|
|
procs, szprocs, NULL);
|
|
|
|
if (res == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (res == STATUS_INFO_LENGTH_MISMATCH)
|
|
|
|
procs = (SYSTEM_PROCESSES *) realloc (procs, szprocs += 200 * sizeof (*procs));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
system_printf ("error %p reading system process information", res);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SYSTEM_PROCESSES *px = procs;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (px->ProcessId)
|
|
|
|
{
|
|
|
|
bool do_add = true;
|
|
|
|
for (unsigned i = 0; i < cygwin_pid_nelem; ++i)
|
|
|
|
if (pidlist[i] == px->ProcessId)
|
|
|
|
{
|
|
|
|
do_add = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (do_add)
|
|
|
|
add (nelem, true, px->ProcessId);
|
|
|
|
}
|
|
|
|
if (!px->NextEntryDelta)
|
|
|
|
break;
|
|
|
|
px = (SYSTEM_PROCESSES *) ((char *) px + px->NextEntryDelta);
|
|
|
|
}
|
2000-11-02 06:25:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nelem;
|
|
|
|
}
|
|
|
|
|
2000-07-29 18:24:59 +02:00
|
|
|
void
|
2002-11-29 08:05:26 +01:00
|
|
|
winpids::set (bool winpid)
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
2004-02-12 04:01:58 +01:00
|
|
|
__malloc_lock ();
|
2007-02-22 11:54:47 +01:00
|
|
|
npids = enum_processes (winpid);
|
2001-10-13 19:23:35 +02:00
|
|
|
if (pidlist)
|
|
|
|
pidlist[npids] = 0;
|
2004-02-12 04:01:58 +01:00
|
|
|
__malloc_unlock ();
|
2000-07-29 18:24:59 +02:00
|
|
|
}
|
|
|
|
|
2000-11-05 07:42:23 +01:00
|
|
|
DWORD
|
|
|
|
winpids::enum_init (bool winpid)
|
2000-07-29 18:24:59 +02:00
|
|
|
{
|
2007-02-22 11:54:47 +01:00
|
|
|
return enum_processes (winpid);
|
2000-11-05 07:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
winpids::release ()
|
|
|
|
{
|
2005-12-12 19:43:31 +01:00
|
|
|
_pinfo *p;
|
2000-11-05 07:42:23 +01:00
|
|
|
for (unsigned i = 0; i < npids; i++)
|
2005-12-22 04:16:36 +01:00
|
|
|
if (pinfolist[i] == (_pinfo *) myself)
|
|
|
|
continue;
|
2005-12-22 06:11:44 +01:00
|
|
|
else if (pinfolist[i].hProcess)
|
2005-12-22 04:16:36 +01:00
|
|
|
{
|
|
|
|
if (pinfolist[i])
|
|
|
|
pinfolist[i].release ();
|
2005-12-22 06:11:44 +01:00
|
|
|
CloseHandle (pinfolist[i].hProcess);
|
2005-12-22 04:16:36 +01:00
|
|
|
}
|
|
|
|
else if ((p = pinfolist[i]))
|
|
|
|
{
|
|
|
|
pinfolist[i].procinfo = NULL;
|
|
|
|
free (p);
|
|
|
|
}
|
2000-11-05 07:42:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
winpids::~winpids ()
|
|
|
|
{
|
|
|
|
if (npidlist)
|
|
|
|
{
|
|
|
|
release ();
|
|
|
|
free (pidlist);
|
|
|
|
free (pinfolist);
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|