The new libpthread records the pthread_exit_process() exit handler with cxa_atexit() instead of on_exit() when possible. The glibc exit() does not include the exit code when calling this flavor of exit handler. As a side effect, a multithreaded program will always terminate with the exit code 0 if the thread that does exit() is not the main thread. Ludo. How to reproduce ----------------- $ cat test.c #include <stdio.h> #include <stdlib.h> #include <pthread.h> void* do_exit(void* dummy) { /* * Just call exit with code 2. */ printf("exit thread does exit\n"); exit(2); } main() { int ret; pthread_t th_exit; /* * Create a default pthread to handle the * process exit. */ ret = pthread_create(&th_exit, NULL, do_exit, NULL); if (ret != 0) { perror("pthread_create failed"); exit(1); } /* * Just loop indefinitely waiting for the * process to exit. */ printf("main thread loops\n"); while(1); /* * NEVER REACHED */ return 0; } $./test; echo $? 0 <- Should actually be 2
My patch for this was accepted into CVS glibc, it will also appear once next glibc rpms are cut.
Fixed in glibc-2.2.1-2 in rawhide.