main.c
changeset 13 23a242d7b7fa
parent 10 d07309450285
child 14 51eb85ae4de4
equal deleted inserted replaced
12:191b3c25974a 13:23a242d7b7fa
    45 	 * default to display everything */
    45 	 * default to display everything */
    46 	v.debugmode = 99;
    46 	v.debugmode = 99;
    47 #else
    47 #else
    48 	v.debugmode = 0;
    48 	v.debugmode = 0;
    49 #endif
    49 #endif
       
    50 
       
    51 	(void)signal( SIGINT, shutdown_handler );
    50 
    52 
    51 	/* default database file name */
    53 	/* default database file name */
    52 	v.db = NULL;
    54 	v.db = NULL;
    53 	strcpy( v.dbname, "volta.db" );
    55 	strcpy( v.dbname, "volta.db" );
    54 
    56 
   112 
   114 
   113 	/* get the initial database handle or bomb immediately. */
   115 	/* get the initial database handle or bomb immediately. */
   114 	if ( db_attach() != SQLITE_OK ) exit( 1 );
   116 	if ( db_attach() != SQLITE_OK ) exit( 1 );
   115 
   117 
   116 	/* enter stdin parsing loop */
   118 	/* enter stdin parsing loop */
   117 	return( accept_loop() );
   119 	unsigned char exitval = accept_loop();
       
   120 	shutdown_actions();
       
   121 	return( exitval );
   118 }
   122 }
   119 
   123 
       
   124 
       
   125 /*
       
   126  * Perform actions in preparation for a graceful shutdown.
       
   127  *
       
   128  */
       
   129 void
       
   130 shutdown_actions( void )
       
   131 {
       
   132 	sqlite3_finalize( v.db_stmt.match_request );
       
   133 	sqlite3_finalize( v.db_stmt.get_rewrite_rule );
       
   134 	sqlite3_close( v.db );
       
   135 	report_speed();
       
   136 }
       
   137 
       
   138 
       
   139 /*
       
   140  * Signal handler for shutting things down.
       
   141  *
       
   142  */
       
   143 void
       
   144 shutdown_handler( int sig )
       
   145 {
       
   146 	debug( 1, LOC, "Exiting via signal %d.\n", sig );
       
   147 	shutdown_actions();
       
   148 	exit( 0 );
       
   149 }
       
   150