Bug 23758 - exit in libpthread is broken.
Summary: exit in libpthread is broken.
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 7.0
Hardware: All
OS: Linux
high
high
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Aaron Brown
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-01-11 02:33 UTC by Need Real Name
Modified: 2016-11-24 15:19 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-01-12 13:22:14 UTC
Embargoed:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.