зеркало из 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:
Родитель
b478675027
Коммит
0c3aa26907
|
@ -4,6 +4,7 @@
|
||||||
#include "sub-process.h"
|
#include "sub-process.h"
|
||||||
#include "sigchain.h"
|
#include "sigchain.h"
|
||||||
#include "pkt-line.h"
|
#include "pkt-line.h"
|
||||||
|
#include "quote.h"
|
||||||
|
|
||||||
int cmd2process_cmp(const void *unused_cmp_data,
|
int cmd2process_cmp(const void *unused_cmp_data,
|
||||||
const struct hashmap_entry *eptr,
|
const struct hashmap_entry *eptr,
|
||||||
|
@ -118,6 +119,52 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
|
||||||
return 0;
|
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,
|
static int handshake_version(struct child_process *process,
|
||||||
const char *welcome_prefix, int *versions,
|
const char *welcome_prefix, int *versions,
|
||||||
int *chosen_version)
|
int *chosen_version)
|
||||||
|
|
|
@ -57,6 +57,12 @@ typedef int(*subprocess_start_fn)(struct subprocess_entry *entry);
|
||||||
int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, const char *cmd,
|
int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, const char *cmd,
|
||||||
subprocess_start_fn startfn);
|
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. */
|
/* Kill a subprocess and remove it from the subprocess hashmap. */
|
||||||
void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry);
|
void subprocess_stop(struct hashmap *hashmap, struct subprocess_entry *entry);
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче