- Allocate buffer large enough to contain UNIX_PATH_MAX size pathnames in case of...
[oweals/gnunet.git] / src / util / os_priority.c
index 0f2acca061fcaf42bff06a163d073fca31dff148..23eb1d168dbbe1d2faa06502a5dde5b176f30dba 100644 (file)
@@ -753,6 +753,7 @@ start_process (int pipe_control,
   DWORD stdif, stdof, stdef;
   BOOL bresult;
   DWORD error_code;
+  DWORD create_no_window;
 
   if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename, GNUNET_NO, NULL))
     return NULL; /* not executable */
@@ -1051,8 +1052,17 @@ start_process (int pipe_control,
     return NULL;
   }
 
+  create_no_window = 0;
+  {
+    HANDLE console_input = CreateFile ("CONIN$", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
+    if (INVALID_HANDLE_VALUE == console_input)
+      create_no_window = CREATE_NO_WINDOW;
+    else
+      CloseHandle (console_input);
+  }
+
   bresult = CreateProcessW (wpath, wcmd, NULL, NULL, GNUNET_YES,
-       CREATE_NO_WINDOW | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
+       create_no_window | CREATE_SUSPENDED, env_block, NULL, &start, &proc);
   error_code = GetLastError ();
 
   if ((NULL == pipe_stdin) && (stdih))
@@ -1089,7 +1099,7 @@ start_process (int pipe_control,
     return NULL;
   }
 
-  gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process));
+  gnunet_proc = GNUNET_new (struct GNUNET_OS_Process);
   gnunet_proc->pid = proc.dwProcessId;
   gnunet_proc->handle = proc.hProcess;
   gnunet_proc->control_pipe = childpipe_write;
@@ -1330,9 +1340,9 @@ GNUNET_OS_start_process_v (int pipe_control,
 
 /**
  * Start a process.  This function is similar to the GNUNET_OS_start_process_*
- * except that the @a filename and @argv can have whole strings which contain
+ * except that the filename and arguments can have whole strings which contain
  * the arguments.  These arguments are to be separated by spaces and are parsed
- * in the order they appear.  Arguments containing spaces can be used by 
+ * in the order they appear.  Arguments containing spaces can be used by
  * quoting them with @em ".
  *
  * @param pipe_control should a pipe be used to send signals to the child?
@@ -1341,18 +1351,16 @@ GNUNET_OS_start_process_v (int pipe_control,
  *         must be NULL on platforms where dup is not supported
  * @param filename name of the binary.  It is valid to have the arguments
  *         in this string when they are separated by spaces.
- * @param ... more arguments.  Should be of type <tt>char *</tt>.  It is valid
+ * @param ... more arguments.  Should be of type `char *`.  It is valid
  *         to have the arguments in these strings when they are separated by
- *         spaces.
- * @param argv NULL-terminated list of arguments to the process,
- *             including the process name as the first argument
+ *         spaces.  The last argument MUST be NULL.
  * @return pointer to process structure of the new process, NULL on error
  */
 struct GNUNET_OS_Process *
 GNUNET_OS_start_process_s (int pipe_control,
                            unsigned int std_inheritance,
                            const SOCKTYPE * lsocks,
-                           const char *first_arg, ...)
+                           const char *filename, ...)
 {
   va_list ap;
   char **argv;
@@ -1369,8 +1377,8 @@ GNUNET_OS_start_process_s (int pipe_control,
   size_t len;
 
   argv_size = 1;
-  va_start (ap, first_arg);
-  arg = first_arg;
+  va_start (ap, filename);
+  arg = filename;
   last = NULL;
   do
   {
@@ -1384,7 +1392,7 @@ GNUNET_OS_start_process_s (int pipe_control,
          quote_on = 0;
        else
          quote_on = 1;
-      }        
+      }
       if ( (' ' == *rpos) && (0 == quote_on) )
       {
        if (NULL != last)
@@ -1407,8 +1415,8 @@ GNUNET_OS_start_process_s (int pipe_control,
 
   argv = GNUNET_malloc (argv_size * sizeof (char *));
   argv_size = 0;
-  va_start (ap, first_arg);
-  arg = first_arg;
+  va_start (ap, filename);
+  arg = filename;
   last = NULL;
   do
   {
@@ -1416,7 +1424,7 @@ GNUNET_OS_start_process_s (int pipe_control,
     quote_on = 0;
     pos = cp;
     while ('\0' != *pos)
-    {  
+    {
       if ('"' == *pos)
       {
        if (1 == quote_on)
@@ -1447,14 +1455,14 @@ GNUNET_OS_start_process_s (int pipe_control,
   while (NULL != (arg = (va_arg (ap, const char*))));
   va_end (ap);
   argv[argv_size] = NULL;
-  
+
   for(i = 0; i < argv_size; i++)
   {
     len = strlen (argv[i]);
     if ( (argv[i][0] == '"') && (argv[i][len-1] == '"'))
     {
       memmove (&argv[i][0], &argv[i][1], len - 2);
-      argv[i][len-2] = '\0';  
+      argv[i][len-2] = '\0';
     }
   }
   binary_path = argv[0];
@@ -1776,7 +1784,7 @@ GNUNET_OS_command_run (GNUNET_OS_LineProcessor proc, void *proc_cls,
     return NULL;
   }
   GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
-  cmd = GNUNET_malloc (sizeof (struct GNUNET_OS_CommandHandle));
+  cmd = GNUNET_new (struct GNUNET_OS_CommandHandle);
   cmd->timeout = GNUNET_TIME_relative_to_absolute (timeout);
   cmd->eip = eip;
   cmd->opipe = opipe;