GNU bug report logs -
#51263
29.0.50; [PATCH] Use run-at-time to read a password in comint
Previous Next
Reported by: miha <at> kamnitnik.top
Date: Mon, 18 Oct 2021 11:52:02 UTC
Severity: normal
Tags: patch
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 51263 in the body.
You can then email your comments to 51263 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#51263
; Package
emacs
.
(Mon, 18 Oct 2021 11:52:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
miha <at> kamnitnik.top
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Mon, 18 Oct 2021 11:52:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Currently, comint-watch-for-password-prompt has some problems. It is
called from the comint process filter and doesn't return until the user
exits the password minibuffer.
If the process produces more output while the minibuffer is still open
(this happens if the "sudo" command times out, for example), the process
filter will be called recursively before the current execution of the
process filter has a chance to finish. This filter function uses some
global/buffer-local, state (the variable comint-last-output-start, for
example), so it isn't made to be called simultaneously like that.
The user may also quit the password minibuffer with C-g, canceling
execution of the filter function.
The result of these two events is usually that the buffer text
containing the password prompt isn't correctly marked as output with the
'field text property. Further problems may arise if
comint-output-filter-functions contain functions after the password
prompt watcher.
I've come up with a solution: using (run-at-time 0 ...), we can prompt
for a password after the filter function finishes execution. The
attached patch implements this for comint, eshell and term.el.
Best regards.
[0001-watch-for-password-prompt-Use-run-at-time-to-read-pa.patch (text/x-patch, inline)]
From d4e8af0f4d90c7d989f21781fc7ca7fd284652bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miha=20Rihtar=C5=A1i=C4=8D?= <miha <at> kamnitnik.top>
Date: Mon, 18 Oct 2021 13:13:45 +0200
Subject: [PATCH] *-watch-for-password-prompt: Use run-at-time to read password
* lisp/comint.el (comint-watch-for-password-prompt):
* lisp/eshell/esh-mode.el (eshell-watch-for-password-prompt):
* lisp/term.el (term-watch-for-password-prompt):
Use run-at-time to read a password.
---
lisp/comint.el | 18 +++++++++++++-----
lisp/eshell/esh-mode.el | 9 ++++++++-
lisp/term.el | 9 ++++++++-
3 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/lisp/comint.el b/lisp/comint.el
index a0873c0b6a..e925b3a4b6 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -2455,11 +2455,19 @@ comint-watch-for-password-prompt
(when (let ((case-fold-search t))
(string-match comint-password-prompt-regexp
(string-replace "\r" "" string)))
- (let ((comint--prompt-recursion-depth (1+ comint--prompt-recursion-depth)))
- (if (> comint--prompt-recursion-depth 10)
- (message "Password prompt recursion too deep")
- (comint-send-invisible
- (string-trim string "[ \n\r\t\v\f\b\a]+" "\n+"))))))
+ ;; Use `run-at-time' in order not to pause execution of the
+ ;; process filter with a minibuffer
+ (run-at-time
+ 0 nil
+ (lambda (current-buf)
+ (with-current-buffer current-buf
+ (let ((comint--prompt-recursion-depth
+ (1+ comint--prompt-recursion-depth)))
+ (if (> comint--prompt-recursion-depth 10)
+ (message "Password prompt recursion too deep")
+ (comint-send-invisible
+ (string-trim string "[ \n\r\t\v\f\b\a]+" "\n+"))))))
+ (current-buffer))))
;; Low-level process communication
diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el
index 98e89037f3..579b01f4d1 100644
--- a/lisp/eshell/esh-mode.el
+++ b/lisp/eshell/esh-mode.el
@@ -940,7 +940,14 @@ eshell-watch-for-password-prompt
(beginning-of-line)
(if (re-search-forward eshell-password-prompt-regexp
eshell-last-output-end t)
- (eshell-send-invisible))))))
+ ;; Use `run-at-time' in order not to pause execution of
+ ;; the process filter with a minibuffer
+ (run-at-time
+ 0 nil
+ (lambda (current-buf)
+ (with-current-buffer current-buf
+ (eshell-send-invisible)))
+ (current-buffer)))))))
(custom-add-option 'eshell-output-filter-functions
'eshell-watch-for-password-prompt)
diff --git a/lisp/term.el b/lisp/term.el
index dd5457745b..530b93484e 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -2409,7 +2409,14 @@ term-watch-for-password-prompt
(when (term-in-line-mode)
(when (let ((case-fold-search t))
(string-match comint-password-prompt-regexp string))
- (term-send-invisible (read-passwd string)))))
+ ;; Use `run-at-time' in order not to pause execution of the
+ ;; process filter with a minibuffer
+ (run-at-time
+ 0 nil
+ (lambda (current-buf)
+ (with-current-buffer current-buf
+ (term-send-invisible (read-passwd string))))
+ (current-buffer)))))
;;; Low-level process communication
--
2.33.0
[signature.asc (application/pgp-signature, inline)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#51263
; Package
emacs
.
(Mon, 18 Oct 2021 13:27:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 51263 <at> debbugs.gnu.org (full text, mbox):
miha <at> kamnitnik.top writes:
> I've come up with a solution: using (run-at-time 0 ...), we can prompt
> for a password after the filter function finishes execution. The
> attached patch implements this for comint, eshell and term.el.
Seems to work very nicely -- I tried mixing some async output while
prompting for a "su" password, and I couldn't see any glitches, so I've
pushed your patch to Emacs 29.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
bug marked as fixed in version 29.1, send any further explanations to
51263 <at> debbugs.gnu.org and miha <at> kamnitnik.top
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 18 Oct 2021 13:27:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 16 Nov 2021 12:24:09 GMT)
Full text and
rfc822 format available.
This bug report was last modified 2 years and 133 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.