local/bin/recompress: Cleanly kill subprocesses on C-c.
parent
9bf1809aae
commit
e63c37bb31
|
@ -28,11 +28,26 @@ If EXTENSIONS is empty, list all files."
|
|||
(uiop:ensure-all-directories-exist (list (uiop:ensure-directory-pathname path)))
|
||||
path)
|
||||
|
||||
(defun terminate-process-with-group (process-info)
|
||||
;; TODO: Is it possible to kill a group without pkill, maybe with osicat?
|
||||
(uiop:run-program
|
||||
(list "pkill" "-TERM" "-g"
|
||||
(format nil "~a" (osicat-posix:getpgid (uiop:process-info-pid process-info)))))
|
||||
(uiop:terminate-process process-info))
|
||||
|
||||
(defun run (&rest arguments)
|
||||
;; TODO: Hide stacktrace with `handler-case??
|
||||
(uiop:run-program arguments
|
||||
:output t
|
||||
:error-output :output))
|
||||
(let ((process-info nil))
|
||||
(handler-case
|
||||
(progn
|
||||
(setf process-info (uiop:launch-program arguments
|
||||
:output *standard-output*
|
||||
:error-output *error-output*))
|
||||
(uiop:wait-process process-info))
|
||||
(sb-sys:interactive-interrupt ()
|
||||
(terminate-process-with-group process-info)
|
||||
(format *error-output* "~&Interrupted.~&")
|
||||
(uiop:quit 127)))))
|
||||
|
||||
(defun assert-program (program &rest more-programs)
|
||||
(sera:and-let* ((missing-programs
|
||||
|
@ -40,6 +55,8 @@ If EXTENSIONS is empty, list all files."
|
|||
(warn "Missing programs: ~{~a~,^, ~}" missing-programs)
|
||||
(uiop:quit 1)))
|
||||
|
||||
(assert-program "pkill")
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun list-files ()
|
||||
|
@ -87,5 +104,6 @@ If EXTENSIONS is empty, list all files."
|
|||
(unless (= 2 (length (uiop:command-line-arguments)))
|
||||
(error "Requires 2 arguments"))
|
||||
|
||||
;; TODO: Hide compression output, only display processed file size and final size.
|
||||
(compress (first (uiop:command-line-arguments))
|
||||
(second (uiop:command-line-arguments)))
|
||||
|
|
Loading…
Reference in New Issue