-fixing #2546
[oweals/gnunet.git] / src / arm / do_start_process.c
index a2aca9deacd5245e04f674b77f0ede211e177a2d..1bc56d540b7607abfaed8545468fe5eabeed166b 100644 (file)
@@ -7,14 +7,16 @@
  * limitation that it does NOT allow passing command line arguments
  * with spaces to the new process.
  *
+ * @param pipe_control should a pipe be used to send signals to the child?
+ * @param std_inheritance a set of GNUNET_OS_INHERIT_STD_* flags
  * @param lsocks array of listen sockets to dup starting at fd3 (systemd-style), or NULL
  * @param first_arg first argument for argv (may be an empty string)
  * @param ... more arguments, NULL terminated
- * @return PID of the started process, -1 on error
+ * @return handle of the started process, NULL on error
  */
 static struct GNUNET_OS_Process *
-do_start_process (const int *lsocks,
-                 const char *first_arg, ...)
+do_start_process (int pipe_control, unsigned int std_inheritance,
+                 const SOCKTYPE * lsocks, const char *first_arg, ...)
 {
   va_list ap;
   char **argv;
@@ -34,24 +36,24 @@ do_start_process (const int *lsocks,
   do
     {
 /* *INDENT-ON* */
-      rpos = arg;
-      while ('\0' != *rpos)
+  rpos = arg;
+  while ('\0' != *rpos)
+    {
+      if (' ' == *rpos)
        {
-         if (' ' == *rpos)
-           {
-             if (last != NULL)
-               argv_size++;
-             last = NULL;
-             while (' ' == *rpos)
-               rpos++;
-           } 
-         if ( (last == NULL) && (*rpos != '\0') )
-           last = rpos;
-         if (*rpos != '\0')
+         if (last != NULL)
+           argv_size++;
+         last = NULL;
+         while (' ' == *rpos)
            rpos++;
-       }      
-      if (last != NULL)
-       argv_size++;
+       }
+      if ((last == NULL) && (*rpos != '\0'))
+       last = rpos;
+      if (*rpos != '\0')
+       rpos++;
+    }
+  if (last != NULL)
+    argv_size++;
 /* *INDENT-OFF* */
     }
   while (NULL != (arg = (va_arg (ap, const char*))));
@@ -67,36 +69,36 @@ do_start_process (const int *lsocks,
   do
     {
 /* *INDENT-ON* */
-      cp = GNUNET_strdup (arg);
-      pos = cp;
-      while ('\0' != *pos)
+  cp = GNUNET_strdup (arg);
+  pos = cp;
+  while ('\0' != *pos)
+    {
+      if (' ' == *pos)
        {
-         if (' ' == *pos)
-           {
-             *pos = '\0';
-             if (last != NULL)
-               argv[argv_size++] = GNUNET_strdup (last);
-             last = NULL;
-             pos++;
-             while (' ' == *pos)
-               pos++;
-           }
-         if ( (last == NULL) && (*pos != '\0') ) 
-           last = pos;
-         if (*pos != '\0')
+         *pos = '\0';
+         if (last != NULL)
+           argv[argv_size++] = GNUNET_strdup (last);
+         last = NULL;
+         pos++;
+         while (' ' == *pos)
            pos++;
        }
-      if (last != NULL)
-       argv[argv_size++] = GNUNET_strdup (last);
-      last = NULL;
-      GNUNET_free (cp);
+      if ((last == NULL) && (*pos != '\0'))
+       last = pos;
+      if (*pos != '\0')
+       pos++;
+    }
+  if (last != NULL)
+    argv[argv_size++] = GNUNET_strdup (last);
+  last = NULL;
+  GNUNET_free (cp);
 /* *INDENT-OFF* */
     }
   while (NULL != (arg = (va_arg (ap, const char*))));
 /* *INDENT-ON* */
   va_end (ap);
   argv[argv_size] = NULL;
-  proc = GNUNET_OS_start_process_v (lsocks, argv[0], argv);
+  proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, argv[0], argv);
   while (argv_size > 0)
     GNUNET_free (argv[--argv_size]);
   GNUNET_free (argv);