gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r30967 - in gnunet/src: arm include testing util


From: gnunet
Subject: [GNUnet-SVN] r30967 - in gnunet/src: arm include testing util
Date: Fri, 29 Nov 2013 11:25:47 +0100

Author: harsha
Date: 2013-11-29 11:25:47 +0100 (Fri, 29 Nov 2013)
New Revision: 30967

Removed:
   gnunet/src/arm/do_start_process.c
Modified:
   gnunet/src/arm/arm_api.c
   gnunet/src/arm/gnunet-service-arm.c
   gnunet/src/include/gnunet_os_lib.h
   gnunet/src/testing/testing.c
   gnunet/src/util/os_priority.c
Log:
- move do_start_process to util/


Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c    2013-11-29 09:51:56 UTC (rev 30966)
+++ gnunet/src/arm/arm_api.c    2013-11-29 10:25:47 UTC (rev 30967)
@@ -737,9 +737,6 @@
 }
 
 
-#include "do_start_process.c"
-
-
 /**
  * A client specifically requested starting of ARM itself.
  * This function is called with information about whether
@@ -832,26 +829,27 @@
     /* Means we are ONLY running locally */
     /* we're clearly running a test, don't daemonize */
     if (NULL == config)
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, quotedbinary,
-                              /* no daemonization! */
-                              lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary,
+                                        /* no daemonization! */
+                                        lopostfix, NULL);
     else
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
                               NULL, loprefix, quotedbinary, "-c", config,
-                              /* no daemonization! */
-                              lopostfix, NULL);
+                                        /* no daemonization! */
+                                        lopostfix, NULL);
   }
   else
   {
     if (NULL == config)
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, quotedbinary,
-                              "-d", lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary,
+                                        "-d", lopostfix, NULL);
     else
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, quotedbinary, "-c", config,
-                              "-d", lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary, "-c",
+                                        config,
+                                        "-d", lopostfix, NULL);
   }
   GNUNET_free (binary);
   GNUNET_free (quotedbinary);

Deleted: gnunet/src/arm/do_start_process.c
===================================================================
--- gnunet/src/arm/do_start_process.c   2013-11-29 09:51:56 UTC (rev 30966)
+++ gnunet/src/arm/do_start_process.c   2013-11-29 10:25:47 UTC (rev 30967)
@@ -1,155 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2011, 2012 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-#include "gnunet_os_lib.h"
-
-/**
- * Actually start a process.  All of the arguments given to this
- * function are strings that are used for the "argv" array.  However,
- * if those strings contain spaces, the given argument is split into
- * multiple argv entries without spaces.  Similarly, if an argument is
- * the empty string, it is skipped.  This function has the inherent
- * 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 handle of the started process, NULL on error
- */
-static struct GNUNET_OS_Process *
-do_start_process (int pipe_control, unsigned int std_inheritance,
-                 const SOCKTYPE * lsocks, const char *first_arg, ...)
-{
-  va_list ap;
-  char **argv;
-  unsigned int argv_size;
-  const char *arg;
-  const char *rpos;
-  char *pos;
-  char *cp;
-  const char *last;
-  struct GNUNET_OS_Process *proc;
-  char *binary_path;
-  int quote_on;
-  unsigned int i;
-  size_t len;
-
-  argv_size = 1;
-  va_start (ap, first_arg);
-  arg = first_arg;
-  last = NULL;
-  do
-  {
-    rpos = arg;
-    quote_on = 0;
-    while ('\0' != *rpos)
-    {
-      if ('"' == *rpos)
-      {
-       if (1 == quote_on)
-         quote_on = 0;
-       else
-         quote_on = 1;
-      }        
-      if ( (' ' == *rpos) && (0 == quote_on) )
-      {
-       if (NULL != last)
-         argv_size++;
-       last = NULL;
-       rpos++;
-       while (' ' == *rpos)
-         rpos++;
-      }
-      if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=?
-       last = rpos;
-      if ('\0' != *rpos)
-       rpos++;
-    }
-    if (NULL != last)
-      argv_size++;
-  }
-  while (NULL != (arg = (va_arg (ap, const char*))));
-  va_end (ap);
-
-  argv = GNUNET_malloc (argv_size * sizeof (char *));
-  argv_size = 0;
-  va_start (ap, first_arg);
-  arg = first_arg;
-  last = NULL;
-  do
-  {
-    cp = GNUNET_strdup (arg);
-    quote_on = 0;
-    pos = cp;
-    while ('\0' != *pos)
-    {  
-      if ('"' == *pos)
-      {
-       if (1 == quote_on)
-         quote_on = 0;
-       else
-         quote_on = 1;
-      }
-      if ( (' ' == *pos) && (0 == quote_on) )
-      {
-       *pos = '\0';
-       if (NULL != last)
-         argv[argv_size++] = GNUNET_strdup (last);
-       last = NULL;
-       pos++;
-       while (' ' == *pos)
-         pos++;
-      }
-      if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
-       last = pos;
-      if ('\0' != *pos)
-       pos++;
-    }
-    if (NULL != last)
-      argv[argv_size++] = GNUNET_strdup (last);
-    last = NULL;
-    GNUNET_free (cp);
-  }
-  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';  
-    }
-  }
-  binary_path = argv[0];
-  proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks,
-                                   binary_path, argv);
-  while (argv_size > 0)
-    GNUNET_free (argv[--argv_size]);
-  GNUNET_free (argv);
-  return proc;
-}
-
-/* end of do_start_process.c */

Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2013-11-29 09:51:56 UTC (rev 30966)
+++ gnunet/src/arm/gnunet-service-arm.c 2013-11-29 10:25:47 UTC (rev 30967)
@@ -246,8 +246,6 @@
 static struct GNUNET_SERVER_NotificationContext *notifier;
 
 
