X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Ftools.c;h=4874fc62645fdff6aa372ecc6637227e6377865e;hb=fc339122d69a85e5238d8bd7069d24ed4be4aed4;hp=b78702d03a6d1ff26df2a1d412f3bb2965d40b67;hpb=daf9ee7d8e2b683ff05283beb1843611ad8c9e8a;p=ccan diff --git a/tools/tools.c b/tools/tools.c index b78702d0..4874fc62 100644 --- a/tools/tools.c +++ b/tools/tools.c @@ -40,6 +40,7 @@ char *run_with_timeout(const void *ctx, const char *cmd, struct rbuf in; int status, ms; struct timeabs start; + char *ret; *ok = false; if (pipe(p) != 0) @@ -82,9 +83,8 @@ char *run_with_timeout(const void *ctx, const char *cmd, } 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) @@ -97,14 +97,14 @@ char *run_with_timeout(const void *ctx, const char *cmd, *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. */ @@ -267,7 +267,7 @@ free: 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;