| Line | |
|---|
| 1 | /* 12.t |
|---|
| 2 | - ioctx access across fork() (12.t) |
|---|
| 3 | */ |
|---|
| 4 | #include <sys/types.h> |
|---|
| 5 | #include <sys/wait.h> |
|---|
| 6 | #include <unistd.h> |
|---|
| 7 | #include <signal.h> |
|---|
| 8 | |
|---|
| 9 | #include "aio_setup.h" |
|---|
| 10 | |
|---|
| 11 | void test_child(void) |
|---|
| 12 | { |
|---|
| 13 | int res; |
|---|
| 14 | res = attempt_io_submit(io_ctx, 0, NULL, -EINVAL); |
|---|
| 15 | fflush(stdout); |
|---|
| 16 | _exit(res); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | int test_main(void) |
|---|
| 20 | { |
|---|
| 21 | int res, status; |
|---|
| 22 | pid_t pid; |
|---|
| 23 | |
|---|
| 24 | if (attempt_io_submit(io_ctx, 0, NULL, 0)) |
|---|
| 25 | return 1; |
|---|
| 26 | |
|---|
| 27 | sigblock(sigmask(SIGCHLD) | siggetmask()); |
|---|
| 28 | fflush(NULL); |
|---|
| 29 | pid = fork(); assert(pid != -1); |
|---|
| 30 | |
|---|
| 31 | if (pid == 0) |
|---|
| 32 | test_child(); |
|---|
| 33 | |
|---|
| 34 | res = waitpid(pid, &status, 0); |
|---|
| 35 | |
|---|
| 36 | if (WIFEXITED(status)) { |
|---|
| 37 | int failed = (WEXITSTATUS(status) != 0); |
|---|
| 38 | printf("child exited with status %d%s\n", WEXITSTATUS(status), |
|---|
| 39 | failed ? " -- FAILED" : ""); |
|---|
| 40 | return failed; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | /* anything else: failed */ |
|---|
| 44 | if (WIFSIGNALED(status)) |
|---|
| 45 | printf("child killed by signal %d -- FAILED.\n", |
|---|
| 46 | WTERMSIG(status)); |
|---|
| 47 | |
|---|
| 48 | return 1; |
|---|
| 49 | } |
|---|
Note: See
TracBrowser
for help on using the repository browser.