From 1b17985c5a438858b4cbe4e1e57cf000aeea0772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 13 Jan 2023 16:05:07 +0100 Subject: fix(permissions): lock stdio streams when prompt is shown (#17392) This commit changes permission prompt to lock stdio streams when prompt is shown. --- runtime/permissions/prompter.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime/permissions') diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index a73898835..ae07e004c 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -192,6 +192,11 @@ impl PermissionPrompter for TtyPrompter { return PromptResponse::Deny; // don't grant permission if this fails } + // Lock stdio streams, so no other output is written while the prompt is + // displayed. + let _stdout_guard = std::io::stdout().lock(); + let _stderr_guard = std::io::stderr().lock(); + // print to stderr so that if stdout is piped this is still displayed. const OPTS: &str = "[y/n] (y = yes, allow; n = no, deny)"; eprint!("{} ┌ ", PERMISSION_EMOJI); @@ -238,6 +243,9 @@ impl PermissionPrompter for TtyPrompter { }; }; + drop(_stdout_guard); + drop(_stderr_guard); + value } } -- cgit v1.2.3