shell: Use job_write_cb for closing stdin

Commit @45525853d352 removed usage of the `job_write_cb` for closing stdin due
to a memory error, but that doesn't work anymore because `job_close_in` closes
stdin immediately, possibly trimming input data before it is fully written.

Since most memory issues with jobs have been fixed, re-add the `job_write_cb`
call to ensure stdin is only closed when it should. Also add tests for scenarios
where using the callback makes a difference.
This commit is contained in:
Thiago de Arruda
2014-11-10 09:19:27 -03:00
parent ab826d88f6
commit 3e8ef31ada
2 changed files with 37 additions and 2 deletions

View File

@@ -244,6 +244,9 @@ static int shell(const char *cmd,
job_stop(job);
return -1;
}
// close the input stream after everything is written
job_write_cb(job, shell_write_cb);
} else {
// close the input stream, let the process know that no more input is
// coming
job_close_in(job);
@@ -447,3 +450,9 @@ static void write_output(char *output, size_t remaining)
curbuf->b_no_eol_lnum = 0;
}
}
static void shell_write_cb(WStream *wstream, void *data, int status)
{
Job *job = data;
job_close_in(job);
}