From fe5f357446bd5b763b184bfcf142330ea51e6dca Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Mon, 30 Nov 2020 13:35:19 +0300 Subject: [PATCH] rc lint: Avoid stray processes and temporary directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- rc/tools/lint.kak | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/rc/tools/lint.kak b/rc/tools/lint.kak index c53b6b71..0d92b828 100644 --- a/rc/tools/lint.kak +++ b/rc/tools/lint.kak @@ -14,6 +14,14 @@ declare-option -hidden int lint_warning_count declare-option -docstring "name of the client in which utilities display information" \ 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 \ -hidden \ -params 1 \ @@ -42,14 +50,6 @@ define-command \ # A directory to keep all our temporary data. 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. eval set -- "$kak_selections_desc" i=0 @@ -207,6 +207,10 @@ define-command \ "$kak_client" 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, # and clean up. cat "$dir"/result > "$dir"/fifo