add stdin functionality for os start process function
authorNathan S. Evans <evans@in.tum.de>
Tue, 16 Feb 2010 12:25:45 +0000 (12:25 +0000)
committerNathan S. Evans <evans@in.tum.de>
Tue, 16 Feb 2010 12:25:45 +0000 (12:25 +0000)
src/util/os_priority.c

index 9820592ac004c4fe11bbb4e2ec75f52e426d6d12..26c76483c9004ff02964812fcdbf1cdba6d9ce04 100644 (file)
@@ -127,6 +127,7 @@ pid_t
 GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, const char *filename, ...)
 {
   /* FIXME:  Make this work on windows!!! */
+  /* FIXME:  Make this work with stdin as well as stdout! */
   va_list ap;
 
 #ifndef MINGW
@@ -149,6 +150,8 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
   va_end (ap);
   if (pipe_stdout != NULL)
     GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE), &fd_stdout_write, sizeof (int));
+  if (pipe_stdin != NULL)
+    GNUNET_DISK_internal_file_handle_ (GNUNET_DISK_pipe_handle(pipe_stdout, GNUNET_DISK_PIPE_END_READ), &fd_stdin_read, sizeof (int));
 
 #if HAVE_WORKING_VFORK
   ret = vfork ();
@@ -175,17 +178,26 @@ GNUNET_OS_start_process (struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNE
           sleep (1);
           if (pipe_stdout != NULL)
             GNUNET_DISK_pipe_close_end(pipe_stdout, GNUNET_DISK_PIPE_END_WRITE);
+          if (pipe_stdin != NULL)
+            GNUNET_DISK_pipe_close_end(pipe_stdin, GNUNET_DISK_PIPE_END_READ);
 #endif
         }
       GNUNET_free (argv);
       return ret;
     }
+
   if (pipe_stdout != NULL)
     {
       dup2(fd_stdout_write, 1);
       close (fd_stdout_write);
     }
 
+  if (pipe_stdout != NULL)
+    {
+      dup2(fd_stdin_read, 0);
+      close (fd_stdin_read);
+    }
+
   execvp (filename, argv);
   GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename);
   _exit (1);