// Wraps the call to std{out,err}_cb and emits a JobExit event if necessary. static void read_cb(RStream *rstream, void *data, bool eof) { Job *job = data; if (rstream == job->out) { job->opts.stdout_cb(rstream, data, eof); if (eof) { close_job_out(job); } } else { job->opts.stderr_cb(rstream, data, eof); if (eof) { close_job_err(job); } } }
static void close_cb(uv_handle_t *handle) { Job *job = handle_get_job(handle); if (handle == (uv_handle_t *)&job->proc) { // Make sure all streams are properly closed to trigger callback invocation // when job->proc is closed close_job_in(job); close_job_out(job); close_job_err(job); } if (--job->refcount == 0) { // Invoke the exit_cb job_exit_callback(job); // Free all memory allocated for the job free(job->proc.data); free(job->proc_stdin.data); free(job->proc_stdout.data); free(job->proc_stderr.data); shell_free_argv(job->proc_opts.args); free(job); } }
void job_close_streams(Job *job) { close_job_in(job); close_job_out(job); close_job_err(job); }