]> git.ozlabs.org Git - ccan/commitdiff
tools: fix compile after rbuf rewrite.
authorRusty Russell <rusty@rustcorp.com.au>
Wed, 26 Sep 2018 23:57:40 +0000 (09:27 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Wed, 26 Sep 2018 23:57:40 +0000 (09:27 +0930)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Makefile
tools/depends.c
tools/tools.c
tools/tools.h

index c507b746651c57243f7fa0834d6c132bef5415cb..d53e89f4d1ca9556e64187e4d3a1a63272b64c74 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -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 := 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)
     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)
index 36b58092cabc10e924e42cb1669e279ccab2beb7..bf4015bf3c4c0f50ee0cc5b784517fbf02905e6d 100644 (file)
@@ -20,6 +20,7 @@ lines_from_cmd(const void *ctx, const char *format, ...)
        char *cmd;
        FILE *p;
        struct rbuf in;
        char *cmd;
        FILE *p;
        struct rbuf in;
+       char *str;
 
        va_start(ap, format);
        cmd = tal_vfmt(ctx, format, ap);
 
        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! */
                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);
 
                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).
 }
 
 /* Be careful about trying to compile over running programs (parallel make).
index b78702d03a6d1ff26df2a1d412f3bb2965d40b67..2af158f8afb4d751ae5b45c78aa9e5c228ff6fc6 100644 (file)
@@ -40,6 +40,7 @@ char *run_with_timeout(const void *ctx, const char *cmd,
        struct rbuf in;
        int status, ms;
        struct timeabs start;
        struct rbuf in;
        int status, ms;
        struct timeabs start;
+       const char *ret;
 
        *ok = false;
        if (pipe(p) != 0)
 
        *ok = false;
        if (pipe(p) != 0)
@@ -82,9 +83,10 @@ char *run_with_timeout(const void *ctx, const char *cmd,
        }
 
        close(p[1]);
        }
 
        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)
 
        /* 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) {
                *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);
                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. */
 }
 
 /* Tals *output off ctx; return false if command fails. */
@@ -267,7 +269,7 @@ free:
        return ret;
 }
 
        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;
 {
        tal_resize((char **)&p, size);
        return p;
index 257a14ae18b1857bb9a2e29764302ce147d6b647..e4bc8998613fd2748b71d805ad0d0857645e4d66 100644 (file)
@@ -67,7 +67,7 @@ const char *temp_dir(void);
 void keep_temp_dir(void);
 bool move_file(const char *oldname, const char *newname);
 
 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);
 
 /* Freed on exit: a good parent for auto cleanup. */
 tal_t *autofree(void);