|
4 | 4 | #include "sub-process.h"
|
5 | 5 | #include "sigchain.h"
|
6 | 6 | #include "pkt-line.h"
|
| 7 | +#include "quote.h" |
7 | 8 |
|
8 | 9 | int cmd2process_cmp(const void *unused_cmp_data,
|
9 | 10 | const struct hashmap_entry *eptr,
|
@@ -118,6 +119,52 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co
|
118 | 119 | return 0;
|
119 | 120 | }
|
120 | 121 |
|
| 122 | +int subprocess_start_argv(struct hashmap *hashmap, |
| 123 | + struct subprocess_entry *entry, |
| 124 | + int is_git_cmd, |
| 125 | + const struct argv_array *argv, |
| 126 | + subprocess_start_fn startfn) |
| 127 | +{ |
| 128 | + int err; |
| 129 | + int k; |
| 130 | + struct child_process *process; |
| 131 | + struct strbuf quoted = STRBUF_INIT; |
| 132 | + |
| 133 | + process = &entry->process; |
| 134 | + |
| 135 | + child_process_init(process); |
| 136 | + for (k = 0; k < argv->argc; k++) |
| 137 | + argv_array_push(&process->args, argv->argv[k]); |
| 138 | + process->use_shell = 1; |
| 139 | + process->in = -1; |
| 140 | + process->out = -1; |
| 141 | + process->git_cmd = is_git_cmd; |
| 142 | + process->clean_on_exit = 1; |
| 143 | + process->clean_on_exit_handler = subprocess_exit_handler; |
| 144 | + process->trace2_child_class = "subprocess"; |
| 145 | + |
| 146 | + sq_quote_argv_pretty("ed, argv->argv); |
| 147 | + entry->cmd = strbuf_detach("ed, 0); |
| 148 | + |
| 149 | + err = start_command(process); |
| 150 | + if (err) { |
| 151 | + error("cannot fork to run subprocess '%s'", entry->cmd); |
| 152 | + return err; |
| 153 | + } |
| 154 | + |
| 155 | + hashmap_entry_init(&entry->ent, strhash(entry->cmd)); |
| 156 | + |
| 157 | + err = startfn(entry); |
| 158 | + if (err) { |
| 159 | + error("initialization for subprocess '%s' failed", entry->cmd); |
| 160 | + subprocess_stop(hashmap, entry); |
| 161 | + return err; |
| 162 | + } |
| 163 | + |
| 164 | + hashmap_add(hashmap, &entry->ent); |
| 165 | + return 0; |
| 166 | +} |
| 167 | + |
121 | 168 | static int handshake_version(struct child_process *process,
|
122 | 169 | const char *welcome_prefix, int *versions,
|
123 | 170 | int *chosen_version)
|
|
0 commit comments