]> git.ozlabs.org Git - ccan/commitdiff
failtest: fix fascist warn_unused_result warnings
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 28 Mar 2011 04:14:40 +0000 (14:44 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 28 Mar 2011 04:14:40 +0000 (14:44 +1030)
ccan/failtest/failtest.c
ccan/failtest/test/run-open.c
ccan/failtest/test/run-write.c

index b25b049edac1d162c663ae58218c75dc3815e0dd..30903e3f3c4ecf232d474e2d09bc82f5238e777c 100644 (file)
@@ -248,7 +248,8 @@ static struct saved_file *save_file(struct saved_file *next, int fd)
        s->len = lseek(fd, 0, SEEK_END);
        lseek(fd, 0, SEEK_SET);
        s->contents = malloc(s->len);
        s->len = lseek(fd, 0, SEEK_END);
        lseek(fd, 0, SEEK_SET);
        s->contents = malloc(s->len);
-       read(fd, s->contents, s->len);
+       if (read(fd, s->contents, s->len) != s->len)
+               err(1, "Failed to save %zu bytes", (size_t)s->len);
        lseek(fd, s->off, SEEK_SET);
        return s;
 }
        lseek(fd, s->off, SEEK_SET);
        return s;
 }
@@ -293,8 +294,11 @@ static void restore_files(struct saved_file *s)
                struct saved_file *next = s->next;
 
                lseek(s->fd, 0, SEEK_SET);
                struct saved_file *next = s->next;
 
                lseek(s->fd, 0, SEEK_SET);
-               write(s->fd, s->contents, s->len);
-               ftruncate(s->fd, s->len);
+               if (write(s->fd, s->contents, s->len) != s->len)
+                       err(1, "Failed to restore %zu bytes", (size_t)s->len);
+               if (ftruncate(s->fd, s->len) != 0)
+                       err(1, "Failed to trim file to length %zu",
+                           (size_t)s->len);
                free(s->contents);
                lseek(s->fd, s->off, SEEK_SET);
                free(s);
                free(s->contents);
                lseek(s->fd, s->off, SEEK_SET);
                free(s);
@@ -395,8 +399,8 @@ static bool should_fail(struct failtest_call *call)
                        signal(SIGUSR1, SIG_IGN);
                        sprintf(str, "xterm -e gdb /proc/%d/exe %d &",
                                getpid(), getpid());
                        signal(SIGUSR1, SIG_IGN);
                        sprintf(str, "xterm -e gdb /proc/%d/exe %d &",
                                getpid(), getpid());
-                       system(str);
-                       sleep(5);
+                       if (system(str) == 0)
+                               sleep(5);
                }
        }
 
                }
        }
 
index a81fa259334c70298c0c2ac0ed320e23d556ca72..e055045739d619db301f3cf98cddcb24b0def734 100644 (file)
@@ -15,13 +15,15 @@ int main(void)
 
        plan_tests(12);
 
 
        plan_tests(12);
 
-       pipe(pfd);
+       if (pipe(pfd))
+               abort();
        fd = failtest_open("run-open-scratchpad", "run-open.c", 1,
                           O_RDWR|O_CREAT, 0600);
        if (fd == -1) {
                /* We are the child: write error code for parent to check. */
                err = errno;
        fd = failtest_open("run-open-scratchpad", "run-open.c", 1,
                           O_RDWR|O_CREAT, 0600);
        if (fd == -1) {
                /* We are the child: write error code for parent to check. */
                err = errno;
-               write(pfd[1], &err, sizeof(err));
+               if (write(pfd[1], &err, sizeof(err)) != sizeof(err))
+                       abort();
                failtest_exit(0);
        }
        /* Check it is read-write. */
                failtest_exit(0);
        }
        /* Check it is read-write. */
@@ -46,12 +48,14 @@ int main(void)
        close(pfd[1]);
 
        /* Two-arg open. */
        close(pfd[1]);
 
        /* Two-arg open. */
-       pipe(pfd);
+       if (pipe(pfd) != 0)
+               abort();
        fd = failtest_open("run-open-scratchpad", "run-open.c", 1, O_RDONLY);
        if (fd == -1) {
                /* We are the child: write error code for parent to check. */
                err = errno;
        fd = failtest_open("run-open-scratchpad", "run-open.c", 1, O_RDONLY);
        if (fd == -1) {
                /* We are the child: write error code for parent to check. */
                err = errno;
-               write(pfd[1], &err, sizeof(err));
+               if (write(pfd[1], &err, sizeof(err)) != sizeof(err))
+                       abort();
                failtest_exit(0);
        }
        /* Check it is read-only. */
                failtest_exit(0);
        }
        /* Check it is read-only. */
index 9f1f1d7fc8005fdda59cbe46684157329f2469be..ada185a643004ba961ce3698026a822824ad9e84 100644 (file)
@@ -21,7 +21,8 @@ int main(int argc, char *argv[])
        /* Child will fail, ignore. */
        if (fd < 0)
                failtest_exit(0);
        /* Child will fail, ignore. */
        if (fd < 0)
                failtest_exit(0);
-       write(fd, buf, strlen(buf));
+       if (write(fd, buf, strlen(buf)) != strlen(buf))
+               abort();
        ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
 
        p = failtest_malloc(100, __FILE__, __LINE__);
        ok1(lseek(fd, 0, SEEK_CUR) == strlen(buf));
 
        p = failtest_malloc(100, __FILE__, __LINE__);