run-command: add pre-exec callback

This is a function provided by the caller which is called
_after_ the process is forked, but before the spawned
program is executed. On platforms (like mingw) where
subprocesses are forked and executed in a single call, the
preexec callback is simply ignored.

This will be used in the following patch to do some setup
for 'less' that must happen in the forked child.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2008-07-22 03:12:46 -04:00 committed by Junio C Hamano
parent b0320eaf6a
commit ccf08bc3d0
2 changed files with 3 additions and 0 deletions

View File

@ -110,6 +110,8 @@ int start_command(struct child_process *cmd)
unsetenv(*cmd->env); unsetenv(*cmd->env);
} }
} }
if (cmd->preexec_cb)
cmd->preexec_cb();
if (cmd->git_cmd) { if (cmd->git_cmd) {
execv_git_cmd(cmd->argv); execv_git_cmd(cmd->argv);
} else { } else {

View File

@ -42,6 +42,7 @@ struct child_process {
unsigned no_stderr:1; unsigned no_stderr:1;
unsigned git_cmd:1; /* if this is to be git sub-command */ unsigned git_cmd:1; /* if this is to be git sub-command */
unsigned stdout_to_stderr:1; unsigned stdout_to_stderr:1;
void (*preexec_cb)(void);
}; };
int start_command(struct child_process *); int start_command(struct child_process *);