int sane_execvp(const char *file, char * const argv[])
{
+#ifndef GIT_WINDOWS_NATIVE
+ /*
+ * execvp() doesn't return, so we all we can do is tell trace2
+ * what we are about to do and let it leave a hint in the log
+ * (unless of course the execvp() fails).
+ *
+ * we skip this for Windows because the compat layer already
+ * has to emulate the execvp() call anyway.
+ */
+ int exec_id = trace2_exec(file, (const char **)argv);
+#endif
+
if (!execvp(file, argv))
return 0; /* cannot happen ;-) */
+#ifndef GIT_WINDOWS_NATIVE
+ {
+ int ec = errno;
+ trace2_exec_result(exec_id, ec);
+ errno = ec;
+ }
+#endif
+
/*
* When a command can't be found because one of the directories
* listed in $PATH is unsearchable, execvp reports EACCES, but
cmd->err = fderr[0];
}
+ trace2_child_start(cmd);
trace_run_command(cmd);
fflush(NULL);
if (prepare_cmd(&argv, cmd) < 0) {
failed_errno = errno;
cmd->pid = -1;
+ if (!cmd->silent_exec_failure)
+ error_errno("cannot run %s", cmd->argv[0]);
goto end_of_spawn;
}
#endif
if (cmd->pid < 0) {
+ trace2_child_exit(cmd, -1);
+
if (need_in)
close_pair(fdin);
else if (cmd->in)
int finish_command(struct child_process *cmd)
{
int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
+ trace2_child_exit(cmd, ret);
child_process_clear(cmd);
return ret;
}
int finish_command_in_signal(struct child_process *cmd)
{
- return wait_or_whine(cmd->pid, cmd->argv[0], 1);
+ int ret = wait_or_whine(cmd->pid, cmd->argv[0], 1);
+ trace2_child_exit(cmd, ret);
+ return ret;
}
return run_command_v_opt_cd_env(argv, opt, NULL, NULL);
}
+int run_command_v_opt_tr2(const char **argv, int opt, const char *tr2_class)
+{
+ return run_command_v_opt_cd_env_tr2(argv, opt, NULL, NULL, tr2_class);
+}
+
int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env)
+{
+ return run_command_v_opt_cd_env_tr2(argv, opt, dir, env, NULL);
+}
+
+int run_command_v_opt_cd_env_tr2(const char **argv, int opt, const char *dir,
+ const char *const *env, const char *tr2_class)
{
struct child_process cmd = CHILD_PROCESS_INIT;
cmd.argv = argv;
cmd.clean_on_exit = opt & RUN_CLEAN_ON_EXIT ? 1 : 0;
cmd.dir = dir;
cmd.env = env;
+ cmd.trace2_child_class = tr2_class;
return run_command(&cmd);
}
hook.env = env;
hook.no_stdin = 1;
hook.stdout_to_stderr = 1;
+ hook.trace2_hook_name = name;
return run_command(&hook);
}
pp_cleanup(&pp);
return 0;
}
+
+int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task,
+ start_failure_fn start_failure,
+ task_finished_fn task_finished, void *pp_cb,
+ const char *tr2_category, const char *tr2_label)
+{
+ int result;
+
+ trace2_region_enter_printf(tr2_category, tr2_label, NULL, "max:%d",
+ ((n < 1) ? online_cpus() : n));
+
+ result = run_processes_parallel(n, get_next_task, start_failure,
+ task_finished, pp_cb);
+
+ trace2_region_leave(tr2_category, tr2_label, NULL);
+
+ return result;
+}