X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fccanlint%2Fasync.c;h=f3d1a5ba13b36354d23bdf309ae28d8c75617bd3;hp=680f947c357305aa945d7db765c215323aa47636;hb=d872b7f22bc98092cad2aa4a456973bdbdb2c8fb;hpb=b980b856670208893a4ac597c3b2e8dec47f453d diff --git a/tools/ccanlint/async.c b/tools/ccanlint/async.c index 680f947c..f3d1a5ba 100644 --- a/tools/ccanlint/async.c +++ b/tools/ccanlint/async.c @@ -6,15 +6,14 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include -#include static struct lbalance *lb; TLIST_TYPE(command, struct command); @@ -36,7 +35,7 @@ struct command { const void *ctx; }; -static void killme(int sig) +static void killme(int sig UNNEEDED) { kill(-getpid(), SIGKILL); } @@ -70,7 +69,7 @@ static void run_more(void) signal(SIGALRM, killme); itim.it_interval.tv_sec = itim.it_interval.tv_usec = 0; - itim.it_value = timespec_to_timeval(time_from_msec(c->time_ms)); + itim.it_value = timespec_to_timeval(time_from_msec(c->time_ms).ts); setitimer(ITIMER_REAL, &itim, NULL); c->status = system(c->command); @@ -92,7 +91,7 @@ static void run_more(void) } } -static int destroy_command(struct command *command) +static void destroy_command(struct command *command) { if (!command->done && command->pid) { kill(-command->pid, SIGKILL); @@ -101,7 +100,6 @@ static int destroy_command(struct command *command) } tlist_del(command, list); - return 0; } void run_command_async(const void *ctx, unsigned int time_ms, @@ -115,17 +113,18 @@ void run_command_async(const void *ctx, unsigned int time_ms, if (!lb) lb = lbalance_new(); - command = talloc(ctx, struct command); + command = tal(ctx, struct command); command->ctx = ctx; command->time_ms = time_ms; command->pid = 0; - command->output = talloc_strdup(command, ""); + /* We want to track length, so don't use tal_strdup */ + command->output = tal_arrz(command, char, 1); va_start(ap, fmt); - command->command = talloc_vasprintf(command, fmt, ap); + command->command = tal_vfmt(command, fmt, ap); va_end(ap); tlist_add_tail(&pending, command, list); command->done = false; - talloc_set_destructor(command, destroy_command); + tal_add_destructor(command, destroy_command); run_more(); } @@ -151,14 +150,12 @@ static void reap_output(void) 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); + old_len = tal_count(c->output); + tal_resize(&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); + tal_resize(&c->output, old_len + len); c->output[old_len + len - 1] = '\0'; if (len == 0) { struct rusage ru; @@ -198,8 +195,8 @@ void *collect_command(bool *ok, char **output) *ok = (WIFEXITED(c->status) && WEXITSTATUS(c->status) == 0); ctx = c->ctx; - *output = talloc_steal(ctx, c->output); - talloc_free(c); + *output = tal_steal(ctx, c->output); + tal_free(c); return (void *)ctx; }