]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/async.c
tal: add del_destructor().
[ccan] / tools / ccanlint / async.c
index 9c7a442ee64fabcbd8a3a581a3f79e85ebbac725..680f947c357305aa945d7db765c215323aa47636 100644 (file)
@@ -47,10 +47,12 @@ static void run_more(void)
 
        while (num_running < lbalance_target(lb)) {
                int p[2];
-               c = tlist_top(&pending, struct command, list);
+
+               c = tlist_top(&pending, list);
                if (!c)
                        break;
 
+               fflush(stdout);
                if (pipe(p) != 0)
                        err(1, "Pipe failed");
                c->pid = fork();
@@ -68,7 +70,7 @@ static void run_more(void)
 
                        signal(SIGALRM, killme);
                        itim.it_interval.tv_sec = itim.it_interval.tv_usec = 0;
-                       itim.it_value = time_from_msec(c->time_ms);
+                       itim.it_value = timespec_to_timeval(time_from_msec(c->time_ms));
                        setitimer(ITIMER_REAL, &itim, NULL);
 
                        c->status = system(c->command);
@@ -148,14 +150,16 @@ static void reap_output(void)
        tlist_for_each_safe(&running, c, next, list) {
                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);
-                       len = read(c->output_fd, 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);
+                       c->output[old_len + len - 1] = '\0';
                        if (len == 0) {
                                struct rusage ru;
                                wait4(c->pid, &c->status, 0, &ru);
@@ -185,7 +189,7 @@ void *collect_command(bool *ok, char **output)
        struct command *c;
        const void *ctx;
 
-       while ((c = tlist_top(&done, struct command, list)) == NULL) {
+       while ((c = tlist_top(&done, list)) == NULL) {
                if (tlist_empty(&pending) && tlist_empty(&running))
                        return NULL;
                reap_output();