summaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-03-25 19:54:27 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-03-25 19:54:27 (GMT)
commitea1fd481b4e689f143142662a82fb62c9b2efb65 (patch)
treea9e2475bf714d67eafee037aa710023495cad21e /wt-status.c
parentd78374e578a1837ee73c45f944c420c6f3f64deb (diff)
parentc29b3962af3df80a43fab4ead4875bd2ca275e4c (diff)
downloadgit-ea1fd481b4e689f143142662a82fb62c9b2efb65.zip
git-ea1fd481b4e689f143142662a82fb62c9b2efb65.tar.gz
git-ea1fd481b4e689f143142662a82fb62c9b2efb65.tar.bz2
Merge branch 'jk/run-command-capture'
The run-command interface was easy to abuse and make a pipe for us to read from the process, wait for the process to finish and then attempt to read its output, which is a pattern that lead to a deadlock. Fix such uses by introducing a helper to do this correctly (i.e. we need to read first and then wait the process to finish) and also add code to prevent such abuse in the run-command helper. * jk/run-command-capture: run-command: forbid using run_command with piped output trailer: use capture_command submodule: use capture_command wt-status: use capture_command run-command: introduce capture_command helper wt_status: fix signedness mismatch in strbuf_read call wt-status: don't flush before running "submodule status"
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/wt-status.c b/wt-status.c
index 7036fa2..853419f 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -729,7 +729,6 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
struct strbuf cmd_stdout = STRBUF_INIT;
struct strbuf summary = STRBUF_INIT;
char *summary_content;
- size_t len;
argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s",
s->index_file);
@@ -745,15 +744,11 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
sm_summary.git_cmd = 1;
sm_summary.no_stdin = 1;
- fflush(s->fp);
- sm_summary.out = -1;
- run_command(&sm_summary);
-
- len = strbuf_read(&cmd_stdout, sm_summary.out, 1024);
+ capture_command(&sm_summary, &cmd_stdout, 1024);
/* prepend header, only if there's an actual output */
- if (len) {
+ if (cmd_stdout.len) {
if (uncommitted)
strbuf_addstr(&summary, _("Submodules changed but not updated:"));
else
@@ -764,6 +759,7 @@ static void wt_status_print_submodule_summary(struct wt_status *s, int uncommitt
strbuf_release(&cmd_stdout);
if (s->display_comment_prefix) {
+ size_t len;
summary_content = strbuf_detach(&summary, &len);
strbuf_add_commented_lines(&summary, summary_content, len);
free(summary_content);