Bug 6982

Summary: atexit() hooks are not called on exec()
Product: glibc Reporter: Andrew Zabolotny <anpaza>
Component: libcAssignee: Ulrich Drepper <drepper.fsp>
Status: RESOLVED INVALID    
Severity: normal CC: glibc-bugs
Priority: P2 Flags: fweimer: security-
Version: 2.8   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:

Description Andrew Zabolotny 2008-10-24 18:46:15 UTC
"man 3 exit" says, amongst other:

...
The  exit()  function  causes  normal process termination and the value of
status & 0377 is returned to the parent (see wait(2)).

All functions registered with atexit(3) and on_exit(3) are called, in  the
reverse  order  of  their  registration.
...

However, the atexit() hooks are never called if you invoke any of the exec*()
functions.

Steps to Reproduce:
1. Copy the example from 'man 3 atexit' to test.c
2. Modify it so that instead of "exit(EXIT_SUCCESS)" at the end we have, for
example:

execl ("/bin/ls", "ls");

3. Compile and run the example

Actual results:

$ ./a.out 
ATEXIT_MAX = 2147483647
a.out  test.c

Expected results:

$ ./a.out 
ATEXIT_MAX = 2147483647
That was all, folks
a.out  test.c

I think it is a serious bug as it does not allow applications that rely on it
to cleanup things that won't automatically cleanup during a normal process
destruction.
Comment 1 Ulrich Drepper 2008-10-24 18:51:12 UTC
They are not meant to be called at exec time.  Just read the standards.
Comment 2 Andrew Zabolotny 2008-10-24 18:53:31 UTC
(In reply to comment #1)
> They are not meant to be called at exec time.  Just read the standards.
So it's a bug in the man page?