Skip to content

Commit a9bdc31

Browse files
committed
CHANGELOG
1 parent 83725b7 commit a9bdc31

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Unreleased
22

3-
## Added
4-
5-
## Fixed
6-
73
## Changed
84

5+
- Make sure child processes are killed when launchpad receives a INT/TERM/KILL signal
6+
97
# 0.29.135-alpha (2024-06-03 / 00df813)
108

119
## Added
@@ -231,4 +229,4 @@ Initial release
231229
- lambdaisland.classpath integration
232230
- Support for cider-nrepl, refactor-nrepl
233231
- Basic support for shadow-cljs cljs nREPL-base REPL
234-
- Auto-connect for Emacs
232+
- Auto-connect for Emacs

src/lambdaisland/launchpad.clj

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@
1515
(java.net ServerSocket)
1616
(java.util.concurrent TimeUnit)))
1717

18+
(defonce processes (atom []))
19+
20+
(defn cleanup [sig]
21+
(println "Received" (str "SIG" sig))
22+
(doseq [process @processes]
23+
(print "Killing" (.pid process))
24+
(flush)
25+
(.destroy process)
26+
(println " ->" (.waitFor process))
27+
(flush))
28+
(System/exit 0))
29+
30+
(defmacro set-signal-handler!
31+
[signal f]
32+
`(sun.misc.Signal/handle
33+
(sun.misc.Signal. ~signal)
34+
(proxy [sun.misc.SignalHandler] []
35+
(handle [signal#] (~f signal#)))))
36+
37+
(set-signal-handler! "INT" cleanup)
38+
(set-signal-handler! "TERM" cleanup)
39+
(set-signal-handler! "KILL" cleanup)
40+
1841
(def cli-opts
1942
[["-h" "--help"]
2043
["-v" "--verbose" "Print debug information"]
@@ -518,6 +541,7 @@
518541
color (mod (hash (or prefix (first cmd))) 8)
519542
prefix (str "[" (ansi-fg (+ 30 color) (or prefix (first cmd))) "] ")
520543
process (pipe-process-output (.start proc-builder) prefix)
544+
_ (swap! processes conj process)
521545
ctx (update ctx :processes (fnil conj []) process)]
522546
(when show-command?
523547
(apply println (str prefix "$") (map shellquote cmd)))
@@ -617,7 +641,5 @@
617641
after-steps
618642
end-steps)))
619643
processes (:processes ctx)]
620-
(.addShutdownHook (Runtime/getRuntime)
621-
(Thread. (fn [] (run! #(.destroy %) processes))))
622644
(System/exit (apply min (for [p processes]
623645
(.waitFor p))))))

0 commit comments

Comments
 (0)