@@ -279,10 +279,32 @@ "-q" ;; quiet 0, errors/warnings only ) args:arg-hash 0)) +(define (std-exit-procedure) + (rmt:print-db-stats) + (let ((run-ids (hash-table-keys *db-local-sync*))) + (if (not (null? run-ids)) + (db:multi-db-sync run-ids 'new2old))) + (if *dbstruct-db* (db:close-all *dbstruct-db*)) + (if *megatest-db* (begin + (sqlite3:interrupt! *megatest-db*) + (sqlite3:finalize! *megatest-db* #t))) + (if *task-db* (let ((db (vector-ref *task-db* 0))) + (sqlite3:interrupt! db) + (sqlite3:finalize! db #t)))) + +(define (std-signal-handler signum) + (signal-mask! signum) + (debug:print 0 "ERROR: Received signal " signum " exiting promptly") + (std-exit-procedure) + (exit)) + +(set-signal-handler! signal/int std-signal-handler) +(set-signal-handler! signal/term std-signal-handler) + (if (args:get-arg "-log") (let ((oup (open-output-file (args:get-arg "-log")))) (debug:print-info 0 "Sending log output to " (args:get-arg "-log")) (current-error-port oup) (current-output-port oup))) @@ -347,18 +369,11 @@ (let ((newval (conc (args:get-arg "-testpatt") "/" (args:get-arg "-itempatt")))) (debug:print 0 "WARNING: -itempatt has been deprecated, please use -testpatt testpatt/itempatt method, new testpatt is "newval) (hash-table-set! args:arg-hash "-testpatt" newval) (hash-table-delete! args:arg-hash "-itempatt"))) -(on-exit (lambda () - (rmt:print-db-stats) - (let ((run-ids (hash-table-keys *db-local-sync*))) - (if (not (null? run-ids)) - (db:multi-db-sync run-ids 'new2old))) - (if *dbstruct-db* (db:close-all *dbstruct-db*)) - (if *megatest-db* (sqlite3:finalize! *megatest-db*)) - (if *task-db* (sqlite3:finalize! (vector-ref *task-db* 0))))) +(on-exit std-exit-procedure) ;;====================================================================== ;; Misc general calls ;;======================================================================