Commit d98e77e5 authored by Rusty Russell's avatar Rusty Russell

tools: fix compile after rbuf rewrite.

Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent d8a270fd
......@@ -46,7 +46,7 @@ config.h: $(CONFIGURATOR) Makefile
TOOLS := tools/ccan_depends tools/doc_extract tools/namespacize tools/modfiles
TOOLS_SRCS := $(filter-out $(TOOLS:%=%.c), $(wildcard tools/*.c))
TOOLS_DEPS := $(TOOLS_SRCS:%.c=%.d) $(TOOLS:%=%.d)
TOOLS_CCAN_MODULES := asort err foreach hash htable list noerr opt rbuf \
TOOLS_CCAN_MODULES := asort err foreach hash htable list membuf noerr opt rbuf \
read_write_all str take tal tal/grab_file tal/link tal/path tal/str time
TOOLS_CCAN_SRCS := $(wildcard $(TOOLS_CCAN_MODULES:%=ccan/%/*.c))
TOOLS_OBJS := $(TOOLS_SRCS:%.c=%.o) $(TOOLS_CCAN_SRCS:%.c=%.o)
......
......@@ -20,6 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...)
char *cmd;
FILE *p;
struct rbuf in;
char *str;
va_start(ap, format);
cmd = tal_vfmt(ctx, format, ap);
......@@ -30,12 +31,13 @@ lines_from_cmd(const void *ctx, const char *format, ...)
err(1, "Executing '%s'", cmd);
/* FIXME: Use rbuf_read_str(&in, '\n') rather than strsplit! */
rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0);
if (!rbuf_read_str(&in, 0, do_tal_realloc) && errno)
rbuf_init(&in, fileno(p), tal_arr(ctx, char, 0), 0, membuf_tal_realloc);
str = rbuf_read_str(&in, 0);
if (!str)
err(1, "Reading from '%s'", cmd);
pclose(p);
return tal_strsplit(ctx, in.buf, "\n", STR_EMPTY_OK);
return tal_strsplit(ctx, str, "\n", STR_EMPTY_OK);
}
/* Be careful about trying to compile over running programs (parallel make).
......
......@@ -40,6 +40,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
struct rbuf in;
int status, ms;
struct timeabs start;
const char *ret;
*ok = false;
if (pipe(p) != 0)
......@@ -82,9 +83,10 @@ 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, membuf_tal_realloc);
ret = rbuf_read_str(&in, '\0');
if (!ret)
tal_free(rbuf_cleanup(&in));
/* This shouldn't fail... */
if (waitpid(pid, &status, 0) != pid)
......@@ -97,14 +99,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 +269,7 @@ free:
return ret;
}
void *do_tal_realloc(void *p, size_t size)
void *membuf_tal_realloc(struct membuf *mb, void *p, size_t size)
{
tal_resize((char **)&p, size);
return p;
......
......@@ -67,7 +67,7 @@ const char *temp_dir(void);
void keep_temp_dir(void);
bool move_file(const char *oldname, const char *newname);
void *do_tal_realloc(void *p, size_t size);
void *membuf_tal_realloc(struct membuf *mb, void *p, size_t size);
/* Freed on exit: a good parent for auto cleanup. */
tal_t *autofree(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment