rc lint: Avoid stray processes and temporary directory

This commit is an attempt at mitigating stray processes and temporary
directories, which pile up in the process tree and `$TMPDIR` over time.

To reproduce the issue, run the `lint` command in rapid successions,
or simply run `:lint; lint; lint;` in the prompt (two consecutive
calls are enough to trigger the bug).

The first call creates a `\*lint-ouput*` buffer, bound to a named
pipe that will be populated later on in an asychronous shell
process. It's that same process that runs the linter afterward, and as
soon as it has been spawned, the following call to `:lint` is executed.

Each call to `:lint` overrides the path to the named pipe that was
assigned to `\*lint-output*` by the previous one, resulting in several
asynchronous processes (that write diagnostics to the pipe) hanging
forever — the pipe is never read, and so the process idles.

The command that removes the temporary directory follows the one that
writes to the named pipe, it's never called in the above scenario,
which additionally results in `kak-lint.XXXXXXXX` directories being
left behind in `$TMPDIR`.

(Also) Fixes #3681.
This commit is contained in:
Frank LENORMAND 2020-11-30 13:35:19 +03:00
parent 14f7d2637c
commit fe5f357446

View File

@ -14,6 +14,14 @@ declare-option -hidden int lint_warning_count
declare-option -docstring "name of the client in which utilities display information" \ declare-option -docstring "name of the client in which utilities display information" \
str toolsclient str toolsclient
define-command -hidden -params 1 lint-open-output-buffer %{
evaluate-commands -try-client %opt{toolsclient} %{
edit! -fifo "%arg{1}/fifo" -debug *lint-output*
set-option buffer filetype make
set-option buffer make_current_error_line 0
}
}
define-command \ define-command \
-hidden \ -hidden \
-params 1 \ -params 1 \
@ -42,14 +50,6 @@ define-command \
# A directory to keep all our temporary data. # A directory to keep all our temporary data.
dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-lint.XXXXXXXX) dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-lint.XXXXXXXX)
# A fifo to send the results back to a Kakoune buffer.
mkfifo "$dir"/fifo
printf '%s\n' "evaluate-commands -try-client '$kak_opt_toolsclient' %{
edit! -fifo $(kakquote "$dir/fifo") -debug *lint-output*
set-option buffer filetype make
set-option buffer make_current_error_line 0
}"
# Write all the selection descriptions to files. # Write all the selection descriptions to files.
eval set -- "$kak_selections_desc" eval set -- "$kak_selections_desc"
i=0 i=0
@ -207,6 +207,10 @@ define-command \
"$kak_client" "$kak_client"
fi | kak -p "$kak_session" fi | kak -p "$kak_session"
# A fifo to send the results back to a Kakoune buffer.
mkfifo "$dir"/fifo
printf 'lint-open-output-buffer %s' "$(kakquote "$dir")" | kak -p "$kak_session"
# We are done here. Send the results to Kakoune, # We are done here. Send the results to Kakoune,
# and clean up. # and clean up.
cat "$dir"/result > "$dir"/fifo cat "$dir"/result > "$dir"/fifo