From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thien-Thi Nguyen Newsgroups: gmane.emacs.bugs Subject: bug#471: pgg-gpg.el - pgg-gpg-process-region timing problem Date: Mon, 23 Jun 2008 15:17:39 +0200 Message-ID: <873an4b898.fsf__5420.00031932748$1214278000$gmane$org@ambire.localdomain> References: <2cd46e7f0806221037h6d16839bp567eb5b901313375@mail.gmail.com> <87zlpc8t00.fsf@ambire.localdomain> <87r6ao8rty.fsf@ambire.localdomain> Reply-To: Thien-Thi Nguyen , 471@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1214277950 8329 80.91.229.12 (24 Jun 2008 03:25:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 24 Jun 2008 03:25:50 +0000 (UTC) Cc: wilde@sha-bang.de, emacs-pretest-bug@gnu.org, ueno@unixuser.org, emacs-devel To: "ken manheimer" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jun 24 05:26:34 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KAzAq-0002BP-Pz for geb-bug-gnu-emacs@m.gmane.org; Tue, 24 Jun 2008 05:26:29 +0200 Original-Received: from localhost ([127.0.0.1]:53814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KAzA1-0004uX-FR for geb-bug-gnu-emacs@m.gmane.org; Mon, 23 Jun 2008 23:25:37 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KAmO2-0002XW-RG for bug-gnu-emacs@gnu.org; Mon, 23 Jun 2008 09:47:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KAmO2-0002XG-53 for bug-gnu-emacs@gnu.org; Mon, 23 Jun 2008 09:47:14 -0400 Original-Received: from [199.232.76.173] (port=52699 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KAmO1-0002X8-Tp for bug-gnu-emacs@gnu.org; Mon, 23 Jun 2008 09:47:13 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:44293) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KAmO1-0008E8-IB for bug-gnu-emacs@gnu.org; Mon, 23 Jun 2008 09:47:13 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m5NDlAaV031249; Mon, 23 Jun 2008 06:47:10 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m5NDU4NF026641; Mon, 23 Jun 2008 06:30:04 -0700 X-Loop: don@donarmstrong.com Resent-From: Thien-Thi Nguyen Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Mon, 23 Jun 2008 13:30:03 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 471 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.121422724825258 (code B ref -1); Mon, 23 Jun 2008 13:30:03 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 23 Jun 2008 13:20:48 +0000 Original-Received: from fencepost.gnu.org (fencepost.gnu.org [140.186.70.10]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m5NDKfZQ025252 for ; Mon, 23 Jun 2008 06:20:42 -0700 Original-Received: from mx10.gnu.org ([199.232.76.166]:50368) by fencepost.gnu.org with esmtp (Exim 4.67) (envelope-from ) id 1KAlyD-0002sf-S0 for emacs-pretest-bug@gnu.org; Mon, 23 Jun 2008 09:20:34 -0400 Original-Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1KAlyF-00055G-0v for emacs-pretest-bug@gnu.org; Mon, 23 Jun 2008 09:20:38 -0400 Original-Received: from [151.61.141.75] (port=46002 helo=ambire.localdomain) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KAlyD-00052G-Mb; Mon, 23 Jun 2008 09:20:34 -0400 Original-Received: from ttn by ambire.localdomain with local (Exim 4.63) (envelope-from ) id 1KAlvP-00024h-GV; Mon, 23 Jun 2008 15:17:39 +0200 In-Reply-To: <87r6ao8rty.fsf@ambire.localdomain> (Thien-Thi Nguyen's message of "Mon, 23 Jun 2008 10:43:05 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Genre and OS details not recognized. X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Mon, 23 Jun 2008 09:47:14 -0400 X-Mailman-Approved-At: Mon, 23 Jun 2008 23:25:12 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:18512 Archived-At: Delving into this, i got a little carried away... full func below. This adds GOOD_PASSPHRASE checking (necessary for GNUPG 1.4.6, at least) and some other coding-system related finessing, but removes the sentinel proposed in the first attempt. In its place, we zonk the baleful `process-adaptive-read-buffering' and remove timeout parameters from `accept-process-output' calls. With this func things seem to work fine for `pgg-sign' on a small buffer, and mostly for large buffers (270KB), but sometimes (~10%) with large buffers, i see a "file error: bad address *GnuPG*". Hmmm... thi ______________________________________________________________________ (defun pgg-gpg-process-region (start end passphrase program args) (let* ((use-agent (and (null passphrase) (pgg-gpg-use-agent-p))) (output-file-name (pgg-make-temp-file "pgg-output")) (args `("--status-fd" "2" ,@(if use-agent '("--use-agent") (if passphrase '("--passphrase-fd" "0"))) "--yes" ; overwrite "--output" ,output-file-name ,@pgg-gpg-extra-args ,@args)) (output-buffer pgg-output-buffer) (errors-buffer pgg-errors-buffer) (orig-mode (default-file-modes)) (inhibit-redisplay t)) (with-current-buffer (get-buffer-create errors-buffer) (buffer-disable-undo) (erase-buffer)) (unwind-protect (let* ((coding-system-for-write 'binary) ;; GNUPG 1.4.6 does not terminate on bad passphrase, eg: ;; [GNUPG:] BAD_PASSPHRASE (long hex # here) ;; gpg: skipped "ttn": bad passphrase ;; gpg: [stdin]: clearsign failed: bad passphrase ;; so we need to check that condition ourselves and bail out. ;; ;; To check if the passphrase is accepted, we need to parse the ;; errors-buffer, but `process-adaptive-read-buffering' non-nil ;; sometimes prevents it from filling. So turn it off. (process-adaptive-read-buffering (not passphrase)) (process (progn (set-default-file-modes 448) (apply #'start-process "*GnuPG*" errors-buffer program args))) (status (process-status process)) exit-status) (set-process-sentinel process nil) (when passphrase (let ((coding-system-for-write (or pgg-passphrase-coding-system 'binary))) (process-send-string process passphrase)) (process-send-string process "\n") ;; Bail out if passphrase is not accepted. ;; MAINTAIN ME: Tested against GNUPG 1.4.6. (let (result) (while (not result) (accept-process-output process) (with-current-buffer errors-buffer (save-excursion (goto-char (point-min)) (when (re-search-forward ;; BGM: BAD, GOOD, MISSING. "^.GNUPG:. \\([BGM][A-Z]+\\)_PASSPHRASE" nil t) (setq result (match-string 1)))))) (unless (string= "GOOD" result) (error "Passphrase no good")))) (process-send-region process start end) (process-send-eof process) ;; TODO: Re-enable `process-adaptive-read-buffering' here. (while (eq 'run (setq status (process-status process))) (accept-process-output process)) (delete-process process) (setq exit-status (process-exit-status process)) (with-current-buffer (get-buffer-create output-buffer) (buffer-disable-undo) (erase-buffer) (if (file-exists-p output-file-name) (let ((coding-system-for-read (if pgg-text-mode 'raw-text 'binary))) (insert-file-contents output-file-name))) (set-buffer errors-buffer) (if (memq status '(stop signal)) (error "%s exited abnormally: '%s'" program exit-status)) (if (= 127 exit-status) (error "%s could not be found" program)))) (if (file-exists-p output-file-name) (delete-file output-file-name)) (when (get-process "*GnuPG*") (kill-process "*GnuPG*")) (set-default-file-modes orig-mode))))