gnunet

Main GNUnet Logic
Log | Files | Refs | Submodules | README | LICENSE

commit 447ebb5371c2cdc54aa6d5a39919cfee688c2b8e
parent 73c61a51290216778e5e8b7152fcbd48ef1b3131
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 26 Nov 2013 22:39:32 +0000

allow spaces in binary file names (#3094)

Diffstat:
Msrc/arm/arm_api.c | 13+++++++++----
Msrc/arm/do_start_process.c | 112+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Msrc/arm/gnunet-service-arm.c | 14++++++++++----
3 files changed, 86 insertions(+), 53 deletions(-)

diff --git a/src/arm/arm_api.c b/src/arm/arm_api.c @@ -759,6 +759,7 @@ arm_service_report (void *cls, unsigned char test_is_active; char *cbinary; char *binary; + char *quotedbinary; char *config; char *loprefix; char *lopostfix; @@ -817,6 +818,9 @@ arm_service_report (void *cls, 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 @@ arm_service_report (void *cls, /* 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 @@ arm_service_report (void *cls, { 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); diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c @@ -50,37 +50,45 @@ do_start_process (int pipe_control, unsigned int std_inheritance, 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 @@ do_start_process (int pipe_control, unsigned int std_inheritance, 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); diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c @@ -414,6 +414,7 @@ start_process (struct ServiceList *sl, SOCKTYPE *lsocks; unsigned int ls; char *binary; + char *quotedbinary; /* calculate listen socket list */ lsocks = NULL; @@ -486,18 +487,22 @@ start_process (struct ServiceList *sl, "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 @@ start_process (struct ServiceList *sl, 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"),