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"
This commit is contained in:
10
wt-status.c
10
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);
|
||||
|
Reference in New Issue
Block a user