Skip to content

Commit c5eadca

Browse files
peffgitster
authored andcommitted
trailer: use capture_command
When we read from a trailer.*.command sub-program, the current code uses run_command followed by a pipe read, which can result in deadlock (though in practice you would have to have a large trailer for this to be a problem). The current code also leaks the file descriptor for the pipe to the sub-command. Instead, let's use capture_command, which makes this simpler (and we can get rid of our custom helper). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d4974c commit c5eadca

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

trailer.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,6 @@ static struct trailer_item *remove_first(struct trailer_item **first)
214214
return item;
215215
}
216216

217-
static int read_from_command(struct child_process *cp, struct strbuf *buf)
218-
{
219-
if (run_command(cp))
220-
return error("running trailer command '%s' failed", cp->argv[0]);
221-
if (strbuf_read(buf, cp->out, 1024) < 1)
222-
return error("reading from trailer command '%s' failed", cp->argv[0]);
223-
strbuf_trim(buf);
224-
return 0;
225-
}
226-
227217
static const char *apply_command(const char *command, const char *arg)
228218
{
229219
struct strbuf cmd = STRBUF_INIT;
@@ -240,14 +230,16 @@ static const char *apply_command(const char *command, const char *arg)
240230
cp.argv = argv;
241231
cp.env = local_repo_env;
242232
cp.no_stdin = 1;
243-
cp.out = -1;
244233
cp.use_shell = 1;
245234

246-
if (read_from_command(&cp, &buf)) {
235+
if (capture_command(&cp, &buf, 1024)) {
236+
error("running trailer command '%s' failed", cmd.buf);
247237
strbuf_release(&buf);
248238
result = xstrdup("");
249-
} else
239+
} else {
240+
strbuf_trim(&buf);
250241
result = strbuf_detach(&buf, NULL);
242+
}
251243

252244
strbuf_release(&cmd);
253245
return result;

0 commit comments

Comments
 (0)