Bug 23758

Summary: exit in libpthread is broken.
Product: [Retired] Red Hat Linux Reporter: Need Real Name <ludovic.fernandez>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED RAWHIDE QA Contact: Aaron Brown <abrown>
Severity: high Docs Contact:
Priority: high    
Version: 7.0CC: fweimer, ludovic.fernandez
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2001-01-12 13:22:14 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Need Real Name 2001-01-11 02:33:02 UTC
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

Comment 1 Jakub Jelinek 2001-01-12 13:22:10 UTC
My patch for this was accepted into CVS glibc, it will also appear once next
glibc rpms are cut.

Comment 2 Jakub Jelinek 2001-01-23 10:12:37 UTC
Fixed in glibc-2.2.1-2 in rawhide.