mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpgscm: Implement 'atexit'.
* tests/gpgscm/ffi.scm (throw): Run *run-atexit-handlers* when terminating the interpreter. (*atexit-handlers*): New variable. (*run-atexit-handlers*): New function. (atexit): Likewise. * tests/gpgscm/main.c (main): Run *run-atexit-handlers* at normal interpreter shutdown. Signed-off-by: Justus Winter <justus@g10code.com>
This commit is contained in:
parent
cd00b07ec2
commit
43f8006f5c
@ -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*)))
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user