- GNUNET_break (0 == close (fd_stdout_read));
- if (-1 == dup2 (fd_stdout_write, 1))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- GNUNET_break (0 == close (fd_stdout_write));
- }
-
- if (pipe_stdin != NULL)
- {
-
- GNUNET_break (0 == close (fd_stdin_write));
- if (-1 == dup2 (fd_stdin_read, 0))
- LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2");
- GNUNET_break (0 == close (fd_stdin_read));
- }
- execvp (filename, argv);
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
- _exit (1);
-#else
- char *arg;
- unsigned int cmdlen;
- char *cmd, *idx;
- STARTUPINFOW start;
- PROCESS_INFORMATION proc;
- int argc;
- HANDLE stdin_handle;
- HANDLE stdout_handle;
-
- char path[MAX_PATH + 1];
-
- char *our_env[3] = { NULL, NULL, NULL };
- char *env_block = NULL;
- char *pathbuf;
- DWORD pathbuf_len, alloc_len;
- char *self_prefix;
- char *bindir;
- char *libdir;
- char *ptr;
- char *non_const_filename;
- wchar_t wpath[MAX_PATH + 1], wcmd[32768];
-
- /* Search in prefix dir (hopefully - the directory from which
- * the current module was loaded), bindir and libdir, then in PATH
- */
- self_prefix = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_SELF_PREFIX);
- bindir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR);
- libdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBDIR);
-
- pathbuf_len = GetEnvironmentVariableA ("PATH", (char *) &pathbuf, 0);
-
- alloc_len =
- pathbuf_len + 1 + strlen (self_prefix) + 1 + strlen (bindir) + 1 +
- strlen (libdir);
-
- pathbuf = GNUNET_malloc (alloc_len * sizeof (char));
-
- ptr = pathbuf;
- ptr += sprintf (pathbuf, "%s;%s;%s;", self_prefix, bindir, libdir);
- GNUNET_free (self_prefix);
- GNUNET_free (bindir);
- GNUNET_free (libdir);
-
- alloc_len = GetEnvironmentVariableA ("PATH", ptr, pathbuf_len);
- GNUNET_assert (alloc_len == (pathbuf_len - 1));
-
- cmdlen = strlen (filename);
- if (cmdlen < 5 || strcmp (&filename[cmdlen - 4], ".exe") != 0)
- GNUNET_asprintf (&non_const_filename, "%s.exe", filename);
- else
- GNUNET_asprintf (&non_const_filename, "%s", filename);
-
- /* Check that this is the full path. If it isn't, search. */
- if (non_const_filename[1] == ':')
- snprintf (path, sizeof (path) / sizeof (char), "%s", non_const_filename);
- else if (!SearchPathA
- (pathbuf, non_const_filename, NULL, sizeof (path) / sizeof (char),
- path, NULL))
- {
- SetErrnoFromWinError (GetLastError ());
- LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "SearchPath",
- non_const_filename);
- GNUNET_free (non_const_filename);
- GNUNET_free (pathbuf);
- return NULL;
- }
- GNUNET_free (pathbuf);
- GNUNET_free (non_const_filename);
-
- cmdlen = 0;
- argc = 0;
- while (NULL != (arg = argv[argc++]))
- {
- if (cmdlen == 0)
- cmdlen = cmdlen + strlen (path) + 3;
- else
- cmdlen = cmdlen + strlen (arg) + 3;
- }
-
- cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1));
- argc = 0;
- while (NULL != (arg = argv[argc++]))
- {
- if (idx == cmd)
- idx += sprintf (idx, "\"%s\" ", path);
- else
- idx += sprintf (idx, "\"%s\" ", arg);
- }
-
- memset (&start, 0, sizeof (start));
- start.cb = sizeof (start);
-
- if ((pipe_stdin != NULL) || (pipe_stdout != NULL))
- start.dwFlags |= STARTF_USESTDHANDLES;
-
- if (pipe_stdin != NULL)
- {
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdin, GNUNET_DISK_PIPE_END_READ),
- &stdin_handle, sizeof (HANDLE));
- start.hStdInput = stdin_handle;
- }
-
- if (pipe_stdout != NULL)
- {
- GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle
- (pipe_stdout,
- GNUNET_DISK_PIPE_END_WRITE),
- &stdout_handle, sizeof (HANDLE));
- start.hStdOutput = stdout_handle;
- }
-
- control_pipe =
- GNUNET_DISK_npipe_create (&childpipename, GNUNET_DISK_OPEN_WRITE,
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE);
- if (control_pipe == NULL)
- {
- GNUNET_free (cmd);
- GNUNET_free (path);
- return NULL;