From rfg@monkeys.com  Sat Nov 10 17:15:20 2001
Return-Path: <rfg@monkeys.com>
Received: from segfault.monkeys.com (246.dsl6660157.rstatic.surewest.net [66.60.157.246])
	by hub.freebsd.org (Postfix) with ESMTP id EE0F637B41C
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 10 Nov 2001 17:15:08 -0800 (PST)
Received: by segfault.monkeys.com (Postfix, from userid 1237)
	id 862796399; Sat, 10 Nov 2001 17:15:03 -0800 (PST)
Message-Id: <20011111011503.862796399@segfault.monkeys.com>
Date: Sat, 10 Nov 2001 17:15:03 -0800 (PST)
From: rfg@monkeys.com
Reply-To: rfg@monkeys.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: No method available to unwind atexit(3) stack without exiting
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         31906
>Category:       kern
>Synopsis:       [libc] No method available to unwind atexit(3) stack without exiting
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 10 17:20:00 PST 2001
>Closed-Date:    
>Last-Modified:  Mon Sep 29 03:22:25 UTC 2008
>Originator:     Ronald F. Guilmette
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
Infinite Monkeys & Co.
>Environment:
System: FreeBSD segfault.monkeys.com 4.3-RELEASE FreeBSD 4.3-RELEASE #0: Wed Aug 1 16:51:35 PDT 2001 root@:/usr/src/sys/compile/rfg20010801 i386


>Description:
	C programs are typically exited via a call to exit(3) however it
	it frequently useful to replace a running program image via a call
	to one of the exec*() family functions, rather than exiting the
	program via a call to exit(3).

	Unfortunately, when exiting a program via a call to one of the exec*
	functions, there is no obvious way to `unwind' the stack of program
	finalization actions that have been built up, during program execution,
	via successive calls to the atexit(3) function.  Likewise there is
	no easy way to insure that all open streams are properly flushed
	(as would happen if exit(3) were called) prior to a call to one of
	the exec* functions.

	Ideally, there should be some standard C library function available
	that could be called, prior to a call to one of the exec* functions,
	that would invoke the set of pending atexit(3) finalization actions,
	and that would also flush all open streams.  In effect, what I am
	requesting is a C library entry point that would invoke the following
	code, copied from the current exit(3) implementation:

        for (p = __atexit; p; p = p->next)
                for (n = p->ind; --n >= 0;)
                        (*p->fns[n])();
        if (__cleanup)
                (*__cleanup)();

>How-To-Repeat:
	This is a C library enhancement request.  There is nothing to repeat.

>Fix:
	Move the code shown above (from the exit(3) implementation) into its
	own function, make that function accessible via the standard C library
	interface, and make the implementation of exit(3) call the new function
	rather than having the code inline.
>Release-Note:
>Audit-Trail:
>Unformatted:
