Browse Source

Handle the app_fini stuff in exit without requiring atexit().
This avoids pulling in all the malloc/free code for a simple true/false app.

Manuel Novoa III 21 years ago
parent
commit
e919981c95
2 changed files with 13 additions and 3 deletions
  1. 4 3
      libc/misc/internals/__uClibc_main.c
  2. 9 0
      libc/stdlib/atexit.c

+ 4 - 3
libc/misc/internals/__uClibc_main.c

@@ -101,6 +101,9 @@ void __uClibc_init(void)
 
 }
 
+#ifdef __UCLIBC_CTOR_DTOR__
+void (*__app_fini)(void) = NULL;
+#endif
 
 /* __uClibc_start_main is the new main stub for uClibc. This function is 
  * called from crt0 (version 0.9.16 or newer), after ALL shared libraries 
@@ -128,9 +131,7 @@ __uClibc_start_main(int argc, char **argv, char **envp,
 
 #ifdef __UCLIBC_CTOR_DTOR__
     /* Arrange for the application's dtors to run before we exit.  */
-    if (app_fini!=NULL) {
-	atexit(app_fini);
-    }
+	__app_fini = app_fini;
 
     /* Run all the application's ctors now.  */
     if (app_init!=NULL) {

+ 9 - 0
libc/stdlib/atexit.c

@@ -218,6 +218,10 @@ void (*__exit_cleanup) (int) = 0;
 pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 #endif
 
+#ifdef __UCLIBC_CTOR_DTOR__
+extern void (*__app_fini)(void);
+#endif
+
 /*
  * Normal program termination
  */
@@ -230,6 +234,11 @@ void exit(int rv)
 	}
 	UNLOCK;
 
+#ifdef __UCLIBC_CTOR_DTOR__
+	if (__app_fini != NULL)
+		(__app_fini)();
+#endif
+
     /* If we are using stdio, try to shut it down.  At the very least,
 	 * this will attempt to commit all buffered writes.  It may also
 	 * unbuffer all writable files, or close them outright.