X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fasync.c;h=e12e140daae9b0a4d5cccd0ae08b076fb782f5c4;hp=9c7a442ee64fabcbd8a3a581a3f79e85ebbac725;hb=163daaf4813b2061b106b9b0077202724e3dca04;hpb=4640e61b45d8d3cdfc5301bc58ef7c96a42077ec diff --git a/tools/ccanlint/async.c b/tools/ccanlint/async.c index 9c7a442e..e12e140d 100644 --- a/tools/ccanlint/async.c +++ b/tools/ccanlint/async.c @@ -47,10 +47,12 @@ static void run_more(void) while (num_running < lbalance_target(lb)) { int p[2]; + c = tlist_top(&pending, struct command, list); if (!c) break; + fflush(stdout); if (pipe(p) != 0) err(1, "Pipe failed"); c->pid = fork(); @@ -148,14 +150,16 @@ static void reap_output(void) tlist_for_each_safe(&running, c, next, list) { if (FD_ISSET(c->output_fd, &in)) { int old_len, len; + /* This length includes nul terminator! */ old_len = talloc_array_length(c->output); c->output = talloc_realloc(c, c->output, char, old_len + 1024); - len = read(c->output_fd, c->output + old_len, 1024); + len = read(c->output_fd, c->output + old_len - 1, 1024); if (len < 0) err(1, "Reading from async command"); c->output = talloc_realloc(c, c->output, char, old_len + len); + c->output[old_len + len - 1] = '\0'; if (len == 0) { struct rusage ru; wait4(c->pid, &c->status, 0, &ru);