HANDLE section, event;
struct fake_fork_info *info;
char *name;
- DWORD le;
name = make_section_name (GetCurrentProcessId ());
section = OpenFileMapping (FILE_MAP_WRITE, FALSE, name);
- le = GetLastError ();
xfree (name);
+ /* It seems that Windows 9x and NT set last-error inconsistently when
+ OpenFileMapping() fails; so we assume it failed because the section
+ object does not exist. */
if (!section)
- {
- if (le == ERROR_FILE_NOT_FOUND)
- return 0; /* Section object does not exist; we are the parent. */
- else
- return -1;
- }
+ return 0; /* We are the parent. */
info = MapViewOfFile (section, FILE_MAP_WRITE, 0, 0, 0);
if (!info)
static void
fake_fork (void)
{
- char *cmdline, *args;
char exe[MAX_PATH + 1];
DWORD exe_len, le;
SECURITY_ATTRIBUTES sa;
event = section = pi.hProcess = pi.hThread = NULL;
- /* Get command line arguments to pass to the child process.
- We need to skip the name of the command (what amounts to argv[0]). */
- cmdline = GetCommandLine ();
- if (*cmdline == '"')
- {
- args = strchr (cmdline + 1, '"');
- if (args)
- ++args;
- }
- else
- args = strchr (cmdline, ' ');
-
- /* It's ok if args is NULL, that would mean there were no arguments
- after the command name. As it is now though, we would never get here
- if that were true. */
-
/* Get the fully qualified name of our executable. This is more reliable
than using argv[0]. */
exe_len = GetModuleFileName (GetModuleHandle (NULL), exe, sizeof (exe));
if (!event)
return;
- /* Creat the child process detached form the current console and in a
+ /* Create the child process detached form the current console and in a
suspended state. */
memset (&si, 0, sizeof (si));
si.cb = sizeof (si);
- rv = CreateProcess (exe, args, NULL, NULL, TRUE, CREATE_SUSPENDED |
- DETACHED_PROCESS, NULL, NULL, &si, &pi);
+ rv = CreateProcess (exe, GetCommandLine (), NULL, NULL, TRUE,
+ CREATE_SUSPENDED | DETACHED_PROCESS,
+ NULL, NULL, &si, &pi);
if (!rv)
goto cleanup;