Throughout rename _PROC_* to _CH_*.
* child_info.h: Include "pinfo.h".
(child_info_types): Rename _PROC_* -> _CH_* to avoid confusion with similarly
named constants.
(_PROC_*): Delete unneeded aliases.
(PROC_*): Ditto.
(CURR_CHILD_INFO_MAGIC): Ditto.
(cchildren): Define using "pinfo_minimal".
(child_info::set_saw_ctrl_c): Move to
(child_info_spawn::set_saw_ctrl_c): Here.
(child_info_spawn::lock): New field.
(child_info_spawn::hExeced): Ditto.
(child_info_spawn::ev): Ditto.
(child_info_spawn::~child_info_spawn): Move to sigproc.cc.
(child_info_spawn::child_info_spawn): Ditto.
(child_info_spawn::cleanup): Declare new function.
(child_info_spawn::set_saw_ctrl_c): Move to this class. Set flag only when
execed and return true when we have set the flag.
(child_info_spawn::child_info_spawn::signal_myself_exited): New function.
(child_info_spawn::wait_for_myself): Ditto.
(child_info_spawn::has_execed_cygwin): Ditto.
(child_info_spawn::has_execed): Ditto. Replaces "hExeced" test.
(child_info_spawn::operator HANDLE&): New operator.
(child_info_spawn::worker): Define old "spawn_guts" as class member.
(ch_spawn): Declare.
(have_execed): Define.
(have_execed_cygwin): Ditto.
* cygheap.h: Update comment.
* dcrt0.cc (get_cygwin_startup_info): Use _CH_* enums.
(child_info_spawn::handle_spawn): Ditto.
(dll_crt0_0): Ditto.
(multiple_cygwin_problem): Ditto.
* exceptions.cc (chExeced): Delete obsolete declaration.
(ctrl_c_handler): Reference set_saw_ctrl_c via new ch_spawn global.
* globals.cc (hExeced): Delete.
* pinfo.cc (pinfo::thisproc): Refer to cygheap as ::cygheap for consistency in
handle naming when -DDEBUGGING.
(pinfo::init): Accommodate case where myself.h is known but h0 is passed in.
(pinfo::pinfo): New constructor for setting up a pinfo passed in by previous
exec'or.
(pinfo::proc_waiter): Don't handle subprocess if we're in the process of
exiting due to an exec of a cygwin process. Don't close rd_proc_pipe here.
Close it when we actually are finished with the process. Use new
ch_spawn.signal_myself_exited function to let exec stub know that subprocess
has exited.
(pinfo::wait): Clarify debugging output.
(pinfo::release): Use "close_h" to close all handles to avoid races.
(winpids::add): Assume that elements of the array do not need to be zeroed and
are properly initialized or suffer problems on pinfo::release. Don't close
hProcess since release does that now.
* pinfo.h: Update comment.
(pinfo_minimal): Move some elements from pinfo here so that child_info_spawn
can use them.
(pinfo): Inherit from pinfo_minimal.
(pinfo::pinfo): Modify to accommodate new pinfo_minimal.
(pinfo::allow_remove): New function.
* sigproc.cc (proc_subproc): Use boolean values for true/false. Implement
PROC_EXEC_CLEANUP.
(proc_terminate): Set ppid = 1 since the procs list will only be iterated when
the process has not execed. Don't do any cleanup here since it is now handled
in pinfo::release.
(sigproc_init): Initialize sync_proc_subproc earlier.
(child_info::child_info): Assume that all important fields are properly
initialized and avoid memset().
(child_info_spawn::child_info_spawn): Specifically test for execing and then
set up appropriate fields in the struct.
(child_info_spawn::cleanup): Define new function.
(child_info_spawn::record_children): Specifically test for being execed here.
Fill in pinfo_minimal part of children array.
(child_info_spawn::reattach_children): Use constructor to duplicate information
for previous exec'or. Add more debugging output.
(remove_proc): Force deletion of thread when exiting due to exec. Rely on
pinfo::cleanup in release.
* sigproc.h (PROC_EXEC_CLEANUP): New enum.
(PROC_DETACHED_CHILD): Delete.
* spawn.cc (chExeced): Delete.
(child_info_spawn::worker): Rename from spawn_guts. Use elements of
child_info_spawn throughout rather than ch.whatever. Use ::cygheap to refer to
global rather than element of child_info. Use wait_for_myself() rather than
waitpid(). Call child_info_spawn::cleanup on function return.
(spawnve): Reflect movement of spawn_guts functionality into
child_info_spawn::worker.
* syscalls.cc (popen): Ditto.
* winsup.h (spawn_guts): Delete declaration.
+2011-11-10 Christopher Faylor <me.cygwin2011@cgf.cx>
+
+ Throughout use "have_execed" macro rather than "hExeced" global handle.
+ Throughout rename _PROC_* to _CH_*.
+ * child_info.h: Include "pinfo.h".
+ (child_info_types): Rename _PROC_* -> _CH_* to avoid confusion with
+ similarly named constants.
+ (_PROC_*): Delete unneeded aliases.
+ (PROC_*): Ditto.
+ (CURR_CHILD_INFO_MAGIC): Ditto.
+ (cchildren): Define using "pinfo_minimal".
+ (child_info::set_saw_ctrl_c): Move to
+ (child_info_spawn::set_saw_ctrl_c): Here.
+ (child_info_spawn::lock): New field.
+ (child_info_spawn::hExeced): Ditto.
+ (child_info_spawn::ev): Ditto.
+ (child_info_spawn::~child_info_spawn): Move to sigproc.cc.
+ (child_info_spawn::child_info_spawn): Ditto.
+ (child_info_spawn::cleanup): Declare new function.
+ (child_info_spawn::set_saw_ctrl_c): Move to this class. Set flag only
+ when execed and return true when we have set the flag.
+ (child_info_spawn::child_info_spawn::signal_myself_exited): New function.
+ (child_info_spawn::wait_for_myself): Ditto.
+ (child_info_spawn::has_execed_cygwin): Ditto.
+ (child_info_spawn::has_execed): Ditto. Replaces "hExeced" test.
+ (child_info_spawn::operator HANDLE&): New operator.
+ (child_info_spawn::worker): Define old "spawn_guts" as class member.
+ (ch_spawn): Declare.
+ (have_execed): Define.
+ (have_execed_cygwin): Ditto.
+ * cygheap.h: Update comment.
+ * dcrt0.cc (get_cygwin_startup_info): Use _CH_* enums.
+ (child_info_spawn::handle_spawn): Ditto.
+ (dll_crt0_0): Ditto.
+ (multiple_cygwin_problem): Ditto.
+ * exceptions.cc (chExeced): Delete obsolete declaration.
+ (ctrl_c_handler): Reference set_saw_ctrl_c via new ch_spawn global.
+ * globals.cc (hExeced): Delete.
+ * pinfo.cc (pinfo::thisproc): Refer to cygheap as ::cygheap for
+ consistency in handle naming when -DDEBUGGING.
+ (pinfo::init): Accommodate case where myself.h is known but h0 is
+ passed in.
+ (pinfo::pinfo): New constructor for setting up a pinfo passed in by
+ previous exec'or.
+ (pinfo::proc_waiter): Don't handle subprocess if we're in the process
+ of exiting due to an exec of a cygwin process. Don't close
+ rd_proc_pipe here. Close it when we actually are finished with the
+ process. Use new ch_spawn.signal_myself_exited function to let exec
+ stub know that subprocess has exited.
+ (pinfo::wait): Clarify debugging output.
+ (pinfo::release): Use "close_h" to close all handles to avoid races.
+ (winpids::add): Assume that elements of the array do not need to be
+ zeroed and are properly initialized or suffer problems on
+ pinfo::release. Don't close hProcess since release does that now.
+ * pinfo.h: Update comment.
+ (pinfo_minimal): Move some elements from pinfo here so that
+ child_info_spawn can use them.
+ (pinfo): Inherit from pinfo_minimal.
+ (pinfo::pinfo): Modify to accommodate new pinfo_minimal.
+ (pinfo::allow_remove): New function.
+ * sigproc.cc (proc_subproc): Use boolean values for true/false.
+ Implement PROC_EXEC_CLEANUP.
+ (proc_terminate): Set ppid = 1 since the procs list will only be
+ iterated when the process has not execed. Don't do any cleanup here
+ since it is now handled in pinfo::release.
+ (sigproc_init): Initialize sync_proc_subproc earlier.
+ (child_info::child_info): Assume that all important fields are properly
+ initialized and avoid memset().
+ (child_info_spawn::child_info_spawn): Specifically test for execing and
+ then set up appropriate fields in the struct.
+ (child_info_spawn::cleanup): Define new function.
+ (child_info_spawn::record_children): Specifically test for being execed
+ here. Fill in pinfo_minimal part of children array.
+ (child_info_spawn::reattach_children): Use constructor to duplicate
+ information for previous exec'or. Add more debugging output.
+ (remove_proc): Force deletion of thread when exiting due to exec. Rely
+ on pinfo::cleanup in release.
+ * sigproc.h (PROC_EXEC_CLEANUP): New enum.
+ (PROC_DETACHED_CHILD): Delete.
+ * spawn.cc (chExeced): Delete.
+ (child_info_spawn::worker): Rename from spawn_guts. Use elements of
+ child_info_spawn throughout rather than ch.whatever. Use ::cygheap to
+ refer to global rather than element of child_info. Use
+ wait_for_myself() rather than waitpid(). Call
+ child_info_spawn::cleanup on function return.
+ (spawnve): Reflect movement of spawn_guts functionality into
+ child_info_spawn::worker.
+ * syscalls.cc (popen): Ditto.
+ * winsup.h (spawn_guts): Delete declaration.
+
2011-11-08 Corinna Vinschen <corinna@vinschen.de>
* posix.sgml (std-gnu): Add ptsname_r.
small_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s\n",
failedexpr, file, line,
func ? ", function: " : "", func ? func : "");
+ debug_printf ("assertion \"%s\" failed: file \"%s\", line %d%s%s",
+ failedexpr, file, line,
+ func ? ", function: " : "", func ? func : "");
}
#ifdef DEBUGGING
enum child_info_types
{
- _PROC_EXEC,
- _PROC_SPAWN,
- _PROC_FORK,
- _PROC_WHOOPS
+ _CH_NADA = 0,
+ _CH_EXEC = 1,
+ _CH_SPAWN = 2,
+ _CH_FORK = 3,
+ _CH_WHOOPS = 4
};
enum child_status
#define PROC_MAGIC_GENERIC 0xaf00fa00
-#define PROC_EXEC (_PROC_EXEC)
-#define PROC_SPAWN (_PROC_SPAWN)
-#define PROC_FORK (_PROC_FORK)
-
#define EXEC_MAGIC_SIZE sizeof(child_info)
/* Change this value if you get a message indicating that it is out-of-sync. */
-#define CURR_CHILD_INFO_MAGIC 0xa049a83aU
+#define CURR_CHILD_INFO_MAGIC 0x941e0a4aU
#define NPROCS 256
+#include "pinfo.h"
struct cchildren
{
pid_t pid;
- HANDLE rd_proc_pipe;
+ pinfo_minimal p;
};
/* NOTE: Do not make gratuitous changes to the names or organization of the
bool isstraced () const {return !!(flag & _CI_STRACED);}
bool iscygwin () const {return !!(flag & _CI_ISCYGWIN);}
bool saw_ctrl_c () const {return !!(flag & _CI_SAW_CTRL_C);}
- void set_saw_ctrl_c () {flag |= _CI_SAW_CTRL_C;}
};
class mount_info;
class child_info_spawn: public child_info
{
+ muto *lock;
+ HANDLE hExeced;
+ HANDLE ev;
public:
cygheap_exec_info *moreinfo;
int __stdin;
int nchildren;
cchildren children[NPROCS];
- ~child_info_spawn ()
- {
- if (moreinfo)
- {
- if (moreinfo->envp)
- {
- for (char **e = moreinfo->envp; *e; e++)
- cfree (*e);
- cfree (moreinfo->envp);
- }
- if (type != _PROC_SPAWN && moreinfo->myself_pinfo)
- CloseHandle (moreinfo->myself_pinfo);
- cfree (moreinfo);
- }
- }
- child_info_spawn (): moreinfo (NULL), nchildren (0) {};
+ void cleanup ();
+ child_info_spawn () {};
child_info_spawn (child_info_types, bool);
void record_children ();
void reattach_children ();
void *operator new (size_t, void *p) __attribute__ ((nothrow)) {return p;}
void set (child_info_types ci, bool b) { new (this) child_info_spawn (ci, b);}
void handle_spawn () __attribute__ ((regparm (1)));
+ bool set_saw_ctrl_c ()
+ {
+ if (!has_execed ())
+ return false;
+ flag |= _CI_SAW_CTRL_C;
+ return true;
+ }
+ bool signal_myself_exited ()
+ {
+ if (!ev)
+ return false;
+ else
+ {
+ SetEvent (ev);
+ return true;
+ }
+ }
+ void wait_for_myself () { WaitForSingleObject (ev, INFINITE); }
+ bool has_execed () const
+ {
+ if (hExeced)
+ return true;
+ if (type != _CH_EXEC)
+ return false;
+ lock->acquire ();
+ lock->release ();
+ return !!hExeced;
+ }
+ bool has_execed_cygwin () const { return iscygwin () && has_execed (); }
+ operator HANDLE& () {return hExeced;}
+ int worker (const char *, const char *const *, const char *const [], int,
+ int = -1, int = -1) __attribute__ ((regparm (3)));;
};
+extern child_info_spawn ch_spawn;
+
+#define have_execed ch_spawn.has_execed ()
+#define have_execed_cygwin ch_spawn.has_execed_cygwin ()
+
void __stdcall init_child_info (DWORD, child_info *, HANDLE);
extern "C" {
cygheap_max = cygheap = (init_cygheap *) _cygheap_start;
_csbrk ((char *) child_proc_info->cygheap_max - (char *) cygheap);
child_copy (child_proc_info->parent, false, "cygheap", cygheap, cygheap_max, NULL);
+debug_printf ("HERE");
cygheap_init ();
+debug_printf ("HERE 2");
debug_fixup_after_fork_exec ();
+debug_printf ("HERE 2, %d", execed);
if (execed)
{
cygheap->hooks.next = NULL;
_cfree (ce); /* Marked by parent for freeing in child */
}
}
+debug_printf ("HERE 3, %d", execed);
}
int
int error; /* This contains an errno number which corresponds
to the problem with this path when trying to start
a native Win32 application. See cwdstuff::set for
- how it gets set. See spawn_guts for how it's
- evaluated. */
+ how it gets set. See child_info_spawn::worker for how
+ it's evaluated. */
void override_win32_cwd (bool, ULONG);
public:
{
static int NO_COPY threadlist_ix;
- debug_printf ("sig %d\n", sig);
+ debug_printf ("signal %d\n", sig);
sentry here (INFINITE);
_cygtls *res = NULL;
unsigned should_be_cb = 0;
switch (res->type)
{
- case _PROC_FORK:
+ case _CH_FORK:
in_forkee = true;
should_be_cb = sizeof (child_info_fork);
/* fall through */;
- case _PROC_SPAWN:
- case _PROC_EXEC:
+ case _CH_SPAWN:
+ case _CH_EXEC:
if (!should_be_cb)
should_be_cb = sizeof (child_info_spawn);
if (should_be_cb != res->cb)
multiple_cygwin_problem ("fhandler size", res->fhandler_union_cb, sizeof (fhandler_union));
if (res->isstraced ())
{
- res->ready (false);
for (unsigned i = 0; !being_debugged () && i < 10000; i++)
yield ();
strace.hello ();
default:
system_printf ("unknown exec type %d", res->type);
/* intentionally fall through */
- case _PROC_WHOOPS:
+ case _CH_WHOOPS:
res = NULL;
break;
}
/* If we're execing we may have "inherited" a list of children forked by the
previous process executing under this pid. Reattach them here so that we
can wait for them. */
- if (type == _PROC_EXEC)
+ if (type == _CH_EXEC)
reattach_children ();
ready (true);
cygwin_user_h = child_proc_info->user_h;
switch (child_proc_info->type)
{
- case _PROC_FORK:
+ case _CH_FORK:
fork_info->handle_fork ();
break;
- case _PROC_SPAWN:
- case _PROC_EXEC:
+ case _CH_SPAWN:
+ case _CH_EXEC:
spawn_info->handle_spawn ();
break;
}
{
if (_cygwin_testing && (strstr (what, "proc") || strstr (what, "cygheap")))
{
- child_proc_info->type = _PROC_WHOOPS;
+ child_proc_info->type = _CH_WHOOPS;
return;
}
void
debug_fixup_after_fork_exec ()
{
+debug_printf ("BEFORE");
/* No lock needed at this point */
handle_list *hl;
for (hl = &cygheap->debug.starth; hl->next != NULL; /* nothing */)
hl = hl->next;
else
delete_handle (hl); // removes hl->next
+debug_printf ("AFTER");
}
static bool __stdcall
extern void sigdelayed ();
};
-extern child_info_spawn *chExeced;
-
static BOOL WINAPI ctrl_c_handler (DWORD);
/* This is set to indicate that we have already exited. */
}
debug_printf ("In cygwin_except_handler exc %p at %p sp %p", e->ExceptionCode, in->Eip, in->Esp);
- debug_printf ("In cygwin_except_handler sig %d at %p", si.si_signo, in->Eip);
+ debug_printf ("In cygwin_except_handler signal %d at %p", si.si_signo, in->Eip);
bool masked = !!(me.sigmask & SIGTOMASK (si.si_signo));
if (masked)
/* Clear any waiting threads prior to dispatching to handler function */
int res = SetEvent (signal_arrived); // For an EINTR case
proc_subproc (PROC_CLEARWAIT, 1);
- sigproc_printf ("armed signal_arrived %p, sig %d, res %d", signal_arrived,
+ sigproc_printf ("armed signal_arrived %p, signal %d, res %d", signal_arrived,
sig, res);
}
if (tls->sig)
{
- sigproc_printf ("trying to send sig %d but signal %d already armed",
+ sigproc_printf ("trying to send signal %d but signal %d already armed",
sig, tls->sig);
goto out;
}
}
}
- if (chExeced)
- {
- chExeced->set_saw_ctrl_c ();
- return TRUE;
- }
+ if (ch_spawn.set_saw_ctrl_c ())
+ return TRUE;
/* We're only the process group leader when we have a valid pinfo structure.
If we don't have one, then the parent "stub" will handle the signal. */
bool masked;
void *handler;
- if (!hExeced || (void *) thissig.sa_handler == (void *) SIG_IGN)
+ if (!have_execed || (void *) thissig.sa_handler == (void *) SIG_IGN)
handler = (void *) thissig.sa_handler;
else if (tls)
return 1;
void
_cygtls::signal_exit (int rc)
{
- if (hExeced)
+ if (have_execed)
{
sigproc_printf ("terminating captive process");
- TerminateProcess (hExeced, sigExeced = rc);
+ TerminateProcess (ch_spawn, sigExeced = rc);
}
signal_debugger (rc & 0x7f);
stackdump (thread_context.ebp, 1, 1);
lock_process until_exit (true);
- if (hExeced || exit_state > ES_PROCESS_LOCKED)
+ if (have_execed || exit_state > ES_PROCESS_LOCKED)
myself.exit (rc);
/* Starve other threads in a vain attempt to stop them from doing something
#include "cygerrno.h"
#include "path.h"
#include "fhandler.h"
+#include "sync.h"
+#include "dtable.h"
+#include "cygheap.h"
+#include "child_info.h"
/*
* Robert Collins:
int
fhandler_dev_clipboard::close ()
{
- if (!hExeced)
+ if (!have_execed)
{
eof = true;
pos = 0;
#include "tls_pbuf.h"
#include "registry.h"
#include <asm/socket.h>
+#include "sync.h"
+#include "child_info.h"
/* Don't make this bigger than NT_MAX_PATH as long as the temporary buffer
is allocated using tmp_pathbuf!!! */
{
CloseHandle (get_io_handle ());
CloseHandle (get_output_handle ());
- if (!hExeced)
+ if (!have_execed)
cygheap->manage_console_count ("fhandler_console::close", -1);
return 0;
}
#include "cygerrno.h"
#include "path.h"
#include "fhandler.h"
+#include "sync.h"
+#include "dtable.h"
+#include "cygheap.h"
+#include "child_info.h"
#define RANDOM 8
#define URANDOM 9
int
fhandler_dev_random::close ()
{
- if (!hExeced && crypt_prov)
+ if (!have_execed && crypt_prov)
while (!CryptReleaseContext (crypt_prov, 0)
&& GetLastError () == ERROR_BUSY)
Sleep (10);
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
+#include "child_info.h"
#define _COMPILING_NEWLIB
#include <dirent.h>
res = -1;
}
}
- if (!hExeced && value_name)
+ if (!have_execed && value_name)
{
cfree (value_name);
value_name = NULL;
#include "cygheap.h"
#include "shared_info.h"
#include "sigproc.h"
+#include "child_info.h"
/* Media changes and bus resets are sometimes reported and the function
hasn't been executed. We repeat all functions which return with one
int ret = 0;
int cret = 0;
- if (!hExeced)
+ if (!have_execed)
{
lock (-1);
ret = mt.drive (driveno ())->close (get_handle (), is_rewind_device ());
void
fhandler_pty_slave::cleanup ()
{
- /* This used to always call fhandler_pty_common::close when hExeced but that
- caused multiple closes of the handles associated with this pty. Since
- close_all_files is not called until after the cygwin process has synced
- or before a non-cygwin process has exited, it should be safe to just
- close this normally. cgf 2006-05-20 */
+ /* This used to always call fhandler_pty_common::close when we were execing
+ but that caused multiple closes of the handles associated with this pty.
+ Since close_all_files is not called until after the cygwin process has
+ synced or before a non-cygwin process has exited, it should be safe to
+ just close this normally. cgf 2006-05-20 */
cygheap->manage_console_count ("fhandler_pty_slave::close", -1);
report_tty_counts (this, "closed", "");
}
fhandler_pty_common::close ();
- if (hExeced || get_ttyp ()->master_pid != myself->pid)
- termios_printf ("not clearing: %d, master_pid %d", hExeced, get_ttyp ()->master_pid);
+ if (have_execed || get_ttyp ()->master_pid != myself->pid)
+ termios_printf ("not clearing: %d, master_pid %d", have_execed, get_ttyp ()->master_pid);
else
get_ttyp ()->set_master_closed ();
#include "fhandler.h"
#include "dtable.h"
#include "cygheap.h"
+#include "sync.h"
+#include "child_info.h"
#include <dirent.h>
int
fhandler_virtual::close ()
{
- if (!hExeced)
+ if (!have_execed)
{
if (filebuf)
{
&si,
&pi);
- if (!rc)
+ if (rc)
+ debug_printf ("forked pid %u", pi.dwProcessId);
+ else
{
this_errno = geterrno_from_win_error ();
error ("CreateProcessW failed for '%W'", myself->progname);
HANDLE NO_COPY hProcToken;
HANDLE NO_COPY hProcImpToken;
HMODULE NO_COPY cygwin_hmodule;
-HANDLE NO_COPY hExeced;
int NO_COPY sigExeced;
WCHAR NO_COPY windows_system_directory[MAX_PATH];
UINT NO_COPY windows_system_directory_length;
else if (!child_proc_info) /* child_proc_info is only set when this process
was started by another cygwin process */
procinfo->start_time = time (NULL); /* Register our starting time. */
- else if (cygheap->pid_handle)
+ else if (::cygheap->pid_handle)
{
- ForceCloseHandle (cygheap->pid_handle);
- cygheap->pid_handle = NULL;
+ ForceCloseHandle (::cygheap->pid_handle);
+ ::cygheap->pid_handle = NULL;
}
}
}
# undef self
+inline void
+pinfo::_pinfo_release ()
+{
+ if (procinfo)
+ {
+ void *unmap_procinfo = procinfo;
+ procinfo = NULL;
+ UnmapViewOfFile (unmap_procinfo);
+ }
+ HANDLE close_h;
+ if (h)
+ {
+ close_h = h;
+ h = NULL;
+ ForceCloseHandle1 (close_h, pinfo_shared_handle);
+ }
+}
+
void
pinfo::init (pid_t n, DWORD flag, HANDLE h0)
{
DWORD access = FILE_MAP_READ
| (flag & (PID_IN_USE | PID_EXECED | PID_MAP_RW)
? FILE_MAP_WRITE : 0);
- if (!h0)
+ if (!h0 || myself.h)
shloc = (flag & (PID_IN_USE | PID_EXECED)) ? SH_JUSTCREATE : SH_JUSTOPEN;
else
{
break;
loop:
- release ();
+ _pinfo_release ();
if (h0)
yield ();
}
else
{
h = h0;
- release ();
+ _pinfo_release ();
}
}
debug_printf ("NtSetSecurityObject %p", status);
}
+pinfo::pinfo (HANDLE parent, pinfo_minimal& from, pid_t pid):
+ pinfo_minimal (), destroy (false), procinfo (NULL), waiter_ready (false),
+ wait_thread (NULL)
+{
+ HANDLE herr;
+ const char *duperr = NULL;
+ if (!DuplicateHandle (parent, herr = from.rd_proc_pipe, GetCurrentProcess (),
+ &rd_proc_pipe, 0, false, DUPLICATE_SAME_ACCESS))
+ duperr = "couldn't duplicate parent rd_proc_pipe handle %p for forked child %d after exec, %E";
+ else if (!DuplicateHandle (parent, herr = from.hProcess, GetCurrentProcess (),
+ &hProcess, 0, false, DUPLICATE_SAME_ACCESS))
+ duperr = "couldn't duplicate parent process handle %p for forked child %d after exec, %E";
+ else
+ {
+ h = NULL;
+ DuplicateHandle (parent, from.h, GetCurrentProcess (), &h, 0, false,
+ DUPLICATE_SAME_ACCESS);
+ init (pid, PID_MAP_RW, h);
+ if (*this)
+ return;
+ }
+
+ if (duperr)
+ debug_printf (duperr, herr, pid);
+
+ /* Returning with procinfo == NULL. Any open handles will be closed by the
+ destructor. */
+}
+
const char *
_pinfo::_ctty (char *buf)
{
si.si_stime = pchildren[rc].rusage_self.ru_stime;
#endif
pid_t pid = vchild->pid;
+ bool its_me = vchild == myself;
for (;;)
{
break;
}
+ if (!its_me && have_execed_cygwin)
+ break;
+
si.si_uid = vchild->uid;
switch (buf)
continue;
case 0:
/* Child exited. Do some cleanup and signal myself. */
- CloseHandle (vchild.rd_proc_pipe);
- vchild.rd_proc_pipe = NULL;
vchild.maybe_set_exit_code_from_windows ();
if (WIFEXITED (vchild->exitcode))
si.si_code = CLD_EXITED;
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. */
- if (hExeced)
- {
- /* execing. no signals available now. */
- proc_subproc (PROC_CLEARWAIT, 0);
- break;
- }
+ if (its_me && ch_spawn.signal_myself_exited ())
+ 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
waiter_ready = false;
/* Fire up a new thread to track the subprocess */
- cygthread *h = new cygthread (proc_waiter, this, "proc_waiter");
+ cygthread *h = new cygthread (proc_waiter, this, "waitproc");
if (!h)
sigproc_printf ("tracking thread creation failed for pid %d", (*this)->pid);
else
{
wait_thread = h;
- sigproc_printf ("created tracking thread for pid %d, winpid %p, rd_pipe %p",
+ sigproc_printf ("created tracking thread for pid %d, winpid %p, rd_proc_pipe %p",
(*this)->pid, (*this)->dwProcessId, rd_proc_pipe);
}
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)
+ if (wr_proc_pipe == INVALID_HANDLE_VALUE || !myself->wr_proc_pipe || have_execed)
/* no parent */;
else
{
void
pinfo::release ()
{
- if (procinfo)
+ _pinfo_release ();
+ HANDLE close_h;
+ if (rd_proc_pipe)
{
- void *unmap_procinfo = procinfo;
- procinfo = NULL;
- UnmapViewOfFile (unmap_procinfo);
+ close_h = rd_proc_pipe;
+ rd_proc_pipe = NULL;
+ ForceCloseHandle1 (close_h, rd_proc_pipe);
}
- if (h)
+ if (hProcess)
{
- HANDLE close_h = h;
- h = NULL;
- ForceCloseHandle1 (close_h, pinfo_shared_handle);
+ close_h = hProcess;
+ hProcess = NULL;
+ ForceCloseHandle1 (close_h, childhProc);
}
}
}
pinfo& p = pinfolist[nelem];
+ memset (&p, 0, sizeof (p));
- /* Open a the process to prevent a subsequent exit from invalidating the
+ /* Open a process to prevent a subsequent exit from invalidating the
shared memory region. */
p.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, false, pid);
_onreturn onreturn (p.hProcess);
/* 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).
- */
+ make a copy of the shared memory area if it exists (it may not). */
bool perform_copy;
if (!p.hProcess)
perform_copy = true;
else
{
*pnew = *p.procinfo;
- if ((_pinfo *) p != (_pinfo *) myself)
- p.release ();
+ p.release ();
p.procinfo = pnew;
p.destroy = false;
}
if (pinfolist[i] == (_pinfo *) myself)
continue;
else if (pinfolist[i].hProcess)
- {
- if (pinfolist[i])
- pinfolist[i].release ();
- CloseHandle (pinfolist[i].hProcess);
- }
+ pinfolist[i].release ();
else if ((p = pinfolist[i]))
{
pinfolist[i].procinfo = NULL;
public:
HANDLE wr_proc_pipe;
DWORD wr_proc_pipe_owner;
- friend class pinfo;
+ friend class pinfo_minimal;
};
DWORD WINAPI commune_process (void *);
__ALERT_ALIVE = 112
};
-class pinfo
+class pinfo_minimal
{
HANDLE h;
- _pinfo *procinfo;
- bool destroy;
public:
- HANDLE rd_proc_pipe;
HANDLE hProcess;
+ HANDLE rd_proc_pipe;
+ pinfo_minimal (): h (NULL), hProcess (NULL), rd_proc_pipe (NULL) {}
+ friend class pinfo;
+};
+
+class pinfo: public pinfo_minimal
+{
+ bool destroy;
+ _pinfo *procinfo;
+public:
bool waiter_ready;
class cygthread *wait_thread;
+
void init (pid_t, DWORD, HANDLE) __attribute__ ((regparm(3)));
- pinfo (): procinfo (NULL), rd_proc_pipe (NULL) {}
- pinfo (_pinfo *x): procinfo (x), rd_proc_pipe (NULL), hProcess (NULL) {}
- pinfo (pid_t n) : rd_proc_pipe (NULL), hProcess (NULL) {init (n, 0, NULL);}
- pinfo (pid_t n, DWORD flag) : rd_proc_pipe (NULL), hProcess (NULL), waiter_ready (0), wait_thread (NULL) {init (n, flag, NULL);}
+ pinfo (_pinfo *x = NULL): pinfo_minimal (), destroy (false), procinfo (x),
+ waiter_ready (false), wait_thread (NULL) {}
+ pinfo (pid_t n, DWORD flag = 0): pinfo_minimal (), destroy (false),
+ procinfo (NULL), waiter_ready (false),
+ wait_thread (NULL)
+ {
+ init (n, flag, NULL);
+ }
+ pinfo (HANDLE, pinfo_minimal&, pid_t);
void thisproc (HANDLE) __attribute__ ((regparm (2)));
+ inline void _pinfo_release ();
void release ();
bool wait () __attribute__ ((regparm (1)));
~pinfo ()
_pinfo *operator * () const {return procinfo;}
operator _pinfo * () const {return procinfo;}
void preserve () { destroy = false; }
+ void allow_remove () { destroy = true; }
#ifndef _SIGPROC_H
int reattach () {system_printf ("reattach is not here"); return 0;}
int remember () {system_printf ("remember is not here"); return 0;}
#define _P_VFORK 0
#define _P_SYSTEM 512
-/* Add this flag in calls to spawn_guts if the calling function is one of
- 'p' type functions: execlp, execvp, spawnlp, spawnvp. Per POSIX, only
- these p-type functions fall back to call /bin/sh if the file is not a
+/* Add this flag in calls to child_info_spawn::worker if the calling function
+ is one of 'p' type functions: execlp, execvp, spawnlp, spawnvp. Per POSIX,
+ only these p-type functions fall back to call /bin/sh if the file is not a
binary. The setting of _P_PATH_TYPE_EXEC is used as a bool value in
av::fixup to decide if the file should be evaluated as a script, or if
ENOEXEC should be returned. */
res = -1;
}
CloseHandle (h);
- sigproc_printf ("returning sig %d", res);
+ sigproc_printf ("returning signal %d", res);
return res;
}
#include "path.h"
#include "fhandler.h"
#include "dtable.h"
+#include "sigproc.h"
#include "cygheap.h"
#include "child_info_magic.h"
#include "shared_info.h"
#include "cygtls.h"
-#include "sigproc.h"
#include "pinfo.h"
#include "ntdll.h"
w = waitq_head.next;
waitq_head.next = wval; /* Add at the beginning. */
wval->next = w; /* Link in rest of the list. */
- clearing = 0;
+ clearing = false;
goto scan_wait;
+ case PROC_EXEC_CLEANUP:
+ while (nprocs)
+ remove_proc (0);
+ for (w = &waitq_head; w->next != NULL; w = w->next)
+ CloseHandle (w->next->ev);
+ break;
+
/* Clear all waiting threads. Called from exceptions.cc prior to
the main thread's dispatch to a signal handler function.
(called from wait_sig thread) */
proc_subproc (PROC_CLEARWAIT, 1);
/* Clean out proc processes from the pid list. */
- int i;
- for (i = 0; i < nprocs; i++)
+ for (int i = 0; i < nprocs; i++)
{
- /* FIXME: Resetting the ppid to 1 when this process execs is decidedly
- non-UNIXy. We should, at the very least, keep a list of pids
- for the exec process to reset when *it* exits. However, avoiding
- setting ppid when we are exec'ing causes the ppid to *never* be
- set to 1 so we don't do that either.
- if (!hExeced)
- */
- if (!hExeced || ISSTATE (myself, PID_NOTCYGWIN))
- procs[i]->ppid = 1;
+ procs[i]->ppid = 1;
if (procs[i].wait_thread)
- {
- // CloseHandle (procs[i].rd_proc_pipe);
- procs[i].wait_thread->terminate_thread ();
- }
+ procs[i].wait_thread->terminate_thread ();
procs[i].release ();
}
nprocs = 0;
api_fatal ("couldn't create signal pipe, %E");
ProtectHandle (my_readsig);
myself->sendsig = my_sendsig;
- new cygthread (wait_sig, cygself, "sig");
/* sync_proc_subproc is used by proc_subproc. It serializes
access to the children and proc arrays. */
sync_proc_subproc.init ("sync_proc_subproc");
+ new cygthread (wait_sig, cygself, "sig");
}
/* Called on process termination to terminate signal and process threads.
pack.wakeup = NULL;
bool wait_for_completion;
- if (!(its_me = (!hExeced && (p == NULL || p == myself || p == myself_nowait))))
+ if (!(its_me = (!have_execed && (p == NULL || p == myself || p == myself_nowait))))
{
/* It is possible that the process is not yet ready to receive messages
* or that it has exited. Detect this.
}
int child_info::retry_count = 10;
+
/* Initialize some of the memory block passed to child processes
by fork/spawn/exec. */
-
-child_info::child_info (unsigned in_cb, child_info_types chtype, bool need_subproc_ready)
+child_info::child_info (unsigned in_cb, child_info_types chtype,
+ bool need_subproc_ready)
{
- memset (this, 0, in_cb);
cb = in_cb;
/* It appears that when running under WOW64 on Vista 64, the first DWORD
}
child_info_fork::child_info_fork () :
- child_info (sizeof *this, _PROC_FORK, true)
+ child_info (sizeof *this, _CH_FORK, true)
{
}
child_info_spawn::child_info_spawn (child_info_types chtype, bool need_subproc_ready) :
child_info (sizeof *this, chtype, need_subproc_ready)
{
+ if (type == _CH_EXEC)
+ {
+ hExeced = NULL;
+ if (myself->wr_proc_pipe)
+ ev = NULL;
+ else if (!(ev = CreateEvent (&sec_none_nih, false, false, NULL)))
+ api_fatal ("couldn't create signalling event for exec, %E");
+
+ get_proc_lock (PROC_EXECING, 0);
+ lock = &sync_proc_subproc;
+ /* exit with lock held */
+ }
+}
+
+void
+child_info_spawn::cleanup ()
+{
+ if (moreinfo)
+ {
+ if (moreinfo->envp)
+ {
+ for (char **e = moreinfo->envp; *e; e++)
+ cfree (*e);
+ cfree (moreinfo->envp);
+ }
+ if (type != _CH_SPAWN && moreinfo->myself_pinfo)
+ CloseHandle (moreinfo->myself_pinfo);
+ cfree (moreinfo);
+ }
+ moreinfo = NULL;
+ nchildren = 0;
+ if (ev)
+ {
+ CloseHandle (ev);
+ ev = NULL;
+ }
+debug_printf ("type %d, type == _CH_EXEC == %d, hExeced %p", type, type == _CH_EXEC, hExeced);
+ if (type == _CH_EXEC)
+ {
+ if (iscygwin () && hExeced)
+{debug_printf ("cleaning up");
+ proc_subproc (PROC_EXEC_CLEANUP, 0);
+}
+ sync_proc_subproc.release ();
+ }
+ type = _CH_NADA;
}
/* Record any non-reaped subprocesses to be passed to about-to-be-execed
void
child_info_spawn::record_children ()
{
- /* FIXME: locking */
- for (nchildren = 0; nchildren < nprocs; nchildren++)
- {
- children[nchildren].pid = procs[nchildren]->pid;
- children[nchildren].rd_proc_pipe = procs[nchildren].rd_proc_pipe;
- }
+ if (type == _CH_EXEC && iscygwin ())
+ for (nchildren = 0; nchildren < nprocs; nchildren++)
+ {
+ children[nchildren].pid = procs[nchildren]->pid;
+ children[nchildren].p = procs[nchildren];
+ }
}
/* Reattach non-reaped subprocesses passed in from the cygwin process
{
for (int i = 0; i < nchildren; i++)
{
- pinfo p (children[i].pid, PID_MAP_RW);
+ pinfo p (parent, children[i].p, children[i].pid);
if (!p)
- /* pid no longer exists */;
- else if (!DuplicateHandle (parent, children[i].rd_proc_pipe,
- GetCurrentProcess (), &p.rd_proc_pipe, 0,
- false, DUPLICATE_SAME_ACCESS))
- debug_printf ("couldn't duplicate parent %p handles for forked children after exec, %E",
- children[i].rd_proc_pipe);
- else if (!(p.hProcess = OpenProcess (PROCESS_QUERY_INFORMATION, false, p->dwProcessId)))
- CloseHandle (p.rd_proc_pipe);
+ debug_only_printf ("couldn't reattach child %d from previous process", children[i].pid);
else if (!p.reattach ())
- {
- CloseHandle (p.hProcess);
- CloseHandle (p.rd_proc_pipe);
- }
+ debug_only_printf ("attach of child process %d failed", children[i].pid);
+ else
+ debug_only_printf ("reattached pid %d<%u>, process handle %p, rd_proc_pipe %p->%p",
+ p->pid, p->dwProcessId, p.hProcess,
+ children[i].p.rd_proc_pipe, p.rd_proc_pipe);
}
}
if (dynamically_loaded)
sigproc_printf ("not really ready");
else if (!SetEvent (subproc_ready))
- api_fatal ("SetEvent failed");
+ api_fatal ("SetEvent failed, %E");
else
sigproc_printf ("signalled %p that I was ready", subproc_ready);
{
res = true;
exit_code = STILL_ACTIVE;
- if (type == _PROC_EXEC && myself->wr_proc_pipe)
+ if (type == _CH_EXEC && myself->wr_proc_pipe)
{
ForceCloseHandle1 (hProcess, childhProc);
hProcess = NULL;
static bool __stdcall
remove_proc (int ci)
{
- if (procs[ci]->exists ())
+ if (have_execed)
+ procs[ci].wait_thread->terminate_thread ();
+ else if (procs[ci]->exists ())
return true;
sigproc_printf ("removing procs[%d], pid %d, nprocs %d", ci, procs[ci]->pid,
nprocs);
if (procs[ci] != myself)
- {
- procs[ci].release ();
- if (procs[ci].hProcess)
- ForceCloseHandle1 (procs[ci].hProcess, childhProc);
- }
+ procs[ci].release ();
if (ci < --nprocs)
{
/* Wait for proc_waiter thread to make a copy of this element before
if (!terminated)
{
- sigproc_printf ("stopped child, stopsig %d", child->stopsig);
+ sigproc_printf ("stopped child, stop signal %d", child->stopsig);
if (child->stopsig == SIGCONT)
w->status = __W_CONTINUED;
else
// We need a per-thread queue since each thread can have its own
// list of blocked signals. CGF 2005-08-24
if (sigq.sigs[sig].si.si_signo && sigq.sigs[sig].tls == pack.tls)
- sigproc_printf ("sig %d already queued", pack.si.si_signo);
+ sigproc_printf ("signal %d already queued", pack.si.si_signo);
else
{
int sigres = pack.process ();
{
PROC_ADDCHILD = 1, // add a new subprocess to list
PROC_REATTACH_CHILD = 2, // reattach after exec
- PROC_DETACHED_CHILD = 3, // set up a detached child
- PROC_CLEARWAIT = 4, // clear all waits - signal arrived
- PROC_WAIT = 5, // setup for wait() for subproc
- PROC_NOTHING = 6 // nothing, really
+ PROC_EXEC_CLEANUP = 3, // cleanup waiting children after exec
+ PROC_DETACHED_CHILD = 4, // set up a detached child
+ PROC_CLEARWAIT = 5, // clear all waits - signal arrived
+ PROC_WAIT = 6, // setup for wait() for subproc
+ PROC_EXECING = 7, // used to get a lock when execing
+ PROC_NOTHING = 8 // nothing, really
};
struct sigpacket
};
#endif
-child_info_spawn NO_COPY *chExeced;
-
/* Add .exe to PROG if not already present and see if that exists.
If not, return PROG (converted from posix to win32 rules if necessary).
The result is always BUF.
return retval;
}
-/* Utility for spawn_guts. */
+/* Utility for child_info_spawn::worker. */
static HANDLE
handle (int fd, bool writing)
# undef cleanup
}
+NO_COPY child_info_spawn ch_spawn;
int
-spawn_guts (const char *prog_arg, const char *const *argv,
- const char *const envp[], int mode, int __stdin, int __stdout)
+child_info_spawn::worker (const char *prog_arg, const char *const *argv,
+ const char *const envp[], int mode,
+ int in__stdin, int in__stdout)
{
bool rc;
pid_t cygpid;
return -1;
}
- syscall_printf ("spawn_guts (%d, %.9500s)", mode, prog_arg);
+ syscall_printf ("mode = %d, prog_arg = %.9500s", mode, prog_arg);
/* FIXME: This is no error condition on Linux. */
if (argv == NULL)
pthread_cleanup_push (do_cleanup, (void *) &cleanup);
av newargv;
linebuf one_line;
- child_info_spawn ch;
PWCHAR envblock = NULL;
path_conv real_path;
bool reset_sendsig = false;
PWCHAR runpath = tp.w_get ();
int c_flags;
bool wascygexec;
- cygheap_exec_info *moreinfo;
bool null_app_name = false;
STARTUPINFOW si = {};
child_info_types chtype;
if (mode != _P_OVERLAY)
- chtype = PROC_SPAWN;
+ chtype = _CH_SPAWN;
else
- chtype = PROC_EXEC;
+ chtype = _CH_EXEC;
moreinfo = (cygheap_exec_info *) ccalloc_abort (HEAP_1_EXEC, 1,
sizeof (cygheap_exec_info));
if (res)
goto out;
- if (!real_path.iscygexec () && cygheap->cwd.get_error ())
+ if (!real_path.iscygexec () && ::cygheap->cwd.get_error ())
{
small_printf ("Error: Current working directory %s.\n"
"Can't start native Windows application from here.\n\n",
- cygheap->cwd.get_error_desc ());
- set_errno (cygheap->cwd.get_error ());
+ ::cygheap->cwd.get_error_desc ());
+ set_errno (::cygheap->cwd.get_error ());
res = -1;
goto out;
}
/* Set up needed handles for stdio */
si.dwFlags = STARTF_USESTDHANDLES;
- si.hStdInput = handle ((__stdin < 0 ? 0 : __stdin), false);
- si.hStdOutput = handle ((__stdout < 0 ? 1 : __stdout), true);
+ si.hStdInput = handle ((in__stdin < 0 ? 0 : in__stdin), false);
+ si.hStdOutput = handle ((in__stdout < 0 ? 1 : in__stdout), true);
si.hStdError = handle (2, true);
si.cb = sizeof (si);
/* Save a copy of a handle to the current process around the first time we
exec so that the pid will not be reused. Why did I stop cygwin from
generating its own pids again? */
- if (cygheap->pid_handle)
+ if (::cygheap->pid_handle)
/* already done previously */;
else if (DuplicateHandle (GetCurrentProcess (), GetCurrentProcess (),
- GetCurrentProcess (), &cygheap->pid_handle,
+ GetCurrentProcess (), &::cygheap->pid_handle,
PROCESS_QUERY_INFORMATION, TRUE, 0))
- ProtectHandleINH (cygheap->pid_handle);
+ ProtectHandleINH (::cygheap->pid_handle);
else
system_printf ("duplicate to pid_handle failed, %E");
}
syscall_printf ("null_app_name %d (%W, %.9500W)", null_app_name,
runpath, wone_line);
- cygbench ("spawn-guts");
+ cygbench ("spawn-worker");
if (!real_path.iscygexec())
- cygheap->fdtab.set_file_pointers_for_exec ();
+ ::cygheap->fdtab.set_file_pointers_for_exec ();
moreinfo->envp = build_env (envp, envblock, moreinfo->envc,
real_path.iscygexec ());
res = -1;
goto out;
}
- ch.set (chtype, real_path.iscygexec ());
- ch.moreinfo = moreinfo;
- ch.__stdin = __stdin;
- ch.__stdout = __stdout;
- if (mode == _P_OVERLAY && ch.iscygwin ())
- ch.record_children ();
+ set (chtype, real_path.iscygexec ());
+ __stdin = in__stdin;
+ __stdout = in__stdout;
+ record_children ();
- si.lpReserved2 = (LPBYTE) &ch;
- si.cbReserved2 = sizeof (ch);
+ si.lpReserved2 = (LPBYTE) this;
+ si.cbReserved2 = sizeof (*this);
- /* Depends on ch.set call above.
+ /* Depends on set call above.
Some file types might need extra effort in the parent after CreateProcess
and before copying the datastructures to the child. So we have to start
the child in suspend state, unfortunately, to avoid a race condition. */
if (!newargv.win16_exe
- && (!ch.iscygwin () || mode != _P_OVERLAY
- || cygheap->fdtab.need_fixup_before ()))
+ && (!iscygwin () || mode != _P_OVERLAY
+ || ::cygheap->fdtab.need_fixup_before ()))
c_flags |= CREATE_SUSPENDED;
/* If a native application should be spawned, we test here if the spawning
process is running in a console and, if so, if it's a foreground or
in a console will break native processes running in the background,
because the Ctrl-C event is sent to all processes in the console, unless
they ignore it explicitely. CREATE_NEW_PROCESS_GROUP does that for us. */
- if (!ch.iscygwin () && myself->ctty >= 0 && iscons_dev (myself->ctty)
+ if (!iscygwin () && myself->ctty >= 0 && iscons_dev (myself->ctty)
&& fhandler_console::tc_getpgid () != getpgrp ())
c_flags |= CREATE_NEW_PROCESS_GROUP;
- ch.refresh_cygheap ();
+ refresh_cygheap ();
/* When ruid != euid we create the new process under the current original
account and impersonate in child, this way maintaining the different
effective vs. real ids.
FIXME: If ruid != euid and ruid != saved_uid we currently give
up on ruid. The new process will have ruid == euid. */
loop:
- cygheap->user.deimpersonate ();
+ ::cygheap->user.deimpersonate ();
if (!real_path.iscygexec () && mode == _P_OVERLAY)
myself->process_state |= PID_NOTCYGWIN;
- if (!cygheap->user.issetuid ()
- || (cygheap->user.saved_uid == cygheap->user.real_uid
- && cygheap->user.saved_gid == cygheap->user.real_gid
- && !cygheap->user.groups.issetgroups ()
- && !cygheap->user.setuid_to_restricted))
+ if (!::cygheap->user.issetuid ()
+ || (::cygheap->user.saved_uid == ::cygheap->user.real_uid
+ && ::cygheap->user.saved_gid == ::cygheap->user.real_gid
+ && !::cygheap->user.groups.issetgroups ()
+ && !::cygheap->user.setuid_to_restricted))
{
rc = CreateProcessW (runpath, /* image name - with full path */
wone_line, /* what was passed to exec */
risk, but we don't want to disable this behaviour for older
OSes because it's still heavily used by some users. They have
been warned. */
- if (!cygheap->user.setuid_to_restricted
+ if (!::cygheap->user.setuid_to_restricted
&& wcscasecmp (wstname, L"WinSta0") != 0)
{
WCHAR sid[128];
sa = sec_user ((PSECURITY_ATTRIBUTES) alloca (1024),
- cygheap->user.sid ());
+ ::cygheap->user.sid ());
/* We're creating a window station per user, not per logon session.
First of all we might not have a valid logon session for
the user (logon by create_token), and second, it doesn't
make sense in terms of security to create a new window
station for every logon of the same user. It just fills up
the system with window stations for no good reason. */
- hwst = CreateWindowStationW (cygheap->user.get_windows_id (sid), 0,
+ hwst = CreateWindowStationW (::cygheap->user.get_windows_id (sid), 0,
GENERIC_READ | GENERIC_WRITE, sa);
if (!hwst)
system_printf ("CreateWindowStation failed, %E");
}
}
- rc = CreateProcessAsUserW (cygheap->user.primary_token (),
+ rc = CreateProcessAsUserW (::cygheap->user.primary_token (),
runpath, /* image name - with full path */
wone_line, /* what was passed to exec */
&sec_none_nih, /* process security attrs */
/* Restore impersonation. In case of _P_OVERLAY this isn't
allowed since it would overwrite child data. */
if (mode != _P_OVERLAY || !rc)
- cygheap->user.reimpersonate ();
+ ::cygheap->user.reimpersonate ();
/* Set errno now so that debugging messages from it appear before our
final debugging message [this is a general rule for debugging
}
if (!(c_flags & CREATE_SUSPENDED))
- strace.write_childpid (ch, pi.dwProcessId);
+ strace.write_childpid (*this, pi.dwProcessId);
/* Fixup the parent data structures if needed and resume the child's
main thread. */
- if (cygheap->fdtab.need_fixup_before ())
- cygheap->fdtab.fixup_before_exec (pi.dwProcessId);
+ if (::cygheap->fdtab.need_fixup_before ())
+ ::cygheap->fdtab.fixup_before_exec (pi.dwProcessId);
if (mode != _P_OVERLAY)
cygpid = cygwin_pid (pi.dwProcessId);
cygpid = myself->pid;
/* We print the original program name here so the user can see that too. */
- syscall_printf ("%d = spawn_guts (%s, %.9500s)",
+ syscall_printf ("%d = child_info_spawn::worker (%s, %.9500s)",
rc ? cygpid : (unsigned int) -1, prog_arg, one_line.buf);
/* Name the handle similarly to proc_subproc. */
pid_t pid;
if (mode == _P_OVERLAY)
{
- chExeced = &ch; /* FIXME: there's a race here if a user sneaks in CTRL-C */
myself->dwProcessId = pi.dwProcessId;
strace.execing = 1;
myself.hProcess = hExeced = pi.hProcess;
orig_wr_proc_pipe = myself->dup_proc_pipe (pi.hProcess);
}
pid = myself->pid;
- if (!ch.iscygwin ())
+ if (!iscygwin ())
close_all_files ();
}
else
if (c_flags & CREATE_SUSPENDED)
{
ResumeThread (pi.hThread);
- strace.write_childpid (ch, pi.dwProcessId);
+ strace.write_childpid (*this, pi.dwProcessId);
}
ForceCloseHandle (pi.hThread);
sigproc_printf ("spawned windows pid %d", pi.dwProcessId);
- if ((mode == _P_DETACH || mode == _P_NOWAIT) && !ch.iscygwin ())
+ if ((mode == _P_DETACH || mode == _P_NOWAIT) && !iscygwin ())
synced = false;
else
- synced = ch.sync (pi.dwProcessId, pi.hProcess, INFINITE);
+ synced = sync (pi.dwProcessId, pi.hProcess, INFINITE);
switch (mode)
{
myself->wr_proc_pipe_owner = GetCurrentProcessId ();
myself->wr_proc_pipe = orig_wr_proc_pipe;
}
- if (!ch.proc_retry (pi.hProcess))
+ if (!proc_retry (pi.hProcess))
{
looped++;
goto loop;
extern bool is_toplevel_proc;
is_toplevel_proc = true;
myself.remember (false);
- waitpid (myself->pid, &res, 0);
+ wait_for_myself ();
}
}
+ this->cleanup ();
myself.exit (EXITCODE_NOSET);
break;
case _P_WAIT:
}
out:
+debug_printf ("about to call cleanup");
+ this->cleanup ();
if (envblock)
free (envblock);
pthread_cleanup_pop (1);
return (int) res;
-#undef ch
}
extern "C" int
switch (_P_MODE (mode))
{
case _P_OVERLAY:
- spawn_guts (path, argv, envp, mode);
- /* Errno should be set by spawn_guts. */
+ ch_spawn.worker (path, argv, envp, mode);
+ /* Errno should be set by worker. */
ret = -1;
break;
case _P_VFORK:
case _P_WAIT:
case _P_DETACH:
case _P_SYSTEM:
- ret = spawn_guts (path, argv, envp, mode);
+ ret = ch_spawn.worker (path, argv, envp, mode);
#ifdef NEWVFORK
if (vf)
{
#include "registry.h"
#include "environ.h"
#include "tls_pbuf.h"
+#include "sync.h"
+#include "child_info.h"
#undef _close
#undef _lseek
cygheap->fdtab.release (i);
}
- if (!hExeced && cygheap->ctty)
+ if (!have_execed && cygheap->ctty)
cygheap->close_ctty ();
if (h)
fcntl64 (stdchild, F_SETFD, stdchild_state | FD_CLOEXEC);
/* Start a shell process to run the given command without forking. */
- pid_t pid = spawn_guts ("/bin/sh", argv, cur_environ (), _P_NOWAIT,
- __std[0], __std[1]);
+ pid_t pid = ch_spawn.worker ("/bin/sh", argv, cur_environ (), _P_NOWAIT,
+ __std[0], __std[1]);
/* Reinstate the close-on-exec state */
fcntl64 (stdchild, F_SETFD, stdchild_state);
si.si_signo = tt->evp.sigev_signo;
si.si_sigval.sival_ptr = tt->evp.sigev_value.sival_ptr;
si.si_code = SI_TIMER;
- debug_printf ("%p sending sig %d", x, tt->evp.sigev_signo);
+ debug_printf ("%p sending signal %d", x, tt->evp.sigev_signo);
sig_send (myself_nowait, si);
break;
}
extern "C" void __stdcall _dll_crt0 ();
void dll_crt0_1 (void *);
void dll_dllcrt0_1 (void *);
-int spawn_guts (const char * prog_arg, const char *const *argv,
- const char *const envp[], int mode, int __stdin = -1,
- int __stdout = -1) __attribute__ ((regparm(3)));
/* dynamically loaded dll initialization */
extern "C" int dll_dllcrt0 (HMODULE, per_process *);