-#include "do_start_process.c"
-
 /**
  * Transmit a status result message.
  *
@@ -496,27 +494,32 @@
   {
     if (NULL == sl->config)
       sl->proc =
-       do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, quotedbinary, "-L",
-                         "DEBUG", options, NULL);
+       GNUNET_OS_start_process_s (sl->pipe_control,
+                                   GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                   lsocks, loprefix, quotedbinary, "-L",
+                                   "DEBUG", options, NULL);
     else
       sl->proc =
-       do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, quotedbinary, "-c", sl->config, 
"-L",
-                         "DEBUG", options, NULL);
+          GNUNET_OS_start_process_s (sl->pipe_control,
+                                     GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                     lsocks, loprefix, quotedbinary, "-c",
+                                     sl->config, "-L",
+                                     "DEBUG", options, NULL);
   }
   else
   {
     if (NULL == sl->config)
       sl->proc =
-       do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, quotedbinary,
-                         options, NULL);
+          GNUNET_OS_start_process_s (sl->pipe_control,
+                                     GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                     lsocks, loprefix, quotedbinary,
+                                     options, NULL);
     else
       sl->proc =
-       do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, quotedbinary, "-c", sl->config,
-                         options, NULL);
+          GNUNET_OS_start_process_s (sl->pipe_control,
+                                     GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                     lsocks, loprefix, quotedbinary, "-c",
+                                     sl->config, options, NULL);
   }
   GNUNET_free (binary);
   GNUNET_free (quotedbinary);

Modified: gnunet/src/include/gnunet_os_lib.h
===================================================================
--- gnunet/src/include/gnunet_os_lib.h  2013-11-29 09:51:56 UTC (rev 30966)
+++ gnunet/src/include/gnunet_os_lib.h  2013-11-29 10:25:47 UTC (rev 30967)
@@ -381,6 +381,33 @@
 
 
 /**
+ * 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
+ * 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 
+ * quoting them with @em ".
+ *
+ * @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 systemd-style (or NULL);
+ *         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
+ *         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
+ * @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, ...);
+
+
+/**
  * Handle to a command action.
  */
 struct GNUNET_OS_CommandHandle;

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2013-11-29 09:51:56 UTC (rev 30966)
+++ gnunet/src/testing/testing.c        2013-11-29 10:25:47 UTC (rev 30967)
@@ -34,8 +34,6 @@
 #include "gnunet_arm_service.h"
 #include "gnunet_testing_lib.h"
 
-#include "../arm/do_start_process.c"
-
 #define LOG(kind,...)                                           \
   GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
 
