Skip to content

Commit

Permalink
CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
plexus committed Jun 12, 2024
1 parent 83725b7 commit a9bdc31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Unreleased

## Added

## Fixed

## Changed

- Make sure child processes are killed when launchpad receives a INT/TERM/KILL signal

# 0.29.135-alpha (2024-06-03 / 00df813)

## Added
Expand Down Expand Up @@ -231,4 +229,4 @@ Initial release
- lambdaisland.classpath integration
- Support for cider-nrepl, refactor-nrepl
- Basic support for shadow-cljs cljs nREPL-base REPL
- Auto-connect for Emacs
- Auto-connect for Emacs
26 changes: 24 additions & 2 deletions src/lambdaisland/launchpad.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@
(java.net ServerSocket)
(java.util.concurrent TimeUnit)))

(defonce processes (atom []))

(defn cleanup [sig]
(println "Received" (str "SIG" sig))
(doseq [process @processes]
(print "Killing" (.pid process))
(flush)
(.destroy process)
(println " ->" (.waitFor process))
(flush))
(System/exit 0))

(defmacro set-signal-handler!
[signal f]
`(sun.misc.Signal/handle
(sun.misc.Signal. ~signal)
(proxy [sun.misc.SignalHandler] []
(handle [signal#] (~f signal#)))))

(set-signal-handler! "INT" cleanup)
(set-signal-handler! "TERM" cleanup)
(set-signal-handler! "KILL" cleanup)

(def cli-opts
[["-h" "--help"]
["-v" "--verbose" "Print debug information"]
Expand Down Expand Up @@ -518,6 +541,7 @@
color (mod (hash (or prefix (first cmd))) 8)
prefix (str "[" (ansi-fg (+ 30 color) (or prefix (first cmd))) "] ")
process (pipe-process-output (.start proc-builder) prefix)
_ (swap! processes conj process)
ctx (update ctx :processes (fnil conj []) process)]
(when show-command?
(apply println (str prefix "$") (map shellquote cmd)))
Expand Down Expand Up @@ -617,7 +641,5 @@
after-steps
end-steps)))
processes (:processes ctx)]
(.addShutdownHook (Runtime/getRuntime)
(Thread. (fn [] (run! #(.destroy %) processes))))
(System/exit (apply min (for [p processes]
(.waitFor p))))))

0 comments on commit a9bdc31

Please sign in to comment.