diff options
author | Christopher Faylor <me@cgf.cx> | 2005-06-01 03:46:56 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2005-06-01 03:46:56 +0000 |
commit | ce95c6407ef6ab1a60a1b1e2cd62ef4ae2081174 (patch) | |
tree | 6d083de1286c20546e090d2d62a45f918182b3af /winsup/cygwin/spawn.cc | |
parent | 302cb8165e957ac12528c221f263b358c859c831 (diff) | |
download | cygnal-ce95c6407ef6ab1a60a1b1e2cd62ef4ae2081174.tar.gz cygnal-ce95c6407ef6ab1a60a1b1e2cd62ef4ae2081174.tar.bz2 cygnal-ce95c6407ef6ab1a60a1b1e2cd62ef4ae2081174.zip |
* child_info.h (child_info::cygheap_h): Delete.
(child_info::dwProcessId): New field.
* cygheap.cc (init_cheap): Delete.
(dup_now): Ditto.
(cygheap_setup_for_child): Ditto.
(cygheap_setup_for_child_cleanup): Ditto.
(cygheap_fixup_in_child): Simplify. Use new "child_copy" function to copy heap
from parent.
(_csbrk): Don't attempt allocation if within cygheap section. Fix so that more
than one allocation will succeed.
(cygheap_init): Reset possibly-nonzero region to zero.
* cygheap.h (cygheap_setup_for_child): Delete declaration.
(cygheap_setup_for_child_cleanup): Ditto.
(cygheap_start): Define as an array.
* cygwin.sc: Modernize. Remove unneeded sections. Define cygheap here.
* dcrt0.cc (do_exit): Reflect argument change to close_all_files.
* dtable.cc (dtable::vfork_parent_restore): Ditto.
* dtable.h: Ditto.
* fhandler.h: Ditto.
* fork.cc (fork_copy): Call ReadProcessMemory if there is no thread
(indicating that we're execing).
(fork_child): Don't mess with hParent.
(fork_parent): Remove hParent stuff. It happens earlier now. Remove call to
cygheap_setup_for_child* stuff.
(fork): Put child_info_stuff in grouped structure. Issue error if parent
handle is not set.
(child_copy): New function.
* sigproc.cc (child_info::child_info): Put cygheap settings here. Set parent
handle.
(child_info::~child_info): Close parent handle if it exists.
* spawn.cc (spawn_guts): Reorganize so that ciresrv is allocated at only the
last minute so that cygheap changes are reflected. Delete cygheap_setup*
calls.
* syscalls.cc (close_all_files): Add an argument to flag when the fd entry
should be released.
* winsup.h (close_all_files): Add an argument to close_all_files declaration.
Declare child_copy.
Diffstat (limited to 'winsup/cygwin/spawn.cc')
-rw-r--r-- | winsup/cygwin/spawn.cc | 45 |
1 files changed, 17 insertions, 28 deletions
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc index 9faec772e..db8b4d97d 100644 --- a/winsup/cygwin/spawn.cc +++ b/winsup/cygwin/spawn.cc @@ -390,12 +390,8 @@ spawn_guts (const char * prog_arg, const char *const *argv, else chtype = PROC_EXEC; - child_info_spawn ciresrv (chtype); - si.lpReserved2 = (LPBYTE) &ciresrv; - si.cbReserved2 = sizeof (ciresrv); - - ciresrv.moreinfo = (cygheap_exec_info *) ccalloc (HEAP_1_EXEC, 1, sizeof (cygheap_exec_info)); - ciresrv.moreinfo->old_title = NULL; + cygheap_exec_info *moreinfo = (cygheap_exec_info *) ccalloc (HEAP_1_EXEC, 1, sizeof (cygheap_exec_info)); + moreinfo->old_title = NULL; /* CreateProcess takes one long string that is the command line (sigh). We need to quote any argument that has whitespace or embedded "'s. */ @@ -600,16 +596,16 @@ spawn_guts (const char * prog_arg, const char *const *argv, return -1; } - ciresrv.moreinfo->argc = newargv.argc; - ciresrv.moreinfo->argv = newargv; + moreinfo->argc = newargv.argc; + moreinfo->argv = newargv; if (mode != _P_OVERLAY || !DuplicateHandle (hMainProc, myself.shared_handle (), hMainProc, - &ciresrv.moreinfo->myself_pinfo, 0, + &moreinfo->myself_pinfo, 0, TRUE, DUPLICATE_SAME_ACCESS)) - ciresrv.moreinfo->myself_pinfo = NULL; + moreinfo->myself_pinfo = NULL; else - VerifyHandle (ciresrv.moreinfo->myself_pinfo); + VerifyHandle (moreinfo->myself_pinfo); skip_arg_parsing: PROCESS_INFORMATION pi = {NULL, 0, 0, 0}; @@ -665,13 +661,18 @@ spawn_guts (const char * prog_arg, const char *const *argv, syscall_printf ("null_app_name %d (%s, %.9500s)", null_app_name, runpath, one_line.buf); - void *newheap; - cygbench ("spawn-guts"); cygheap->fdtab.set_file_pointers_for_exec (); cygheap->user.deimpersonate (); + moreinfo->envp = build_env (envp, envblock, moreinfo->envc, real_path.iscygexec ()); + child_info_spawn ciresrv (chtype); + ciresrv.moreinfo = moreinfo; + + si.lpReserved2 = (LPBYTE) &ciresrv; + si.cbReserved2 = sizeof (ciresrv); + /* 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. @@ -682,9 +683,6 @@ spawn_guts (const char * prog_arg, const char *const *argv, && cygheap->user.saved_gid == cygheap->user.real_gid && !cygheap->user.groups.issetgroups ())) { - ciresrv.moreinfo->envp = build_env (envp, envblock, ciresrv.moreinfo->envc, - real_path.iscygexec ()); - newheap = cygheap_setup_for_child (&ciresrv, cygheap->fdtab.need_fixup_before ()); rc = CreateProcess (runpath, /* image name - with full path */ one_line.buf, /* what was passed to exec */ &sec_none_nih,/* process security attrs */ @@ -719,9 +717,6 @@ spawn_guts (const char * prog_arg, const char *const *argv, strcat (wstname, dskname); si.lpDesktop = wstname; - ciresrv.moreinfo->envp = build_env (envp, envblock, ciresrv.moreinfo->envc, - real_path.iscygexec ()); - newheap = cygheap_setup_for_child (&ciresrv, cygheap->fdtab.need_fixup_before ()); rc = CreateProcessAsUser (cygheap->user.primary_token (), runpath, /* image name - with full path */ one_line.buf, /* what was passed to exec */ @@ -758,7 +753,6 @@ spawn_guts (const char * prog_arg, const char *const *argv, myself->sendsig = myself->exec_sendsig; myself->exec_sendsig = NULL; } - cygheap_setup_for_child_cleanup (newheap, &ciresrv, 0); return -1; } @@ -779,13 +773,8 @@ spawn_guts (const char * prog_arg, const char *const *argv, /* Fixup the parent data structures if needed and resume the child's main thread. */ - if (!cygheap->fdtab.need_fixup_before ()) - cygheap_setup_for_child_cleanup (newheap, &ciresrv, 0); - else - { - cygheap->fdtab.fixup_before_exec (pi.dwProcessId); - cygheap_setup_for_child_cleanup (newheap, &ciresrv, 1); - } + if (cygheap->fdtab.need_fixup_before ()) + cygheap->fdtab.fixup_before_exec (pi.dwProcessId); if (mode != _P_OVERLAY) cygpid = cygwin_pid (pi.dwProcessId); @@ -807,7 +796,7 @@ spawn_guts (const char * prog_arg, const char *const *argv, myself.hProcess = hExeced = pi.hProcess; strcpy (myself->progname, real_path); // FIXME: race? sigproc_printf ("new process name %s", myself->progname); - close_all_files (); + close_all_files (true); /* If wr_proc_pipe doesn't exist then this process was not started by a cygwin process. So, we need to wait around until the process we've just "execed" dies. Use our own wait facility to wait for our own pid to exit (there |