aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-09-15 08:46:57 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-09-15 08:46:57 +0000
commitc8140c2d2929e0dee00b642340dd8b0dd80c29c3 (patch)
treea85cee0fa7c3a297e99ccab8e487e5642bc1e255 /src
parent8b9dfe56e2e6acc113ee6865cb583402f588e57e (diff)
downloadgnunet-c8140c2d2929e0dee00b642340dd8b0dd80c29c3.tar.gz
gnunet-c8140c2d2929e0dee00b642340dd8b0dd80c29c3.zip
0001602: A patch to fix process spawning with redirected std streams
Diffstat (limited to 'src')
-rw-r--r--src/util/os_priority.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 92286a37b..34900a1cc 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -255,13 +255,13 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
255 char *arg; 255 char *arg;
256 unsigned int cmdlen; 256 unsigned int cmdlen;
257 char *cmd, *idx; 257 char *cmd, *idx;
258 int findresult;
258 STARTUPINFO start; 259 STARTUPINFO start;
259 PROCESS_INFORMATION proc; 260 PROCESS_INFORMATION proc;
260#if NILS 261
261 HANDLE stdin_handle; 262 HANDLE stdin_handle;
262 HANDLE stdout_handle; 263 HANDLE stdout_handle;
263#endif 264
264 char *fn = NULL;
265 char path[MAX_PATH + 1]; 265 char path[MAX_PATH + 1];
266 266
267 cmdlen = 0; 267 cmdlen = 0;
@@ -270,7 +270,7 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
270 cmdlen = cmdlen + strlen (arg) + 3; 270 cmdlen = cmdlen + strlen (arg) + 3;
271 va_end (ap); 271 va_end (ap);
272 272
273 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen); 273 cmd = idx = GNUNET_malloc (sizeof (char) * (cmdlen + 1));
274 va_start (ap, filename); 274 va_start (ap, filename);
275 while (NULL != (arg = va_arg (ap, char *))) 275 while (NULL != (arg = va_arg (ap, char *)))
276 idx += sprintf (idx, "\"%s\" ", arg); 276 idx += sprintf (idx, "\"%s\" ", arg);
@@ -279,7 +279,6 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
279 memset (&start, 0, sizeof (start)); 279 memset (&start, 0, sizeof (start));
280 start.cb = sizeof (start); 280 start.cb = sizeof (start);
281 281
282#if NILS
283 if ((pipe_stdin != NULL) || (pipe_stdout != NULL)) 282 if ((pipe_stdin != NULL) || (pipe_stdout != NULL))
284 start.dwFlags |= STARTF_USESTDHANDLES; 283 start.dwFlags |= STARTF_USESTDHANDLES;
285 284
@@ -294,27 +293,26 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin,
294 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &stdout_handle, sizeof (HANDLE)); 293 GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &stdout_handle, sizeof (HANDLE));
295 start.hStdOutput = stdout_handle; 294 start.hStdOutput = stdout_handle;
296 } 295 }
297#endif 296
298 if ((int) FindExecutable(filename, NULL, path) <= 32) 297 findresult = (int) FindExecutableA (filename, NULL, path);
298 if (findresult <= 32)
299 { 299 {
300 SetErrnoFromWinError (GetLastError ()); 300 SetErrnoFromWinError (GetLastError ());
301 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "FindExecutable", fn); 301 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "FindExecutable", filename);
302 return -1; 302 return -1;
303 } 303 }
304 304
305 if (!CreateProcess 305 if (!CreateProcessA
306 (path, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start, 306 (path, cmd, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &start,
307 &proc)) 307 &proc))
308 { 308 {
309 SetErrnoFromWinError (GetLastError ()); 309 SetErrnoFromWinError (GetLastError ());
310 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", fn); 310 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "CreateProcess", path);
311 return -1; 311 return -1;
312 } 312 }
313 313
314 CreateThread (NULL, 64000, ChildWaitThread, proc.hProcess, 0, NULL); 314 CreateThread (NULL, 64000, ChildWaitThread, proc.hProcess, 0, NULL);
315 315
316 if (fn != filename)
317 GNUNET_free (fn);
318 CloseHandle (proc.hThread); 316 CloseHandle (proc.hThread);
319 317
320 GNUNET_free (cmd); 318 GNUNET_free (cmd);