struct rbuf in;
int status, ms;
struct timeabs start;
+ char *ret;
*ok = false;
if (pipe(p) != 0)
}
close(p[1]);
- rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096);
- if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
- in.buf = tal_free(in.buf);
+ rbuf_init(&in, p[0], tal_arr(ctx, char, 4096), 4096, tal_rbuf_enlarge);
+ ret = rbuf_read_str(&in, 0);
/* This shouldn't fail... */
if (waitpid(pid, &status, 0) != pid)
*timeout_ms -= ms;
close(p[0]);
if (tools_verbose) {
- printf("%s", in.buf);
+ printf("%s", ret);
printf("Finished: %u ms, %s %u\n", ms,
WIFEXITED(status) ? "exit status" : "killed by signal",
WIFEXITED(status) ? WEXITSTATUS(status)
: WTERMSIG(status));
}
*ok = (WIFEXITED(status) && WEXITSTATUS(status) == 0);
- return in.buf;
+ return ret;
}
/* Tals *output off ctx; return false if command fails. */
return ret;
}
-void *do_tal_realloc(void *p, size_t size)
+void *tal_rbuf_enlarge(struct membuf *mb, void *p, size_t size)
{
tal_resize((char **)&p, size);
return p;