Bug 23758 - exit in libpthread is broken.
exit in libpthread is broken.
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
7.0
All Linux
high Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Aaron Brown
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-01-10 21:33 EST by Need Real Name
Modified: 2016-11-24 10:19 EST (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-01-12 08:22:14 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2001-01-10 21:33:02 EST
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 08:22:10 EST
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 05:12:37 EST
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.