@@ -1254,7 +1252,6 @@
   }
   else
   {
-    peer->main_binary = GNUNET_CONFIGURATION_expand_dollar (peer->cfg, 
peer->main_binary);
     peer->args = strdup (libexec_binary);
   }
   peer->system = system;
@@ -1325,14 +1322,15 @@
       return GNUNET_SYSERR;
     i->n_refs++;
   }
-  peer->main_process = do_start_process (PIPE_CONTROL,
-                                         GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                                         NULL,
-                                         peer->main_binary,
-                                         peer->args,
-                                         "-c",
-                                         peer->cfgfile,
-                                         NULL);
+  peer->main_binary = GNUNET_CONFIGURATION_expand_dollar (peer->cfg, 
peer->main_binary);
+  peer->main_process = GNUNET_OS_start_process_s (PIPE_CONTROL,
+                                                  
GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
+                                                  NULL,
+                                                  peer->main_binary,
+                                                  peer->args,
+                                                  "-c",
+                                                  peer->cfgfile,
+                                                  NULL);
   if (NULL == peer->main_process)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,

Modified: gnunet/src/util/os_priority.c
===================================================================
--- gnunet/src/util/os_priority.c       2013-11-29 09:51:56 UTC (rev 30966)
+++ gnunet/src/util/os_priority.c       2013-11-29 10:25:47 UTC (rev 30967)
@@ -1329,6 +1329,145 @@
 
 
 /**
+ * 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
+ * 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 
+ * quoting them with @em ".
+ *
+ * @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 systemd-style (or NULL);
+ *         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
+ *         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
+ * @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, ...)
+{
+  va_list ap;
+  char **argv;
+  unsigned int argv_size;
+  const char *arg;
+  const char *rpos;
+  char *pos;
+  char *cp;
+  const char *last;
+  struct GNUNET_OS_Process *proc;
+  char *binary_path;
+  int quote_on;
+  unsigned int i;
+  size_t len;
+
+  argv_size = 1;
+  va_start (ap, first_arg);
+  arg = first_arg;
+  last = NULL;
+  do
+  {
+    rpos = arg;
+    quote_on = 0;
+    while ('\0' != *rpos)
+    {
+      if ('"' == *rpos)
+      {
+       if (1 == quote_on)
+         quote_on = 0;
+       else
+         quote_on = 1;
+      }        
+      if ( (' ' == *rpos) && (0 == quote_on) )
+      {
+       if (NULL != last)
+         argv_size++;
+       last = NULL;
+       rpos++;
+       while (' ' == *rpos)
+         rpos++;
+      }
+      if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=?
+       last = rpos;
+      if ('\0' != *rpos)
+       rpos++;
+    }
+    if (NULL != last)
+      argv_size++;
+  }
+  while (NULL != (arg = (va_arg (ap, const char*))));
+  va_end (ap);
+
+  argv = GNUNET_malloc (argv_size * sizeof (char *));
+  argv_size = 0;
+  va_start (ap, first_arg);
+  arg = first_arg;
+  last = NULL;
+  do
+  {
+    cp = GNUNET_strdup (arg);
+    quote_on = 0;
+    pos = cp;
+    while ('\0' != *pos)
+    {  
+      if ('"' == *pos)
+      {
+       if (1 == quote_on)
+         quote_on = 0;
+       else
+         quote_on = 1;
+      }
+      if ( (' ' == *pos) && (0 == quote_on) )
+      {
+       *pos = '\0';
+       if (NULL != last)
+         argv[argv_size++] = GNUNET_strdup (last);
+       last = NULL;
+       pos++;
+       while (' ' == *pos)
+         pos++;
+      }
+      if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
+       last = pos;
+      if ('\0' != *pos)
+       pos++;
+    }
+    if (NULL != last)
+      argv[argv_size++] = GNUNET_strdup (last);
+    last = NULL;
+    GNUNET_free (cp);
+  }
+  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';  
+    }
+  }
+  binary_path = argv[0];
+  proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks,
+                                   binary_path, argv);
+  while (argv_size > 0)
+    GNUNET_free (argv[--argv_size]);
+  GNUNET_free (argv);
+  return proc;
+}
+
+
+/**
  * Retrieve the status of a process, waiting on him if dead.
  * Nonblocking version.
  *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]