+ cmd = xbt_str_split_quoted(rctx->cmd);
+ xbt_dynar_get_cpy(cmd, 0, &binary_name);
+ args = xbt_new(char *, xbt_dynar_length(cmd) + 1);
+ xbt_dynar_foreach(cmd, it, str) {
+ args[it] = xbt_strdup(str);
+ }
+ args[it] = NULL;
+ xbt_dynar_free_container(&cmd);
+
+ /* To search for the right executable path when not trivial */
+ struct stat stat_buf;
+
+ /* build the command line */
+ if (stat(binary_name, &stat_buf)) {
+ /* Damn. binary not in current dir. We'll have to dig the PATH to find it */
+ int i;
+
+ for (i = 0; environ[i]; i++) {
+ if (!strncmp("PATH=", environ[i], 5)) {
+ xbt_dynar_t path = xbt_str_split(environ[i] + 5, ":");
+
+ xbt_dynar_foreach(path, it, str) {
+ free(binary_name);
+ binary_name = bprintf("%s/%s", str, args[0]);
+ if (!stat(binary_name, &stat_buf)) {
+ /* Found. */
+ XBT_DEBUG("Looked in the PATH for the binary. Found %s",
+ binary_name);
+ xbt_dynar_free(&path);
+ break;
+ }
+ }
+ xbt_dynar_free(&path);
+ if (stat(binary_name, &stat_buf)) {
+ /* not found */
+ printf("TESH_ERROR Command %s not found\n", args[0]);
+ exit(127);
+ }
+ break;
+ }
+ }
+ } else {
+ binary_name = xbt_strdup(args[0]);
+ }
+
+ errcode = execve(binary_name, args, rctx->env);
+ printf("TESH_ERROR %s: Cannot start %s: %s\n", rctx->filepos, rctx->cmd,
+ strerror(errcode));
+ exit(127);
+}
+
+/* Start a new child, plug the pipes as expected and fire up the
+ helping threads. Is also waits for the child to end if this is a
+ foreground job, or fire up a thread to wait otherwise. */
+void rctx_start(void)
+{