2000-02-18 03:38:33 +08:00
|
|
|
/* fork.cc
|
|
|
|
|
2001-03-18 11:34:05 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <errno.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-03 12:16:35 +08:00
|
|
|
#include "cygheap.h"
|
2000-09-02 04:54:22 +08:00
|
|
|
#include "child_info.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#define NEED_VFORK
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "perthread.h"
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "perprocess.h"
|
|
|
|
#include "dll_init.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
#ifdef DEBUGGING
|
2001-09-06 12:41:59 +08:00
|
|
|
static int npid;
|
|
|
|
static int npid_max;
|
|
|
|
static pid_t fork_pids[100];
|
2000-11-15 14:27:48 +08:00
|
|
|
#endif
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Timeout to wait for child to start, parent to init child, etc. */
|
|
|
|
/* FIXME: Once things stabilize, bump up to a few minutes. */
|
|
|
|
#define FORK_WAIT_TIMEOUT (300 * 1000) /* 300 seconds */
|
|
|
|
|
|
|
|
#define dll_data_start &_data_start__
|
|
|
|
#define dll_data_end &_data_end__
|
|
|
|
#define dll_bss_start &_bss_start__
|
|
|
|
#define dll_bss_end &_bss_end__
|
|
|
|
|
|
|
|
void
|
|
|
|
per_thread::set (void *s)
|
2000-09-03 12:16:35 +08:00
|
|
|
{
|
|
|
|
if (s == PER_THREAD_FORK_CLEAR)
|
|
|
|
{
|
|
|
|
tls = TlsAlloc ();
|
|
|
|
s = NULL;
|
|
|
|
}
|
|
|
|
TlsSetValue (get_tls (), s);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
stack_base (child_info_fork &ch)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION m;
|
|
|
|
memset (&m, 0, sizeof m);
|
|
|
|
if (!VirtualQuery ((LPCVOID) &m, &m, sizeof m))
|
|
|
|
system_printf ("couldn't get memory info, %E");
|
|
|
|
|
|
|
|
ch.stacktop = m.AllocationBase;
|
|
|
|
ch.stackbottom = (LPBYTE) m.BaseAddress + m.RegionSize;
|
|
|
|
ch.stacksize = (DWORD) ch.stackbottom - (DWORD) &m;
|
|
|
|
debug_printf ("bottom %p, top %p, stack %p, size %d, reserve %d",
|
|
|
|
ch.stackbottom, ch.stacktop, &m, ch.stacksize,
|
|
|
|
(DWORD) ch.stackbottom - (DWORD) ch.stacktop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy memory from parent to child.
|
|
|
|
The result is a boolean indicating success. */
|
|
|
|
|
|
|
|
static int
|
|
|
|
fork_copy (PROCESS_INFORMATION &pi, const char *what, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *low;
|
|
|
|
int pass = 0;
|
|
|
|
|
|
|
|
va_start (args, what);
|
|
|
|
|
|
|
|
while ((low = va_arg (args, char *)))
|
|
|
|
{
|
|
|
|
char *high = va_arg (args, char *);
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
DWORD todo = wincap.chunksize () ?: high - low;
|
2000-02-18 03:38:33 +08:00
|
|
|
char *here;
|
|
|
|
|
|
|
|
for (here = low; here < high; here += todo)
|
|
|
|
{
|
|
|
|
DWORD done = 0;
|
|
|
|
if (here + todo > high)
|
|
|
|
todo = high - here;
|
|
|
|
int res = WriteProcessMemory (pi.hProcess, here, here, todo, &done);
|
|
|
|
debug_printf ("child handle %p, low %p, high %p, res %d", pi.hProcess,
|
|
|
|
low, high, res);
|
|
|
|
if (!res || todo != done)
|
|
|
|
{
|
|
|
|
if (!res)
|
|
|
|
__seterrno ();
|
|
|
|
/* If this happens then there is a bug in our fork
|
|
|
|
implementation somewhere. */
|
2001-06-19 05:18:59 +08:00
|
|
|
system_printf ("%s pass %d failed, %p..%p, done %d, windows pid %u, %E",
|
|
|
|
what, pass, low, high, done, pi.dwProcessId);
|
2000-02-18 03:38:33 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pass++;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_printf ("done");
|
|
|
|
return 1;
|
|
|
|
|
2001-08-05 05:10:52 +08:00
|
|
|
err:
|
2000-02-18 03:38:33 +08:00
|
|
|
TerminateProcess (pi.hProcess, 1);
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for child to finish what it's doing and signal us.
|
|
|
|
We don't want to wait forever here.If there's a problem somewhere
|
|
|
|
it'll hang the entire system (since all forks are mutex'd). If we
|
|
|
|
time out, set errno = EAGAIN and hope the app tries again. */
|
|
|
|
static int
|
|
|
|
sync_with_child (PROCESS_INFORMATION &pi, HANDLE subproc_ready,
|
|
|
|
BOOL hang_child, const char *s)
|
|
|
|
{
|
|
|
|
/* We also add the child process handle to the wait. If the child fails
|
|
|
|
to initialize (eg. because of a missing dll). Then this
|
|
|
|
handle will become signalled. This stops a *looong* timeout wait.
|
|
|
|
*/
|
|
|
|
HANDLE w4[2];
|
|
|
|
|
2000-10-12 12:38:29 +08:00
|
|
|
debug_printf ("waiting for child. reason: %s, hang_child %d", s,
|
|
|
|
hang_child);
|
2000-02-18 03:38:33 +08:00
|
|
|
w4[1] = pi.hProcess;
|
|
|
|
w4[0] = subproc_ready;
|
|
|
|
DWORD rc = WaitForMultipleObjects (2, w4, FALSE, FORK_WAIT_TIMEOUT);
|
|
|
|
|
|
|
|
if (rc == WAIT_OBJECT_0 ||
|
|
|
|
WaitForSingleObject (subproc_ready, 0) == WAIT_OBJECT_0)
|
|
|
|
/* That's ok */;
|
|
|
|
else if (rc == WAIT_FAILED || rc == WAIT_TIMEOUT)
|
|
|
|
{
|
|
|
|
if (rc != WAIT_FAILED)
|
|
|
|
system_printf ("WaitForMultipleObjects timed out");
|
|
|
|
else
|
|
|
|
system_printf ("WaitForMultipleObjects failed, %E");
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
syscall_printf ("-1 = fork(), WaitForMultipleObjects failed");
|
|
|
|
TerminateProcess (pi.hProcess, 1);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Child died. Clean up and exit. */
|
|
|
|
DWORD errcode;
|
|
|
|
GetExitCodeProcess (pi.hProcess, &errcode);
|
|
|
|
/* Fix me. This is not enough. The fork should not be considered
|
|
|
|
* to have failed if the process was essentially killed by a signal.
|
|
|
|
*/
|
|
|
|
if (errcode != STATUS_CONTROL_C_EXIT)
|
|
|
|
{
|
|
|
|
system_printf ("child %d(%p) died before initialization with status code %p",
|
|
|
|
pi.dwProcessId, pi.hProcess, errcode);
|
|
|
|
system_printf ("*** child state %s", s);
|
|
|
|
#ifdef DEBUGGING
|
|
|
|
abort ();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
syscall_printf ("Child died before subproc_ready signalled");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug_printf ("child signalled me");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-02-21 13:20:38 +08:00
|
|
|
resume_child (PROCESS_INFORMATION &pi, HANDLE forker_finished)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
SetEvent (forker_finished);
|
2000-10-13 06:15:47 +08:00
|
|
|
debug_printf ("signalled child");
|
|
|
|
return 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Notify parent that it is time for the next step.
|
|
|
|
Note that this has to be a macro since the parent may be messing with
|
|
|
|
our stack. */
|
2000-10-13 06:15:47 +08:00
|
|
|
static void __stdcall
|
|
|
|
sync_with_parent(const char *s, bool hang_self)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-13 06:15:47 +08:00
|
|
|
debug_printf ("signalling parent: %s", s);
|
|
|
|
/* Tell our parent we're waiting. */
|
|
|
|
if (!SetEvent (child_proc_info->subproc_ready))
|
2001-09-23 00:55:02 +08:00
|
|
|
api_fatal ("fork child - SetEvent for %s failed, %E", s);
|
2000-10-13 06:15:47 +08:00
|
|
|
if (hang_self)
|
|
|
|
{
|
|
|
|
HANDLE h = child_proc_info->forker_finished;
|
|
|
|
/* Wait for the parent to fill in our stack and heap.
|
|
|
|
Don't wait forever here. If our parent dies we don't want to clog
|
|
|
|
the system. If the wait fails, we really can't continue so exit. */
|
|
|
|
DWORD psync_rc = WaitForSingleObject (h, FORK_WAIT_TIMEOUT);
|
|
|
|
debug_printf ("awake");
|
|
|
|
switch (psync_rc)
|
|
|
|
{
|
|
|
|
case WAIT_TIMEOUT:
|
2001-09-23 00:55:02 +08:00
|
|
|
api_fatal ("WFSO timed out for %s", s);
|
2000-10-13 06:15:47 +08:00
|
|
|
break;
|
|
|
|
case WAIT_FAILED:
|
|
|
|
if (GetLastError () == ERROR_INVALID_HANDLE &&
|
|
|
|
WaitForSingleObject (child_proc_info->forker_finished, 1) != WAIT_FAILED)
|
|
|
|
break;
|
2001-09-23 00:55:02 +08:00
|
|
|
api_fatal ("WFSO failed for %s, fork_finished %p, %E", s,
|
2001-11-05 14:09:15 +08:00
|
|
|
child_proc_info->forker_finished);
|
2000-10-13 06:15:47 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug_printf ("no problems");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
static int __stdcall
|
|
|
|
fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-13 06:15:47 +08:00
|
|
|
debug_printf ("child is running. pid %d, ppid %d, stack here %p",
|
|
|
|
myself->pid, myself->ppid, __builtin_frame_address (0));
|
|
|
|
|
|
|
|
/* Restore the inheritance state as in parent
|
|
|
|
Don't call setuid here! The flags are already set. */
|
2000-11-16 05:04:02 +08:00
|
|
|
if (cygheap->user.impersonated)
|
2000-10-13 06:15:47 +08:00
|
|
|
{
|
2000-11-16 05:04:02 +08:00
|
|
|
debug_printf ("Impersonation of child, token: %d", cygheap->user.token);
|
|
|
|
if (cygheap->user.token == INVALID_HANDLE_VALUE)
|
2000-10-13 06:15:47 +08:00
|
|
|
RevertToSelf (); // probably not needed
|
2000-11-16 05:04:02 +08:00
|
|
|
else if (!ImpersonateLoggedOnUser (cygheap->user.token))
|
2000-10-13 06:15:47 +08:00
|
|
|
system_printf ("Impersonate for forked child failed: %E");
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
sync_with_parent ("after longjmp.", TRUE);
|
|
|
|
ProtectHandle (hParent);
|
2001-07-21 11:20:01 +08:00
|
|
|
sigproc_printf ("hParent %p, child 1 first_dll %p, load_dlls %d\n", hParent,
|
2001-09-08 05:32:07 +08:00
|
|
|
first_dll, load_dlls);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
char c;
|
|
|
|
if (GetEnvironmentVariable ("FORKDEBUG", &c, 1))
|
|
|
|
try_to_debug ();
|
|
|
|
char buf[80];
|
|
|
|
/* This is useful for debugging fork problems. Use gdb to attach to
|
|
|
|
the pid reported here. */
|
|
|
|
if (GetEnvironmentVariable ("CYGWIN_FORK_SLEEP", buf, sizeof (buf)))
|
|
|
|
{
|
|
|
|
small_printf ("Sleeping %d after fork, pid %u\n", atoi (buf), GetCurrentProcessId ());
|
|
|
|
Sleep (atoi(buf));
|
|
|
|
}
|
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* If we've played with the stack, stacksize != 0. That means that
|
|
|
|
fork() was invoked from other than the main thread. Make sure that
|
|
|
|
when the "main" thread exits it calls do_exit, like a normal process.
|
|
|
|
Exit with a status code of 0. */
|
|
|
|
if (child_proc_info->stacksize)
|
|
|
|
{
|
|
|
|
((DWORD *)child_proc_info->stackbottom)[-17] = (DWORD)do_exit;
|
|
|
|
((DWORD *)child_proc_info->stackbottom)[-15] = (DWORD)0;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-06-12 19:31:05 +08:00
|
|
|
set_file_api_mode (current_codepage);
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
MALLOC_CHECK;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-01 13:17:34 +08:00
|
|
|
debug_fixup_after_fork ();
|
2000-10-15 09:37:07 +08:00
|
|
|
pinfo_fixup_after_fork ();
|
2001-04-19 05:10:15 +08:00
|
|
|
cygheap->fdtab.fixup_after_fork (hParent);
|
2000-10-13 06:15:47 +08:00
|
|
|
signal_fixup_after_fork ();
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
|
2002-04-10 00:33:13 +08:00
|
|
|
if (fixup_mmaps_after_fork (hParent))
|
|
|
|
api_fatal ("recreate_mmaps_after_fork_failed");
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* If we haven't dynamically loaded any dlls, just signal
|
|
|
|
the parent. Otherwise, load all the dlls, tell the parent
|
|
|
|
that we're done, and wait for the parent to fill in the.
|
|
|
|
loaded dlls' data/bss. */
|
|
|
|
if (!load_dlls)
|
|
|
|
sync_with_parent ("performed fork fixup.", FALSE);
|
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-13 06:15:47 +08:00
|
|
|
dlls.load_after_fork (hParent, first_dll);
|
|
|
|
sync_with_parent ("loaded dlls", TRUE);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
ForceCloseHandle (hParent);
|
|
|
|
(void) ForceCloseHandle (child_proc_info->subproc_ready);
|
|
|
|
(void) ForceCloseHandle (child_proc_info->forker_finished);
|
2000-07-15 10:48:11 +08:00
|
|
|
|
2002-02-28 22:30:38 +08:00
|
|
|
if (fixup_shms_after_fork ())
|
|
|
|
api_fatal ("recreate_shm areas after fork failed");
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Set thread local stuff to zero. Under Windows 95/98 this is sometimes
|
|
|
|
non-zero, for some reason.
|
|
|
|
FIXME: There is a memory leak here after a fork. */
|
|
|
|
for (per_thread **t = threadstuff; *t; t++)
|
|
|
|
if ((*t)->clear_on_fork ())
|
|
|
|
(*t)->set ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-11 16:15:39 +08:00
|
|
|
user_data->threadinterface->fixup_after_fork ();
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Initialize signal/process handling */
|
|
|
|
sigproc_init ();
|
2001-05-20 09:19:20 +08:00
|
|
|
__pthread_atforkchild ();
|
2000-10-17 07:55:58 +08:00
|
|
|
cygbench ("fork-child");
|
2000-10-13 06:15:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
static void
|
|
|
|
slow_pid_reuse (HANDLE h)
|
|
|
|
{
|
2000-11-16 13:21:03 +08:00
|
|
|
static NO_COPY HANDLE last_fork_procs[8] = {0};
|
2000-11-15 14:27:48 +08:00
|
|
|
static NO_COPY unsigned nfork_procs = 0;
|
|
|
|
|
2000-11-15 14:46:19 +08:00
|
|
|
if (nfork_procs >= (sizeof (last_fork_procs) / sizeof (last_fork_procs [0])))
|
2000-11-15 14:27:48 +08:00
|
|
|
nfork_procs = 0;
|
|
|
|
/* Keep a list of handles to forked processes sitting around to prevent
|
|
|
|
Windows from reusing the same pid n times in a row. Having the same pids
|
|
|
|
close in succesion confuses bash. Keeping a handle open will stop
|
|
|
|
windows from reusing the same pid. */
|
|
|
|
if (last_fork_procs[nfork_procs])
|
2000-11-15 14:46:19 +08:00
|
|
|
ForceCloseHandle1 (last_fork_procs[nfork_procs], fork_stupidity);
|
|
|
|
if (DuplicateHandle (hMainProc, h, hMainProc, &last_fork_procs[nfork_procs],
|
2000-11-15 14:27:48 +08:00
|
|
|
0, FALSE, DUPLICATE_SAME_ACCESS))
|
2000-11-15 14:46:19 +08:00
|
|
|
ProtectHandle1 (last_fork_procs[nfork_procs], fork_stupidity);
|
|
|
|
else
|
2000-11-15 14:27:48 +08:00
|
|
|
{
|
|
|
|
last_fork_procs[nfork_procs] = NULL;
|
|
|
|
system_printf ("couldn't create last_fork_proc, %E");
|
|
|
|
}
|
|
|
|
nfork_procs++;
|
|
|
|
}
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
static int __stdcall
|
2001-06-19 05:18:59 +08:00
|
|
|
fork_parent (HANDLE& hParent, dll *&first_dll,
|
|
|
|
bool& load_dlls, void *stack_here, child_info_fork &ch)
|
2000-10-13 06:15:47 +08:00
|
|
|
{
|
|
|
|
HANDLE subproc_ready, forker_finished;
|
|
|
|
DWORD rc;
|
|
|
|
PROCESS_INFORMATION pi = {0, NULL, 0, 0};
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-05-20 09:19:20 +08:00
|
|
|
/* call the pthread_atfork prepare functions */
|
|
|
|
__pthread_atforkprepare ();
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
subproc_init ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
#ifdef DEBUGGING_NOTNEEDED
|
2000-10-13 06:15:47 +08:00
|
|
|
/* The ProtectHandle call allocates memory so we need to make sure
|
|
|
|
that enough is set aside here so that the sbrk pointer does not
|
|
|
|
move when ProtectHandle is called after the child is started.
|
|
|
|
Otherwise the sbrk pointers in the parent will not agree with
|
|
|
|
the child and when user_data is (regrettably) copied over,
|
|
|
|
the user_data->ptr field will not be accurate. */
|
|
|
|
free (malloc (4096));
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
int c_flags = GetPriorityClass (hMainProc) /*|
|
|
|
|
CREATE_NEW_PROCESS_GROUP*/;
|
|
|
|
STARTUPINFO si = {0, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL};
|
|
|
|
|
|
|
|
/* If we don't have a console, then don't create a console for the
|
|
|
|
child either. */
|
|
|
|
HANDLE console_handle = CreateFileA ("CONOUT$", GENERIC_WRITE,
|
|
|
|
FILE_SHARE_WRITE, &sec_none_nih,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (console_handle != INVALID_HANDLE_VALUE && console_handle != 0)
|
|
|
|
CloseHandle (console_handle);
|
|
|
|
else
|
|
|
|
c_flags |= DETACHED_PROCESS;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-26 18:13:41 +08:00
|
|
|
/* Some file types (currently only sockets) 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. */
|
2001-04-19 05:10:15 +08:00
|
|
|
if (cygheap->fdtab.need_fixup_before ())
|
2000-10-26 18:13:41 +08:00
|
|
|
c_flags |= CREATE_SUSPENDED;
|
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
/* Create an inheritable handle to pass to the child process. This will
|
|
|
|
allow the child to duplicate handles from the parent to itself. */
|
2000-10-13 06:15:47 +08:00
|
|
|
hParent = NULL;
|
|
|
|
if (!DuplicateHandle (hMainProc, hMainProc, hMainProc, &hParent, 0, 1,
|
|
|
|
DUPLICATE_SAME_ACCESS))
|
|
|
|
{
|
|
|
|
system_printf ("couldn't create handle to myself for child, %E");
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Remember the address of the first loaded dll and decide
|
|
|
|
if we need to load dlls. We do this here so that this
|
|
|
|
information will be available in the parent and, when
|
|
|
|
the stack is copied, in the child. */
|
|
|
|
first_dll = dlls.start.next;
|
|
|
|
load_dlls = dlls.reload_on_fork && dlls.loaded_dlls;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* This will help some of the confusion. */
|
|
|
|
fflush (stdout);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
subproc_ready = CreateEvent (&sec_all, FALSE, FALSE, NULL);
|
|
|
|
if (subproc_ready == NULL)
|
|
|
|
{
|
|
|
|
CloseHandle (hParent);
|
|
|
|
system_printf ("unable to allocate subproc_ready event, %E");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
forker_finished = CreateEvent (&sec_all, FALSE, FALSE, NULL);
|
|
|
|
if (forker_finished == NULL)
|
|
|
|
{
|
|
|
|
CloseHandle (hParent);
|
|
|
|
CloseHandle (subproc_ready);
|
2001-10-14 23:49:13 +08:00
|
|
|
system_printf ("unable to allocate forker_finished event, %E");
|
2000-10-13 06:15:47 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
ProtectHandle (subproc_ready);
|
|
|
|
ProtectHandle (forker_finished);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-10-10 10:32:12 +08:00
|
|
|
init_child_info (PROC_FORK, &ch, 1, subproc_ready);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
ch.forker_finished = forker_finished;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
stack_base (ch);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
si.cb = sizeof (STARTUPINFO);
|
|
|
|
si.lpReserved2 = (LPBYTE)&ch;
|
|
|
|
si.cbReserved2 = sizeof(ch);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Remove impersonation */
|
2000-11-16 05:04:02 +08:00
|
|
|
if (cygheap->user.impersonated && cygheap->user.token != INVALID_HANDLE_VALUE)
|
2001-05-01 05:19:42 +08:00
|
|
|
RevertToSelf ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
ch.parent = hParent;
|
2000-11-15 14:27:48 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
if (npid_max)
|
|
|
|
{
|
|
|
|
for (int pass = 0; pass < 2; pass++)
|
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
while ((pid = fork_pids[npid++]))
|
|
|
|
if (!pinfo (pid))
|
|
|
|
{
|
|
|
|
ch.cygpid = pid;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
npid = 0;
|
|
|
|
}
|
|
|
|
}
|
2001-08-05 05:10:52 +08:00
|
|
|
out:
|
2000-11-15 14:27:48 +08:00
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
char sa_buf[1024];
|
2002-05-06 18:05:46 +08:00
|
|
|
PSECURITY_ATTRIBUTES sec_attribs = sec_user_nih (sa_buf);
|
2000-10-14 13:52:38 +08:00
|
|
|
syscall_printf ("CreateProcess (%s, %s, 0, 0, 1, %x, 0, 0, %p, %p)",
|
|
|
|
myself->progname, myself->progname, c_flags, &si, &pi);
|
2001-09-09 11:34:36 +08:00
|
|
|
__malloc_lock (_reent_clib ());
|
2001-09-14 08:49:00 +08:00
|
|
|
void *newheap;
|
|
|
|
newheap = cygheap_setup_for_child (&ch,cygheap->fdtab.need_fixup_before ());
|
2000-10-14 13:52:38 +08:00
|
|
|
rc = CreateProcess (myself->progname, /* image to run */
|
|
|
|
myself->progname, /* what we send in arg0 */
|
2002-05-06 18:05:46 +08:00
|
|
|
sec_attribs,
|
|
|
|
sec_attribs,
|
2000-10-14 13:52:38 +08:00
|
|
|
TRUE, /* inherit handles from parent */
|
|
|
|
c_flags,
|
|
|
|
NULL, /* environment filled in later */
|
2000-11-15 14:27:48 +08:00
|
|
|
0, /* use current drive/directory */
|
2000-10-14 13:52:38 +08:00
|
|
|
&si,
|
|
|
|
&pi);
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
CloseHandle (hParent);
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
syscall_printf ("CreateProcessA failed, %E");
|
|
|
|
ForceCloseHandle(subproc_ready);
|
|
|
|
ForceCloseHandle(forker_finished);
|
2000-06-17 03:36:07 +08:00
|
|
|
/* Restore impersonation */
|
2000-11-16 05:04:02 +08:00
|
|
|
if (cygheap->user.impersonated
|
2001-09-08 05:32:07 +08:00
|
|
|
&& cygheap->user.token != INVALID_HANDLE_VALUE)
|
2001-05-01 05:19:42 +08:00
|
|
|
ImpersonateLoggedOnUser (cygheap->user.token);
|
2001-09-14 08:49:00 +08:00
|
|
|
cygheap_setup_for_child_cleanup (newheap, &ch, 0);
|
2000-10-13 06:15:47 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2000-06-17 03:36:07 +08:00
|
|
|
|
2000-10-26 18:13:41 +08:00
|
|
|
/* Fixup the parent datastructure if needed and resume the child's
|
|
|
|
main thread. */
|
2001-09-14 08:49:00 +08:00
|
|
|
if (!cygheap->fdtab.need_fixup_before ())
|
|
|
|
cygheap_setup_for_child_cleanup (newheap, &ch, 0);
|
|
|
|
else
|
2000-10-26 18:13:41 +08:00
|
|
|
{
|
2001-04-19 05:10:15 +08:00
|
|
|
cygheap->fdtab.fixup_before_fork (pi.dwProcessId);
|
2001-09-14 08:49:00 +08:00
|
|
|
cygheap_setup_for_child_cleanup (newheap, &ch, 1);
|
2000-10-26 18:13:41 +08:00
|
|
|
ResumeThread (pi.hThread);
|
|
|
|
}
|
|
|
|
|
2000-11-15 14:27:48 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
pinfo forked ((ch.cygpid != 1 ? ch.cygpid : cygwin_pid (pi.dwProcessId)), 1);
|
|
|
|
#else
|
2000-10-13 06:15:47 +08:00
|
|
|
pinfo forked (cygwin_pid (pi.dwProcessId), 1);
|
2000-11-15 14:27:48 +08:00
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Initialize things that are done later in dll_crt0_1 that aren't done
|
|
|
|
for the forkee. */
|
|
|
|
strcpy(forked->progname, myself->progname);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Restore impersonation */
|
2000-11-16 05:04:02 +08:00
|
|
|
if (cygheap->user.impersonated && cygheap->user.token != INVALID_HANDLE_VALUE)
|
2001-05-01 05:19:42 +08:00
|
|
|
ImpersonateLoggedOnUser (cygheap->user.token);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
ProtectHandle (pi.hThread);
|
|
|
|
/* Protect the handle but name it similarly to the way it will
|
|
|
|
be called in subproc handling. */
|
|
|
|
ProtectHandle1 (pi.hProcess, childhProc);
|
2000-10-21 12:53:49 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Fill in fields in the child's process table entry. */
|
|
|
|
forked->hProcess = pi.hProcess;
|
|
|
|
forked->dwProcessId = pi.dwProcessId;
|
|
|
|
forked->copysigs(myself);
|
2001-02-10 12:20:52 +08:00
|
|
|
|
|
|
|
/* Hopefully, this will succeed. The alternative to doing things this
|
|
|
|
way is to reserve space prior to calling CreateProcess and then fill
|
|
|
|
it in afterwards. This requires more bookkeeping than I like, though,
|
|
|
|
so we'll just do it the easy way. So, terminate any child process if
|
|
|
|
we can't actually record the pid in the internal table. */
|
|
|
|
if (!forked.remember ())
|
|
|
|
{
|
|
|
|
TerminateProcess (pi.hProcess, 1);
|
|
|
|
set_errno (EAGAIN);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
slow_pid_reuse (pi.hProcess);
|
2000-10-13 06:15:47 +08:00
|
|
|
|
|
|
|
/* Wait for subproc to initialize itself. */
|
2001-11-25 11:28:16 +08:00
|
|
|
if (!sync_with_child (pi, subproc_ready, TRUE, "waiting for longjmp"))
|
2000-10-13 06:15:47 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* CHILD IS STOPPED */
|
|
|
|
debug_printf ("child is alive (but stopped)");
|
|
|
|
|
|
|
|
/* Initialize, in order: data, bss, heap, stack, dll data, dll bss
|
|
|
|
Note: variables marked as NO_COPY will not be copied
|
|
|
|
since they are placed in a protected segment. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
MALLOC_CHECK;
|
|
|
|
rc = fork_copy (pi, "user/cygwin data",
|
|
|
|
user_data->data_start, user_data->data_end,
|
|
|
|
user_data->bss_start, user_data->bss_end,
|
2001-09-08 05:32:07 +08:00
|
|
|
cygheap->heapbase, cygheap->heapptr,
|
2000-10-13 06:15:47 +08:00
|
|
|
stack_here, ch.stackbottom,
|
|
|
|
dll_data_start, dll_data_end,
|
|
|
|
dll_bss_start, dll_bss_end, NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2001-09-09 11:34:36 +08:00
|
|
|
__malloc_unlock (_reent_clib ());
|
2000-10-13 06:15:47 +08:00
|
|
|
MALLOC_CHECK;
|
|
|
|
if (!rc)
|
|
|
|
goto cleanup;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Now fill data/bss of any DLLs that were linked into the program. */
|
|
|
|
for (dll *d = dlls.istart (DLL_LINK); d; d = dlls.inext ())
|
|
|
|
{
|
|
|
|
debug_printf ("copying data/bss of a linked dll");
|
|
|
|
if (!fork_copy (pi, "linked dll data/bss", d->p.data_start, d->p.data_end,
|
|
|
|
d->p.bss_start, d->p.bss_end,
|
|
|
|
NULL))
|
2000-02-18 03:38:33 +08:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Start thread, and wait for it to reload dlls. */
|
|
|
|
if (!resume_child (pi, forker_finished) ||
|
|
|
|
!sync_with_child (pi, subproc_ready, load_dlls, "child loading dlls"))
|
|
|
|
goto cleanup;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
/* If DLLs were loaded in the parent, then the child has reloaded all
|
|
|
|
of them and is now waiting to have all of the individual data and
|
|
|
|
bss sections filled in. */
|
|
|
|
if (load_dlls)
|
|
|
|
{
|
|
|
|
/* CHILD IS STOPPED */
|
|
|
|
/* write memory of reloaded dlls */
|
|
|
|
for (dll *d = dlls.istart (DLL_LOAD); d; d = dlls.inext ())
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-13 06:15:47 +08:00
|
|
|
debug_printf ("copying data/bss for a loaded dll");
|
|
|
|
if (!fork_copy (pi, "loaded dll data/bss", d->p.data_start, d->p.data_end,
|
|
|
|
d->p.bss_start, d->p.bss_end,
|
|
|
|
NULL))
|
|
|
|
goto cleanup;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-10-13 06:15:47 +08:00
|
|
|
/* Start the child up again. */
|
|
|
|
(void) resume_child (pi, forker_finished);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
ForceCloseHandle (subproc_ready);
|
|
|
|
ForceCloseHandle (pi.hThread);
|
|
|
|
ForceCloseHandle (forker_finished);
|
|
|
|
forker_finished = NULL;
|
|
|
|
pi.hThread = NULL;
|
2001-05-20 09:19:20 +08:00
|
|
|
__pthread_atforkparent ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
return forked->pid;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Common cleanup code for failure cases */
|
2001-08-05 05:10:52 +08:00
|
|
|
cleanup:
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Remember to de-allocate the fd table. */
|
|
|
|
if (pi.hProcess)
|
|
|
|
ForceCloseHandle1 (pi.hProcess, childhProc);
|
|
|
|
if (pi.hThread)
|
|
|
|
ForceCloseHandle (pi.hThread);
|
|
|
|
if (subproc_ready)
|
|
|
|
ForceCloseHandle (subproc_ready);
|
|
|
|
if (forker_finished)
|
|
|
|
ForceCloseHandle (forker_finished);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
extern "C" int
|
|
|
|
fork ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-13 06:15:47 +08:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
HANDLE hParent;
|
|
|
|
dll *first_dll;
|
|
|
|
bool load_dlls;
|
|
|
|
} grouped;
|
|
|
|
|
|
|
|
MALLOC_CHECK;
|
2000-10-23 11:35:50 +08:00
|
|
|
sigframe thisframe (mainthread);
|
2000-10-13 06:15:47 +08:00
|
|
|
|
|
|
|
debug_printf ("entering");
|
2000-10-14 13:52:38 +08:00
|
|
|
grouped.hParent = grouped.first_dll = NULL;
|
|
|
|
grouped.load_dlls = 0;
|
2000-10-13 06:15:47 +08:00
|
|
|
|
|
|
|
if (ISSTATE(myself, PID_SPLIT_HEAP))
|
|
|
|
{
|
|
|
|
system_printf ("The heap has been split, CYGWIN can't fork this process.");
|
|
|
|
system_printf ("Increase the heap_chunk_size in the registry and try again.");
|
|
|
|
set_errno (ENOMEM);
|
|
|
|
syscall_printf ("-1 = fork (), split heap");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-10-14 13:52:38 +08:00
|
|
|
void *esp;
|
2001-06-19 05:18:59 +08:00
|
|
|
__asm__ volatile ("movl %%esp,%0": "=r" (esp));
|
2000-10-14 13:52:38 +08:00
|
|
|
|
2000-10-25 11:54:50 +08:00
|
|
|
myself->set_has_pgid_children ();
|
|
|
|
|
2000-10-13 06:15:47 +08:00
|
|
|
child_info_fork ch;
|
|
|
|
|
2000-10-14 13:52:38 +08:00
|
|
|
int res = setjmp (ch.jmp);
|
|
|
|
|
|
|
|
if (res)
|
2000-10-13 06:15:47 +08:00
|
|
|
res = fork_child (grouped.hParent, grouped.first_dll, grouped.load_dlls);
|
|
|
|
else
|
2001-06-19 05:18:59 +08:00
|
|
|
res = fork_parent (grouped.hParent, grouped.first_dll, grouped.load_dlls, esp, ch);
|
2000-10-13 06:15:47 +08:00
|
|
|
|
|
|
|
MALLOC_CHECK;
|
|
|
|
syscall_printf ("%d = fork()", res);
|
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-11-15 14:27:48 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
void
|
|
|
|
fork_init ()
|
|
|
|
{
|
|
|
|
char buf[1024];
|
|
|
|
if (!GetEnvironmentVariable ("CYGWIN_FORK_PIDS", buf, 1024))
|
|
|
|
return;
|
|
|
|
pid_t pid;
|
|
|
|
char *p, *pe;
|
|
|
|
for (p = buf; (pid = strtol (p, &pe, 10)); p = pe)
|
|
|
|
fork_pids[npid_max++] = pid;
|
|
|
|
}
|
|
|
|
#endif /*DEBUGGING*/
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#ifdef NEWVFORK
|
|
|
|
/* Dummy function to force second assignment below to actually be
|
|
|
|
carried out */
|
|
|
|
static vfork_save *
|
|
|
|
get_vfork_val ()
|
|
|
|
{
|
|
|
|
return vfork_storage.val ();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern "C"
|
|
|
|
int
|
|
|
|
vfork ()
|
|
|
|
{
|
|
|
|
#ifndef NEWVFORK
|
|
|
|
return fork ();
|
|
|
|
#else
|
2001-09-15 08:47:44 +08:00
|
|
|
sigframe thisframe;
|
2000-02-18 03:38:33 +08:00
|
|
|
vfork_save *vf = get_vfork_val ();
|
2000-08-03 11:02:41 +08:00
|
|
|
char **esp, **pp;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (vf == NULL)
|
|
|
|
vf = vfork_storage.create ();
|
2001-09-14 12:37:57 +08:00
|
|
|
else if (vf->pid)
|
|
|
|
return fork ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (!setjmp (vf->j))
|
|
|
|
{
|
|
|
|
vf->pid = -1;
|
2000-08-03 11:02:41 +08:00
|
|
|
__asm__ volatile ("movl %%esp,%0": "=r" (vf->vfork_esp):);
|
2000-02-18 03:38:33 +08:00
|
|
|
__asm__ volatile ("movl %%ebp,%0": "=r" (vf->vfork_ebp):);
|
2000-08-03 11:02:41 +08:00
|
|
|
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
|
2001-09-15 08:47:44 +08:00
|
|
|
esp <= vf->vfork_ebp + 2; pp++, esp++)
|
2000-08-03 11:02:41 +08:00
|
|
|
*pp = *esp;
|
2001-06-25 05:57:50 +08:00
|
|
|
int res = cygheap->fdtab.vfork_child_dup () ? 0 : -1;
|
|
|
|
debug_printf ("%d = vfork()", res);
|
2001-10-04 10:34:20 +08:00
|
|
|
debug_printf ("exiting vfork, res %d", res);
|
2001-06-25 05:57:50 +08:00
|
|
|
return res;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
vf = get_vfork_val ();
|
2001-09-14 08:49:00 +08:00
|
|
|
|
|
|
|
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
|
2001-09-15 08:47:44 +08:00
|
|
|
esp <= vf->vfork_ebp + 2; pp++, esp++)
|
2001-09-14 08:49:00 +08:00
|
|
|
*esp = *pp;
|
|
|
|
|
2001-09-15 08:47:44 +08:00
|
|
|
thisframe.init (mainthread);
|
|
|
|
cygheap->fdtab.vfork_parent_restore ();
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
if (vf->pid < 0)
|
|
|
|
{
|
|
|
|
int exitval = -vf->pid;
|
2001-09-14 12:39:56 +08:00
|
|
|
vf->pid = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
if ((vf->pid = fork ()) == 0)
|
|
|
|
exit (exitval);
|
|
|
|
}
|
|
|
|
|
2001-09-14 12:37:57 +08:00
|
|
|
int pid = vf->pid;
|
|
|
|
vf->pid = 0;
|
2001-10-04 10:34:20 +08:00
|
|
|
debug_printf ("exiting vfork, pid %d", pid);
|
2001-09-15 08:47:44 +08:00
|
|
|
sig_dispatch_pending ();
|
2001-09-14 12:37:57 +08:00
|
|
|
return pid;
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
}
|