- Allocate buffer large enough to contain UNIX_PATH_MAX size pathnames in case of...
[oweals/gnunet.git] / src / util / os_priority.c
index de5c84d4c704a8dbd84ef158f200c70794454422..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;
@@ -1339,18 +1349,18 @@ GNUNET_OS_start_process_v (int pipe_control,
  * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
  * @param lsocks array of listen sockets to dup systemd-style (or NULL);
  *         must be NULL on platforms where dup is not supported
- * @param first_arg name of the binary.  It is valid to have the arguments
+ * @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 `char *`.  It is valid
  *         to have the arguments in these strings when they are separated by
- *         spaces.
+ *         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;
@@ -1367,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
   {
@@ -1405,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
   {
@@ -1774,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;