зеркало из https://github.com/microsoft/git.git
sub-process: add subprocess_start_argv()
Add function to start a subprocess with an argv. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
This commit is contained in:
Родитель
f883e257bb
Коммит
84b40b9202
|
@ -5,6 +5,7 @@
|
|||
#include "sub-process.h"
|
||||
#include "sigchain.h"
|
||||
#include "pkt-line.h"
|
||||
#include "quote.h"
|
||||
|
||||
int cmd2process_cmp(const void *cmp_data UNUSED,
|
||||
const struct hashmap_entry *eptr,
|
||||
|
@ -119,6 +120,52 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
|
|||
return 0;
|
||||
}
|
||||
|
||||
int subprocess_start_strvec(struct hashmap *hashmap,
|
||||
struct subprocess_entry *entry,
|
||||
int is_git_cmd,
|
||||
const struct strvec *argv,
|
||||
subprocess_start_fn startfn)
|
||||
{
|
||||
int err;
|
||||
int k;
|
||||
struct child_process *process;
|
||||
struct strbuf quoted = STRBUF_INIT;
|
||||
|
||||
process = &entry->process;
|
||||
|
||||
child_process_init(process);
|
||||
for (k = 0; k < argv->nr; k++)
|
||||
strvec_push(&process->args, argv->v[k]);
|
||||
process->use_shell = 1;
|
||||
process->in = -1;
|
||||
process->out = -1;
|
||||
process->git_cmd = is_git_cmd;
|
||||
process->clean_on_exit = 1;
|
||||
process->clean_on_exit_handler = subprocess_exit_handler;
|
||||
process->trace2_child_class = "subprocess";
|
||||
|
||||
sq_quote_argv_pretty("ed, argv->v);
|
||||
entry->cmd = strbuf_detach("ed, NULL);
|
||||
|
||||
err = start_command(process);
|
||||
if (err) {
|
||||
error("cannot fork to run subprocess '%s'", entry->cmd);
|
||||
return err;
|
||||
}
|
||||
|
||||
hashmap_entry_init(&entry->ent, strhash(entry->cmd));
|
||||
|
||||
err = startfn(entry);
|
||||
if (err) {
|
||||
error("initialization for subprocess '%s' failed", entry->cmd);
|
||||
subprocess_stop(hashmap, entry);
|
||||
return err;
|
||||
}
|
||||
|
||||
hashmap_add(hashmap, &entry->ent);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handshake_version(struct child_process *process,
|
||||
const char *welcome_prefix, int *versions,
|
||||
int *chosen_version)
|
||||
|
|
|
@ -56,6 +56,12 @@ typedef int(*subprocess_start_fn)(struct subprocess_entry *entry);
|
|||
int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, const char *cmd,
|
||||
subprocess_start_fn startfn);
|
||||
|
||||
int subprocess_start_strvec(struct hashmap *hashmap,
|
||||
struct subprocess_entry *entry,
|
||||
int is_git_cmd,
|
||||
const struct strvec *argv,
|
||||
subprocess_start_fn startfn);
|
||||
|
||||
/* Kill a subprocess and remove it from the subprocess hashmap. */
|
||||
void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче