mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
[Housekeeping] Close system port when jobs are cancelled (#182)
* Created a test setup that works * Refactored test setup into real-world fixes
This commit is contained in:
parent
e984c05298
commit
c36e33e1fd
6 changed files with 52 additions and 3 deletions
26
priv/cmd_wrapper.sh
Executable file
26
priv/cmd_wrapper.sh
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script is a wrapper for other programs
|
||||
# that ensures they are killed when stdin closes
|
||||
# (eg: a job terminates)
|
||||
|
||||
# Start the program in the background
|
||||
exec "$@" &
|
||||
pid1=$!
|
||||
|
||||
# Silence warnings from here on
|
||||
exec >/dev/null 2>&1
|
||||
|
||||
# Read from stdin in the background and
|
||||
# kill running program when stdin closes
|
||||
exec 0<&0 $(
|
||||
while read; do :; done
|
||||
kill -KILL $pid1
|
||||
) &
|
||||
pid2=$!
|
||||
|
||||
# Clean up
|
||||
wait $pid1
|
||||
ret=$?
|
||||
kill -KILL $pid2
|
||||
exit $ret
|
||||
Loading…
Add table
Add a link
Reference in a new issue