diff options
-rw-r--r-- | tests/gpgscm/ffi.scm | 18 | ||||
-rw-r--r-- | tests/gpgscm/main.c | 1 |
2 files changed, 19 insertions, 0 deletions
diff --git a/tests/gpgscm/ffi.scm b/tests/gpgscm/ffi.scm index 72a2a8f1e..fb1853857 100644 --- a/tests/gpgscm/ffi.scm +++ b/tests/gpgscm/ffi.scm @@ -57,6 +57,7 @@ ((more-handlers?) (apply (pop-handler) x)) ((and (= 2 (length x)) (equal? *interpreter-exit* (car x))) + (*run-atexit-handlers*) (_exit (cadr x))) (else (apply error x)))) @@ -64,3 +65,20 @@ ;; Terminate the process returning STATUS to the parent. (define (exit status) (throw *interpreter-exit* status)) + +;; A list of functions run at interpreter shutdown. +(define *atexit-handlers* (list)) + +;; Execute all these functions. +(define (*run-atexit-handlers*) + (unless (null? *atexit-handlers*) + (let ((proc (car *atexit-handlers*))) + ;; Drop proc from the list so that it will not get + ;; executed again even if it raises an exception. + (set! *atexit-handlers* (cdr *atexit-handlers*)) + (proc) + (*run-atexit-handlers*)))) + +;; Register a function to be run at interpreter shutdown. +(define (atexit proc) + (set! *atexit-handlers* (cons proc *atexit-handlers*))) diff --git a/tests/gpgscm/main.c b/tests/gpgscm/main.c index f7c6b0d14..70ce85592 100644 --- a/tests/gpgscm/main.c +++ b/tests/gpgscm/main.c @@ -291,6 +291,7 @@ main (int argc, char **argv) log_fatal ("%s: %s", script, gpg_strerror (err)); } + scheme_load_string (sc, "(*run-atexit-handlers*)"); scheme_deinit (sc); xfree (sc); return EXIT_SUCCESS; |