Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 1 | /* Test handle_group_exit() handling of a thread leader still alive with its |
| 2 | * thread child calling exit_group() and proper passing of the process exit |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 3 | * code to the process parent of this whole thread group. |
Dmitry V. Levin | 414fe7d | 2009-07-08 11:21:17 +0000 | [diff] [blame] | 4 | * |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 5 | * gcc -o test/leaderkill test/leaderkill.c -Wall -ggdb2 -pthread;./test/leaderkill & pid=$!;sleep 1;strace -o x -q ./strace -f -p $pid |
| 6 | * It must print: write(1, "OK\n", ... |
| 7 | */ |
| 8 | |
| 9 | #include <pthread.h> |
| 10 | #include <assert.h> |
| 11 | #include <unistd.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> |
| 14 | #include <sys/wait.h> |
| 15 | |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 16 | static void *start0(void *arg) |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 17 | { |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 18 | sleep(1); |
| 19 | exit(42); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 22 | static void *start1(void *arg) |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 23 | { |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 24 | pause(); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 25 | /* NOTREACHED */ |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 26 | assert(0); |
| 27 | } |
| 28 | |
| 29 | int main(int argc, char *argv[]) |
| 30 | { |
| 31 | pthread_t thread0; |
| 32 | pthread_t thread1; |
| 33 | pid_t child, got_pid; |
| 34 | int status; |
| 35 | int i; |
| 36 | |
| 37 | sleep(2); |
| 38 | |
| 39 | child = fork(); |
| 40 | |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 41 | switch (child) { |
Denys Vlasenko | 8ed5727 | 2009-02-25 14:24:02 +0000 | [diff] [blame] | 42 | case -1: |
| 43 | abort(); |
| 44 | case 0: |
| 45 | i = pthread_create(&thread0, NULL, start0, NULL); |
| 46 | assert(i == 0); |
| 47 | i = pthread_create(&thread1, NULL, start1, NULL); |
| 48 | assert(i == 0); |
| 49 | pause(); |
| 50 | /* NOTREACHED */ |
| 51 | assert(0); |
| 52 | break; |
| 53 | default: |
| 54 | got_pid = waitpid(child, &status, 0); |
| 55 | assert(got_pid == child); |
| 56 | assert(WIFEXITED(status)); |
| 57 | assert(WEXITSTATUS(status) == 42); |
| 58 | puts("OK"); |
| 59 | exit(0); |
| 60 | } |
| 61 | |
| 62 | /* NOTREACHED */ |
| 63 | abort(); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 64 | } |