gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30885 - gnunet/src/arm


From: gnunet
Subject: [GNUnet-SVN] r30885 - gnunet/src/arm
Date: Tue, 26 Nov 2013 23:39:32 +0100

Author: grothoff
Date: 2013-11-26 23:39:32 +0100 (Tue, 26 Nov 2013)
New Revision: 30885

Modified:
   gnunet/src/arm/arm_api.c
   gnunet/src/arm/do_start_process.c
   gnunet/src/arm/gnunet-service-arm.c
Log:
allow spaces in binary file names (#3094)

Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c    2013-11-26 22:30:41 UTC (rev 30884)
+++ gnunet/src/arm/arm_api.c    2013-11-26 22:39:32 UTC (rev 30885)
@@ -759,6 +759,7 @@
   unsigned char test_is_active;
   char *cbinary;
   char *binary;
+  char *quotedbinary;
   char *config;
   char *loprefix;
   char *lopostfix;
@@ -817,6 +818,9 @@
       cm->h->cfg, "arm", "CONFIG", &config))
     config = NULL;
   binary = GNUNET_OS_get_libexec_binary_path (cbinary);
+  GNUNET_asprintf (&quotedbinary,
+                  "\"%s\"",
+                  binary);
   GNUNET_free (cbinary);
   if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (
           cm->h->cfg, "TESTING", "WEAKRANDOM")) &&
@@ -829,12 +833,12 @@
     /* we're clearly running a test, don't daemonize */
     if (NULL == config)
       proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary,
+                              NULL, loprefix, quotedbinary,
                               /* no daemonization! */
                               lopostfix, NULL);
     else
       proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary, "-c", config,
+                              NULL, loprefix, quotedbinary, "-c", config,
                               /* no daemonization! */
                               lopostfix, NULL);
   }
@@ -842,14 +846,15 @@
   {
     if (NULL == config)
       proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary,
+                              NULL, loprefix, quotedbinary,
                               "-d", lopostfix, NULL);
     else
       proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary, "-c", config,
+                              NULL, loprefix, quotedbinary, "-c", config,
                               "-d", lopostfix, NULL);
   }
   GNUNET_free (binary);
+  GNUNET_free (quotedbinary);
   GNUNET_free_non_null (config);
   GNUNET_free (loprefix);
   GNUNET_free (lopostfix);

Modified: gnunet/src/arm/do_start_process.c
===================================================================
--- gnunet/src/arm/do_start_process.c   2013-11-26 22:30:41 UTC (rev 30884)
+++ gnunet/src/arm/do_start_process.c   2013-11-26 22:39:32 UTC (rev 30885)
@@ -50,37 +50,45 @@
   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;
-/* *INDENT-OFF* */
   do
+  {
+    rpos = arg;
+    quote_on = 0;
+    while ('\0' != *rpos)
     {
-/* *INDENT-ON* */
-  rpos = arg;
-  while ('\0' != *rpos)
-    {
-      if (' ' == *rpos)
-       {
-         if (last != NULL)
-           argv_size++;
-         last = NULL;
-         while (' ' == *rpos)
-           rpos++;
-       }
-      if ((last == NULL) && (*rpos != '\0'))
+      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 (*rpos != '\0')
+      if ('\0' != *rpos)
        rpos++;
     }
-  if (last != NULL)
-    argv_size++;
-/* *INDENT-OFF* */
-    }
+    if (NULL != last)
+      argv_size++;
+  }
   while (NULL != (arg = (va_arg (ap, const char*))));
-/* *INDENT-ON* */
   va_end (ap);
 
   argv = GNUNET_malloc (argv_size * sizeof (char *));
@@ -88,39 +96,53 @@
   va_start (ap, first_arg);
   arg = first_arg;
   last = NULL;
-/* *INDENT-OFF* */
   do
-    {
-/* *INDENT-ON* */
-  cp = GNUNET_strdup (arg);
-  pos = cp;
-  while ('\0' != *pos)
-    {
-      if (' ' == *pos)
-       {
-         *pos = '\0';
-         if (last != NULL)
-           argv[argv_size++] = GNUNET_strdup (last);
-         last = NULL;
+  {
+    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++;
-         while (' ' == *pos)
-           pos++;
-       }
-      if ((last == NULL) && (*pos != '\0'))
+      }
+      if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=?
        last = pos;
-      if (*pos != '\0')
+      if ('\0' != *pos)
        pos++;
     }
-  if (last != NULL)
-    argv[argv_size++] = GNUNET_strdup (last);
-  last = NULL;
-  GNUNET_free (cp);
-/* *INDENT-OFF* */
-    }
+    if (NULL != last)
+      argv[argv_size++] = GNUNET_strdup (last);
+    last = NULL;
+    GNUNET_free (cp);
+  }
   while (NULL != (arg = (va_arg (ap, const char*))));
-/* *INDENT-ON* */
   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);

Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2013-11-26 22:30:41 UTC (rev 30884)
+++ gnunet/src/arm/gnunet-service-arm.c 2013-11-26 22:39:32 UTC (rev 30885)
@@ -414,6 +414,7 @@
   SOCKTYPE *lsocks;
   unsigned int ls;
   char *binary;
+  char *quotedbinary;
 
   /* calculate listen socket list */
   lsocks = NULL;
@@ -486,18 +487,22 @@
              "Starting service `%s' using binary `%s' and configuration 
`%s'\n",
              sl->name, sl->binary, sl->config);
   binary = GNUNET_OS_get_libexec_binary_path (sl->binary);
+  GNUNET_asprintf (&quotedbinary,
+                  "\"%s\"",
+                  binary);
+  
   GNUNET_assert (NULL == sl->proc);
   if (GNUNET_YES == use_debug)
   {
     if (NULL == sl->config)
       sl->proc =
        do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, binary, "-L",
+                         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, binary, "-c", sl->config, "-L",
+                         lsocks, loprefix, quotedbinary, "-c", sl->config, 
"-L",
                          "DEBUG", options, NULL);
   }
   else
@@ -505,15 +510,16 @@
     if (NULL == sl->config)
       sl->proc =
        do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, binary,
+                         lsocks, loprefix, quotedbinary,
                          options, NULL);
     else
       sl->proc =
        do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, binary, "-c", sl->config,
+                         lsocks, loprefix, quotedbinary, "-c", sl->config,
                          options, NULL);
   }
   GNUNET_free (binary);
+  GNUNET_free (quotedbinary);
   if (sl->proc == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start service `%s'\n"),




reply via email to

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