Bug 468440 - atexit() hooks are not called on exec()
Summary: atexit() hooks are not called on exec()
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: man-pages
Version: 9
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Ivana Varekova
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2008-10-24 18:36 UTC by Andrew Zabolotny
Modified: 2008-10-30 12:35 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2008-10-30 08:50:26 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Sourceware 6982 0 None None None Never

Description Andrew Zabolotny 2008-10-24 18:36:26 UTC
Description of problem:

"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.

Version-Release number of selected component (if applicable):
glibc-2.8-8.x86_64

How reproducible:
Always

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

Additional info:
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 Andrew Zabolotny 2008-10-24 18:52:36 UTC
I tried on a micro linux-from-scratch variant I have running here in a virtual machine, and the bug is still there, so it's really a upstream bug.

I have copied the report to the bugzilla recommended on glibc homepage, and added a link to that bugzilla.

Comment 2 Andrew Zabolotny 2008-10-24 19:09:37 UTC
I was told by Ulrich Drepper that this is behaviour is conformant to standards.

I found in the "The Open Group Base Specifications issue 6" the page related to exec() here:

http://www.opengroup.org/onlinepubs/000095399/functions/exec.html

The only quote mentioning atexit is:

<<After a successful call to any of the exec functions, any functions previously registered by atexit() or pthread_atfork() are no longer registered.>>

This is somehow vague, but anyway I think this can be re-classified as a bug in the man page. FreeBSD and Solaris man pages just repeat the same quote from standard.

Changing target package to man-pages-2.78-2.fc9.noarch.

Comment 3 Ivana Varekova 2008-10-30 08:50:26 UTC
The description details from which results the fact - the atexit stuff is not called before the execl call starts - are on execve page (there is link from execl page): 

"All process attributes are preserved during an execve(), except the following:
..
*  Exit handlers are not preserved (atexit(3), on_exit(3)).
..
"

It seems for me to be sufficient info so I think there is no need to add another notice about it.

Comment 4 Andrew Zabolotny 2008-10-30 12:35:28 UTC
Indeed, there's a note on execve() page.

I do not insist, but I think it would be helpful to note this on exec page as well. And even emphasize that the handlers are not called, not just "not preserved". Maybe I don't understand it well, but "handlers are not preserved" and "handlers are not called and not preserved" sound a bit different to me.

Anyway, this bug can be closed I think.


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