diff src/noffle.c @ 281:5eece4dfd945 noffle

[svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors and exiting, Log_gdbm_fatal() for the the same but specifically as a GDBM error reporting function, and a new log debug level AUTH for a forthcoming authentication mechanism. * src/database.c,src/group.c: Provide new gdbm error function to all gdbm opens. * src/noffle.c: Add atexit() to always close databases on a program- inspired exit. * src/content.c,src/dynamicstring.c,src/fetchlist.c,src/filter.c, src/itemlist.c,src/log.c,src/log.h,src/over.c,src/protocol.h, src/request.c,src/util.c: Use Log_fatal where appropriate.
author bears
date Fri, 27 Dec 2002 21:48:25 +0000
parents d6fedc09b052
children c02c4eb95f95
line wrap: on
line diff
--- a/src/noffle.c	Tue Dec 24 09:08:59 2002 +0000
+++ b/src/noffle.c	Fri Dec 27 21:48:25 2002 +0000
@@ -10,7 +10,7 @@
   received for some seconds (to allow multiple clients connect at the same
   time).
 
-  $Id: noffle.c 402 2002-11-10 11:30:40Z bears $
+  $Id: noffle.c 413 2002-12-27 21:48:25Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -613,7 +613,7 @@
 static void
 closeNoffle( void )
 {
-    if ( noffle.lockAtStartup )
+    if ( Lock_gotLock() )
       Lock_closeDatabases();
     Lock_syncDatabases();
 }
@@ -730,7 +730,7 @@
 	f = fopen( argv[0], "r" );
 	if ( f == NULL )
 	{
-	    Log_err( "Can't access %s (%s).", argv[0], strerror( errno ) );
+	    fprintf( stderr, "Can't access %s (%s).", argv[0], strerror( errno ) );
 	    return EXIT_FAILURE;
 	}
     }
@@ -745,7 +745,6 @@
     if ( f != stdin )
 	fclose( f );
 
-    closeNoffle();
     return result;
 }
 
@@ -804,6 +803,9 @@
     int c, result;
     const char *cmdname, *p;
 
+    /* Attempt to ensure databases are properly closed when we exit */
+    atexit( closeNoffle );
+    
     signal( SIGSEGV, bugReport );
     signal( SIGABRT, logSignal );
     signal( SIGFPE, logSignal );
@@ -1011,6 +1013,5 @@
     default:
         abort(); /* Never reached */
     }
-    closeNoffle();
     return result;
 }