diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-11-26 22:39:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-11-26 22:39:32 +0000 |
commit | 447ebb5371c2cdc54aa6d5a39919cfee688c2b8e (patch) | |
tree | 8b901209fb4e8fbbcf68442d7a6ec26e460401c6 | |
parent | 73c61a51290216778e5e8b7152fcbd48ef1b3131 (diff) | |
download | gnunet-447ebb5371c2cdc54aa6d5a39919cfee688c2b8e.tar.gz gnunet-447ebb5371c2cdc54aa6d5a39919cfee688c2b8e.zip |
allow spaces in binary file names (#3094)
-rw-r--r-- | src/arm/arm_api.c | 13 | ||||
-rw-r--r-- | src/arm/do_start_process.c | 112 | ||||
-rw-r--r-- | src/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 index 9644026d6..d27b6b780 100644 --- a/src/arm/arm_api.c +++ b/src/arm/arm_api.c | |||
@@ -759,6 +759,7 @@ arm_service_report (void *cls, | |||
759 | unsigned char test_is_active; | 759 | unsigned char test_is_active; |
760 | char *cbinary; | 760 | char *cbinary; |
761 | char *binary; | 761 | char *binary; |
762 | char *quotedbinary; | ||
762 | char *config; | 763 | char *config; |
763 | char *loprefix; | 764 | char *loprefix; |
764 | char *lopostfix; | 765 | char *lopostfix; |
@@ -817,6 +818,9 @@ arm_service_report (void *cls, | |||
817 | cm->h->cfg, "arm", "CONFIG", &config)) | 818 | cm->h->cfg, "arm", "CONFIG", &config)) |
818 | config = NULL; | 819 | config = NULL; |
819 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); | 820 | binary = GNUNET_OS_get_libexec_binary_path (cbinary); |
821 | GNUNET_asprintf ("edbinary, | ||
822 | "\"%s\"", | ||
823 | binary); | ||
820 | GNUNET_free (cbinary); | 824 | GNUNET_free (cbinary); |
821 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value ( | 825 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value ( |
822 | cm->h->cfg, "TESTING", "WEAKRANDOM")) && | 826 | cm->h->cfg, "TESTING", "WEAKRANDOM")) && |
@@ -829,12 +833,12 @@ arm_service_report (void *cls, | |||
829 | /* we're clearly running a test, don't daemonize */ | 833 | /* we're clearly running a test, don't daemonize */ |
830 | if (NULL == config) | 834 | if (NULL == config) |
831 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 835 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, |
832 | NULL, loprefix, binary, | 836 | NULL, loprefix, quotedbinary, |
833 | /* no daemonization! */ | 837 | /* no daemonization! */ |
834 | lopostfix, NULL); | 838 | lopostfix, NULL); |
835 | else | 839 | else |
836 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 840 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, |
837 | NULL, loprefix, binary, "-c", config, | 841 | NULL, loprefix, quotedbinary, "-c", config, |
838 | /* no daemonization! */ | 842 | /* no daemonization! */ |
839 | lopostfix, NULL); | 843 | lopostfix, NULL); |
840 | } | 844 | } |
@@ -842,14 +846,15 @@ arm_service_report (void *cls, | |||
842 | { | 846 | { |
843 | if (NULL == config) | 847 | if (NULL == config) |
844 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 848 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, |
845 | NULL, loprefix, binary, | 849 | NULL, loprefix, quotedbinary, |
846 | "-d", lopostfix, NULL); | 850 | "-d", lopostfix, NULL); |
847 | else | 851 | else |
848 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, | 852 | proc = do_start_process (GNUNET_NO, cm->std_inheritance, |
849 | NULL, loprefix, binary, "-c", config, | 853 | NULL, loprefix, quotedbinary, "-c", config, |
850 | "-d", lopostfix, NULL); | 854 | "-d", lopostfix, NULL); |
851 | } | 855 | } |
852 | GNUNET_free (binary); | 856 | GNUNET_free (binary); |
857 | GNUNET_free (quotedbinary); | ||
853 | GNUNET_free_non_null (config); | 858 | GNUNET_free_non_null (config); |
854 | GNUNET_free (loprefix); | 859 | GNUNET_free (loprefix); |
855 | GNUNET_free (lopostfix); | 860 | GNUNET_free (lopostfix); |
diff --git a/src/arm/do_start_process.c b/src/arm/do_start_process.c index d8ee1f0c3..3ff6eba52 100644 --- 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, | |||
50 | const char *last; | 50 | const char *last; |
51 | struct GNUNET_OS_Process *proc; | 51 | struct GNUNET_OS_Process *proc; |
52 | char *binary_path; | 52 | char *binary_path; |
53 | int quote_on; | ||
54 | unsigned int i; | ||
55 | size_t len; | ||
53 | 56 | ||
54 | argv_size = 1; | 57 | argv_size = 1; |
55 | va_start (ap, first_arg); | 58 | va_start (ap, first_arg); |
56 | arg = first_arg; | 59 | arg = first_arg; |
57 | last = NULL; | 60 | last = NULL; |
58 | /* *INDENT-OFF* */ | ||
59 | do | 61 | do |
62 | { | ||
63 | rpos = arg; | ||
64 | quote_on = 0; | ||
65 | while ('\0' != *rpos) | ||
60 | { | 66 | { |
61 | /* *INDENT-ON* */ | 67 | if ('"' == *rpos) |
62 | rpos = arg; | 68 | { |
63 | while ('\0' != *rpos) | 69 | if (1 == quote_on) |
64 | { | 70 | quote_on = 0; |
65 | if (' ' == *rpos) | 71 | else |
66 | { | 72 | quote_on = 1; |
67 | if (last != NULL) | 73 | } |
68 | argv_size++; | 74 | if ( (' ' == *rpos) && (0 == quote_on) ) |
69 | last = NULL; | 75 | { |
70 | while (' ' == *rpos) | 76 | if (NULL != last) |
71 | rpos++; | 77 | argv_size++; |
72 | } | 78 | last = NULL; |
73 | if ((last == NULL) && (*rpos != '\0')) | 79 | rpos++; |
80 | while (' ' == *rpos) | ||
81 | rpos++; | ||
82 | } | ||
83 | if ( (NULL == last) && ('\0' != *rpos) ) // FIXME: == or !=? | ||
74 | last = rpos; | 84 | last = rpos; |
75 | if (*rpos != '\0') | 85 | if ('\0' != *rpos) |
76 | rpos++; | 86 | rpos++; |
77 | } | 87 | } |
78 | if (last != NULL) | 88 | if (NULL != last) |
79 | argv_size++; | 89 | argv_size++; |
80 | /* *INDENT-OFF* */ | 90 | } |
81 | } | ||
82 | while (NULL != (arg = (va_arg (ap, const char*)))); | 91 | while (NULL != (arg = (va_arg (ap, const char*)))); |
83 | /* *INDENT-ON* */ | ||
84 | va_end (ap); | 92 | va_end (ap); |
85 | 93 | ||
86 | argv = GNUNET_malloc (argv_size * sizeof (char *)); | 94 | argv = GNUNET_malloc (argv_size * sizeof (char *)); |
@@ -88,39 +96,53 @@ do_start_process (int pipe_control, unsigned int std_inheritance, | |||
88 | va_start (ap, first_arg); | 96 | va_start (ap, first_arg); |
89 | arg = first_arg; | 97 | arg = first_arg; |
90 | last = NULL; | 98 | last = NULL; |
91 | /* *INDENT-OFF* */ | ||
92 | do | 99 | do |
93 | { | 100 | { |
94 | /* *INDENT-ON* */ | 101 | cp = GNUNET_strdup (arg); |
95 | cp = GNUNET_strdup (arg); | 102 | quote_on = 0; |
96 | pos = cp; | 103 | pos = cp; |
97 | while ('\0' != *pos) | 104 | while ('\0' != *pos) |
98 | { | 105 | { |
99 | if (' ' == *pos) | 106 | if ('"' == *pos) |
100 | { | 107 | { |
101 | *pos = '\0'; | 108 | if (1 == quote_on) |
102 | if (last != NULL) | 109 | quote_on = 0; |
103 | argv[argv_size++] = GNUNET_strdup (last); | 110 | else |
104 | last = NULL; | 111 | quote_on = 1; |
112 | } | ||
113 | if ( (' ' == *pos) && (0 == quote_on) ) | ||
114 | { | ||
115 | *pos = '\0'; | ||
116 | if (NULL != last) | ||
117 | argv[argv_size++] = GNUNET_strdup (last); | ||
118 | last = NULL; | ||
119 | pos++; | ||
120 | while (' ' == *pos) | ||
105 | pos++; | 121 | pos++; |
106 | while (' ' == *pos) | 122 | } |
107 | pos++; | 123 | if ( (NULL == last) && ('\0' != *pos)) // FIXME: == or !=? |
108 | } | ||
109 | if ((last == NULL) && (*pos != '\0')) | ||
110 | last = pos; | 124 | last = pos; |
111 | if (*pos != '\0') | 125 | if ('\0' != *pos) |
112 | pos++; | 126 | pos++; |
113 | } | 127 | } |
114 | if (last != NULL) | 128 | if (NULL != last) |
115 | argv[argv_size++] = GNUNET_strdup (last); | 129 | argv[argv_size++] = GNUNET_strdup (last); |
116 | last = NULL; | 130 | last = NULL; |
117 | GNUNET_free (cp); | 131 | GNUNET_free (cp); |
118 | /* *INDENT-OFF* */ | 132 | } |
119 | } | ||
120 | while (NULL != (arg = (va_arg (ap, const char*)))); | 133 | while (NULL != (arg = (va_arg (ap, const char*)))); |
121 | /* *INDENT-ON* */ | ||
122 | va_end (ap); | 134 | va_end (ap); |
123 | argv[argv_size] = NULL; | 135 | argv[argv_size] = NULL; |
136 | |||
137 | for(i = 0; i < argv_size; i++) | ||
138 | { | ||
139 | len = strlen (argv[i]); | ||
140 | if ( (argv[i][0] == '"') && (argv[i][len-1] == '"')) | ||
141 | { | ||
142 | memmove (&argv[i][0], &argv[i][1], len - 2); | ||
143 | argv[i][len-2] = '\0'; | ||
144 | } | ||
145 | } | ||
124 | binary_path = argv[0]; | 146 | binary_path = argv[0]; |
125 | proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, | 147 | proc = GNUNET_OS_start_process_v (pipe_control, std_inheritance, lsocks, |
126 | binary_path, argv); | 148 | binary_path, argv); |
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 44decaa7f..dcc9cf352 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -414,6 +414,7 @@ start_process (struct ServiceList *sl, | |||
414 | SOCKTYPE *lsocks; | 414 | SOCKTYPE *lsocks; |
415 | unsigned int ls; | 415 | unsigned int ls; |
416 | char *binary; | 416 | char *binary; |
417 | char *quotedbinary; | ||
417 | 418 | ||
418 | /* calculate listen socket list */ | 419 | /* calculate listen socket list */ |
419 | lsocks = NULL; | 420 | lsocks = NULL; |
@@ -486,18 +487,22 @@ start_process (struct ServiceList *sl, | |||
486 | "Starting service `%s' using binary `%s' and configuration `%s'\n", | 487 | "Starting service `%s' using binary `%s' and configuration `%s'\n", |
487 | sl->name, sl->binary, sl->config); | 488 | sl->name, sl->binary, sl->config); |
488 | binary = GNUNET_OS_get_libexec_binary_path (sl->binary); | 489 | binary = GNUNET_OS_get_libexec_binary_path (sl->binary); |
490 | GNUNET_asprintf ("edbinary, | ||
491 | "\"%s\"", | ||
492 | binary); | ||
493 | |||
489 | GNUNET_assert (NULL == sl->proc); | 494 | GNUNET_assert (NULL == sl->proc); |
490 | if (GNUNET_YES == use_debug) | 495 | if (GNUNET_YES == use_debug) |
491 | { | 496 | { |
492 | if (NULL == sl->config) | 497 | if (NULL == sl->config) |
493 | sl->proc = | 498 | sl->proc = |
494 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 499 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
495 | lsocks, loprefix, binary, "-L", | 500 | lsocks, loprefix, quotedbinary, "-L", |
496 | "DEBUG", options, NULL); | 501 | "DEBUG", options, NULL); |
497 | else | 502 | else |
498 | sl->proc = | 503 | sl->proc = |
499 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 504 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
500 | lsocks, loprefix, binary, "-c", sl->config, "-L", | 505 | lsocks, loprefix, quotedbinary, "-c", sl->config, "-L", |
501 | "DEBUG", options, NULL); | 506 | "DEBUG", options, NULL); |
502 | } | 507 | } |
503 | else | 508 | else |
@@ -505,15 +510,16 @@ start_process (struct ServiceList *sl, | |||
505 | if (NULL == sl->config) | 510 | if (NULL == sl->config) |
506 | sl->proc = | 511 | sl->proc = |
507 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 512 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
508 | lsocks, loprefix, binary, | 513 | lsocks, loprefix, quotedbinary, |
509 | options, NULL); | 514 | options, NULL); |
510 | else | 515 | else |
511 | sl->proc = | 516 | sl->proc = |
512 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 517 | do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
513 | lsocks, loprefix, binary, "-c", sl->config, | 518 | lsocks, loprefix, quotedbinary, "-c", sl->config, |
514 | options, NULL); | 519 | options, NULL); |
515 | } | 520 | } |
516 | GNUNET_free (binary); | 521 | GNUNET_free (binary); |
522 | GNUNET_free (quotedbinary); | ||
517 | if (sl->proc == NULL) | 523 | if (sl->proc == NULL) |
518 | { | 524 | { |
519 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start service `%s'\n"), | 525 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to start service `%s'\n"), |