Fix run-read_all and fix hang if they should fail.
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 14 Nov 2008 07:13:09 +0000 (17:43 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 14 Nov 2008 07:13:09 +0000 (17:43 +1030)
ccan/read_write_all/test/run-read_all.c
ccan/read_write_all/test/run-write_all.c

index 2790b64d5ce5c59ea57f5029cc7b6453a7f45a7a..5fa0ec392920d119af1b2d963238cf4b188ea109 100644 (file)
@@ -39,6 +39,8 @@ int main(int argc, char *argv[])
        child = fork();
 
        if (!child) {
        child = fork();
 
        if (!child) {
+               close(p2c[1]);
+               close(c2p[0]);
                /* Child.  Make sure parent ready, then write in two parts. */
                if (read(p2c[0], &c, 1) != 1)
                        exit(1);
                /* Child.  Make sure parent ready, then write in two parts. */
                if (read(p2c[0], &c, 1) != 1)
                        exit(1);
@@ -50,13 +52,15 @@ int main(int argc, char *argv[])
                /* Make sure they get signal. */
                if (read(p2c[0], &c, 1) != 1)
                        exit(4);
                /* Make sure they get signal. */
                if (read(p2c[0], &c, 1) != 1)
                        exit(4);
-               if (write(c2p[1], buffer, PIPE_BUF) != PIPE_BUF)
+               if (write(c2p[1], buffer, BUFSZ) != BUFSZ)
                        exit(5);
                exit(0);
        }
        if (child == -1)
                err(1, "forking");
 
                        exit(5);
                exit(0);
        }
        if (child == -1)
                err(1, "forking");
 
+       close(p2c[0]);
+       close(c2p[1]);
        signal(SIGUSR1, got_signal);
        ok1(write(p2c[1], &c, 1) == 1);
        ok1(read_all(c2p[0], buffer, sizeof(buffer)));
        signal(SIGUSR1, got_signal);
        ok1(write(p2c[1], &c, 1) == 1);
        ok1(read_all(c2p[0], buffer, sizeof(buffer)));
index fbfa1f99aebcbca18b37fe580fa05b3a388ff432..379ff9232fbcb669ce382d0578b14e9ce9adfff8 100644 (file)
@@ -37,6 +37,7 @@ int main(int argc, char *argv[])
        child = fork();
 
        if (!child) {
        child = fork();
 
        if (!child) {
+               close(p2c[1]);
                /* Make sure they started writing. */
                if (read(p2c[0], buffer, 1) != 1)
                        exit(1);
                /* Make sure they started writing. */
                if (read(p2c[0], buffer, 1) != 1)
                        exit(1);
@@ -54,6 +55,7 @@ int main(int argc, char *argv[])
        if (child == -1)
                err(1, "forking");
 
        if (child == -1)
                err(1, "forking");
 
+       close(p2c[0]);
        memset(buffer, 0xff, sizeof(buffer));
        signal(SIGUSR1, got_signal);
        ok1(write_all(p2c[1], buffer, sizeof(buffer)));
        memset(buffer, 0xff, sizeof(buffer));
        signal(SIGUSR1, got_signal);
        ok1(write_all(p2c[1], buffer, sizeof(buffer)));