Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 1 | /* This test is not yet added to Makefile */ |
| 2 | |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 3 | #include <stdlib.h> |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 4 | #include <stddef.h> |
| 5 | #include <unistd.h> |
| 6 | #include <signal.h> |
| 7 | |
| 8 | #include <sys/types.h> |
| 9 | #include <sys/socket.h> |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 10 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 11 | static const struct sockaddr sa; |
| 12 | |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 13 | int main(int argc, char *argv[]) |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 14 | { |
| 15 | int loops; |
| 16 | int pid; |
| 17 | sigset_t set; |
| 18 | |
| 19 | sigemptyset(&set); |
| 20 | sigaddset(&set, SIGCHLD); |
| 21 | sigprocmask(SIG_BLOCK, &set, NULL); |
| 22 | |
| 23 | loops = 999; |
| 24 | if (argv[1]) |
| 25 | loops = atoi(argv[1]); |
| 26 | |
| 27 | while (--loops >= 0) { |
| 28 | pid = fork(); |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 29 | |
| 30 | if (pid < 0) |
| 31 | exit(1); |
| 32 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 33 | if (!pid) { |
| 34 | /* child */ |
| 35 | int child = getpid(); |
| 36 | |
| 37 | loops = 99; |
| 38 | while (--loops) { |
| 39 | pid = fork(); |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 40 | |
| 41 | if (pid < 0) |
| 42 | exit(1); |
| 43 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 44 | if (!pid) { |
| 45 | /* grandchild: kill child */ |
| 46 | kill(child, SIGKILL); |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 47 | exit(0); |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 48 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 49 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 50 | /* Add various syscalls you want to test here. |
| 51 | * strace will decode them and suddenly find |
| 52 | * process disappearing. |
| 53 | * But leave at least one case "empty", so that |
| 54 | * "kill grandchild" happens quicker. |
| 55 | * This produces cases when strace can't even |
| 56 | * decode syscall number before process dies. |
| 57 | */ |
| 58 | switch (loops & 1) { |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 59 | case 0: |
| 60 | break; /* intentional empty */ |
| 61 | case 1: |
| 62 | sendto(-1, "Hello cruel world", 17, 0, &sa, sizeof(sa)); |
| 63 | break; |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 64 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 65 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 66 | /* kill grandchild */ |
| 67 | kill(pid, SIGKILL); |
| 68 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 69 | |
| 70 | exit(0); |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 71 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 72 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 73 | /* parent */ |
| 74 | wait(NULL); |
| 75 | } |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame^] | 76 | |
Denys Vlasenko | 26de70e | 2009-02-13 10:26:31 +0000 | [diff] [blame] | 77 | return 0; |
| 78 | } |