$(top_builddir)/src/util/libgnunetutil.la
EXTRA_DIST = \
- test_arm_api_data.conf
+ test_arm_api_data.conf \
+ do_start_process.c
};
+#include "do_start_process.c"
+
/**
* A client specifically requested starting of ARM itself.
pid_t pid;
char *binary;
char *config;
+ char *loprefix;
+ char *lopostfix;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
{
"gnunet-service-arm");
#endif
/* FIXME: should we check that HOSTNAME for 'arm' is localhost? */
- /* FIXME: interpret 'PREFIX' and 'OPTIONS' configuration options
- (as done by 'gnunet-service-arm.c::start_process') */
- /* start service */
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
+ "arm", "PREFIX", &loprefix))
+ loprefix = GNUNET_strdup ("");
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
+ "arm", "OPTIONS", &lopostfix))
+ lopostfix = GNUNET_strdup ("");
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (pos->h->cfg,
"arm",
if (pos->callback != NULL)
pos->callback (pos->cls, GNUNET_SYSERR);
GNUNET_free (pos);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
return;
}
if (GNUNET_OK !=
pos->callback (pos->cls, GNUNET_SYSERR);
GNUNET_free (binary);
GNUNET_free (pos);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
return;
}
- pid = GNUNET_OS_start_process (NULL, NULL, binary, binary, "-d", "-c", config,
+ pid = do_start_process (loprefix,
+ binary,
+ "-c", config,
#if DEBUG_ARM
- "-L", "DEBUG",
+ "-L", "DEBUG",
#endif
- NULL);
+ "-d",
+ lopostfix,
+ NULL);
GNUNET_free (binary);
GNUNET_free (config);
+ GNUNET_free (loprefix);
+ GNUNET_free (lopostfix);
if (pid == -1)
{
if (pos->callback != NULL)
--- /dev/null
+/**
+ * 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 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
+ */
+static pid_t
+do_start_process (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;
+ pid_t pid;
+
+ argv_size = 1;
+ va_start (ap, first_arg);
+ arg = first_arg;
+ last = NULL;
+ do
+ {
+ rpos = arg;
+ while ('\0' != *rpos)
+ {
+ if (' ' == *rpos)
+ {
+ if (last != NULL)
+ argv_size++;
+ last = NULL;
+ while (' ' == *rpos)
+ rpos++;
+ }
+ if ( (last == NULL) && (*rpos != '\0') )
+ last = rpos;
+ if (*rpos != '\0')
+ rpos++;
+ }
+ if (last != NULL)
+ 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);
+ pos = cp;
+ while ('\0' != *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++;
+ }
+ if (last != NULL)
+ 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;
+ pid = GNUNET_OS_start_process_v (argv[0], argv);
+ while (argv_size > 0)
+ GNUNET_free (argv[--argv_size]);
+ GNUNET_free (argv);
+ return pid;
+}
GNUNET_free (pos);
}
+#include "do_start_process.c"
/**
* Actually start the process for the given service.
start_process (struct ServiceList *sl)
{
char *loprefix;
- char *lopostfix;
char *options;
- char **argv;
- unsigned int argv_size;
- char *lopos;
char *optpos;
- const char *firstarg;
int use_debug;
/* start service */
GNUNET_CONFIGURATION_get_value_string (cfg,
sl->name, "OPTIONS", &options))
{
- options = GNUNET_strdup (lopostfix);
+ options = GNUNET_strdup (final_option);
/* replace '{}' with service name */
if (NULL == strstr (options, "%"))
{
"Starting service `%s' using binary `%s' and configuration `%s'\n",
sl->name, sl->binary, sl->config);
#endif
- argv_size = 6;
- if (use_debug)
- argv_size += 2;
- lopos = loprefix;
- while ('\0' != *lopos)
- {
- if (*lopos == ' ')
- argv_size++;
- lopos++;
- }
- optpos = options;
- while ('\0' != *optpos)
- {
- if (*optpos == ' ')
- argv_size++;
- optpos++;
- }
- firstarg = NULL;
- argv = GNUNET_malloc (argv_size * sizeof (char *));
- argv_size = 0;
- lopos = loprefix;
-
- while ('\0' != *lopos)
- {
- while (*lopos == ' ')
- lopos++;
- if (*lopos == '\0')
- continue;
- if (argv_size == 0)
- firstarg = lopos;
- argv[argv_size++] = lopos;
- while (('\0' != *lopos) && (' ' != *lopos))
- lopos++;
- if ('\0' == *lopos)
- continue;
- *lopos = '\0';
- lopos++;
- }
- if (argv_size == 0)
- firstarg = sl->binary;
- argv[argv_size++] = sl->binary;
- argv[argv_size++] = "-c";
- argv[argv_size++] = sl->config;
if (GNUNET_YES == use_debug)
- {
- argv[argv_size++] = "-L";
- argv[argv_size++] = "DEBUG";
- }
- optpos = options;
- while ('\0' != *optpos)
- {
- while (*optpos == ' ')
- optpos++;
- if (*optpos == '\0')
- continue;
- argv[argv_size++] = optpos;
- while (('\0' != *optpos) && (' ' != *optpos))
- optpos++;
- if ('\0' == *optpos)
- continue;
- *optpos = '\0';
- optpos++;
- }
- argv[argv_size] = NULL;
- sl->pid = GNUNET_OS_start_process_v (firstarg, argv);
- /* FIXME: should check sl->pid */
- GNUNET_free (argv);
+ sl->pid = do_start_process (loprefix,
+ sl->binary,
+ "-c", sl->config,
+ "-L", "DEBUG",
+ options,
+ NULL);
+ else
+ sl->pid = do_start_process (loprefix,
+ sl->binary,
+ "-c", sl->config,
+ options,
+ NULL);
GNUNET_free (loprefix);
GNUNET_free (options);
+ /* FIXME: should check sl->pid */
}
[resolver]
#DEBUG = YES
+PORT = 23355
[do-nothing]
#DEBUG = YES
{
int ret;
- fprintf (stdout,
- "This test will print some warnings about 'do-nothing' being terminated. That's expected!\n");
GNUNET_log_setup ("test-exponential-backoff",
#if VERBOSE
"DEBUG",