diff options
author | Teddy Wing | 2022-05-21 18:48:09 +0200 |
---|---|---|
committer | Teddy Wing | 2022-05-21 18:56:58 +0200 |
commit | 165af78b4f7955870d0b3f6dd029768380661be4 (patch) | |
tree | f022637205683306024df348a3b9c787cd9924d2 | |
parent | 3307447f4a5c361fc2812244cd20c3bbe9a91bdc (diff) | |
download | wajir-165af78b4f7955870d0b3f6dd029768380661be4.tar.bz2 |
main: Exit on Control-c
Use `with-user-abort` to exit on a Control-c SIGINT.
Used the following tutorial for inspiration:
https://stevelosh.com/blog/2021/03/small-common-lisp-cli-programs/#s12-errors
Apparently Control-c should exit with code 130 according to this:
https://tldp.org/LDP/abs/html/exitcodes.html
Followed these Stack Overflow answers to turn off the interactive
debugger in an implementation independent way:
https://stackoverflow.com/questions/3074586/how-to-turn-off-the-debugger-in-sbcl/3074698#3074698
https://stackoverflow.com/questions/69280179/unmatched-close-parenthesis-when-sbcl-debugger-is-turned-off
This still opens the interactive debugger if Control-c is pressed before
`(main)` is called, but I don't know if there's any way to prevent that.
-rw-r--r-- | src/main.lisp | 29 | ||||
-rw-r--r-- | src/package.lisp | 3 | ||||
-rw-r--r-- | wajir.asd | 3 |
3 files changed, 29 insertions, 6 deletions
diff --git a/src/main.lisp b/src/main.lisp index bd1e774..6076da7 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -1,7 +1,5 @@ (in-package :wajir) -(defparameter uiop:*lisp-interaction* nil) - (defun main () ;; Query page of issues ;; Start watching issue @@ -10,8 +8,31 @@ ;; TODO: Add SIGINT and error handling - (let ((config (parse-options))) - (run config))) + ;; Disable interactive debugger. + ; (defparameter uiop:*lisp-interaction* nil) + (setf *debugger-hook* #'debug-ignore) + + (handler-case + (interrupt:with-user-abort + (handler-bind ((error #'(lambda (e) + (exit-with-error e sysexits:+unavailable+)))) + + ; (let ((config (parse-options))) + ; (run config)) + + (format t "l-i: ~S~%" uiop:*lisp-interaction*) + (format t "main ran~%") + (sleep 5))) + + ;; Control-c + (interrupt:user-abort () + (format t "siginted~%") + (opts:exit 130)))) + +(defun debug-ignore (condition hook) + (declare (ignore hook)) + (princ condition) + (abort)) (defun run (config) (let ((basic-auth-token (cl-base64:string-to-base64-string diff --git a/src/package.lisp b/src/package.lisp index c48ccba..1b3ea43 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1,6 +1,7 @@ (defpackage :wajir (:use :cl) - (:local-nicknames (:jzon :com.inuoe.jzon)) + (:local-nicknames (:interrupt :with-user-abort) + (:jzon :com.inuoe.jzon)) (:export :main)) @@ -15,7 +15,8 @@ :com.inuoe.jzon :dexador :sysexits - :unix-opts) + :unix-opts + :with-user-abort) :components ((:module "src" :serial t :components ((:file "package") |