From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 047956DE0C64 for ; Thu, 17 Aug 2017 10:57:42 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.069 X-Spam-Level: X-Spam-Status: No, score=-0.069 tagged_above=-999 required=5 tests=[AWL=-0.108, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.211, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mVbJ3NWwtson for ; Thu, 17 Aug 2017 10:57:39 -0700 (PDT) Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by arlo.cworth.org (Postfix) with ESMTPS id 656A56DE0A5B for ; Thu, 17 Aug 2017 10:57:39 -0700 (PDT) Received: by mail-wr0-f180.google.com with SMTP id z91so41688249wrc.4 for ; Thu, 17 Aug 2017 10:57:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3P/nV7Um6wGhtK/sCn5WkUK4fwN0PMSfxjdr+ZK6Pvk=; b=Lro1oMITyzilNTbEDGKMikEatGWWrlCSEucLPE8iz/MF9TPrdYa3lSLCjlMSLfLnCi /PIGlPjQFZiB9/+y7bhBMHzl0EHvF14YsDxpqJ4zdGqY2aV/dUw0bSle3SKVIZsdb/e8 Xyjg8X4XrU2VgnrY6lDNDWUnOZI5K60uyevoDOraPzcxKGZZneFBDVjpKUYA+pDe9P9K Dw0oEaaC0eQsbFrWGhvQbkgvQZ56G9L2OT1xsyZT7GJJmINuTGqfV77X4Ito12vHcS/v ah94SsV9lM5vkcoYuKR1VxxYFUzb5ZEia8jCkljC/VWBu+BCi4/8zXtHdCKnnbf1+Wpj KOLg== X-Gm-Message-State: AHYfb5jwEafuzxGt/3HJlVSIf/u8pe0Oenv4mAXvLRFDEP6Oc+KGtcLM o9NGAWlpQUeKuPVGsxE= X-Received: by 10.223.158.202 with SMTP id b10mr4050816wrf.234.1502992657577; Thu, 17 Aug 2017 10:57:37 -0700 (PDT) Received: from home.thecybershadow.net ([89.28.117.31]) by smtp.gmail.com with ESMTPSA id e2sm39759wrd.60.2017.08.17.10.57.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Aug 2017 10:57:36 -0700 (PDT) From: Vladimir Panteleev To: notmuch@notmuchmail.org Subject: [PATCH 1/2] emacs: Refactor subprocess stderr propagation Date: Thu, 17 Aug 2017 17:57:11 +0000 Message-Id: <20170817175712.6302-2-notmuch@thecybershadow.net> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170817175712.6302-1-notmuch@thecybershadow.net> References: <20170817175712.6302-1-notmuch@thecybershadow.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Aug 2017 17:57:42 -0000 Load subprocess error output to a string in the callers, and propagate the error messages as a string parameter instead of a path to file names. Required to be able to avoid using temporary files for subprocess error output. * notmuch-lib.el: Update notmuch-check-async-exit-status, notmuch-check-exit-status: accept an err parameter instead of err-file; shift the responsibility of loading error messages from files up the call stack. --- emacs/notmuch-lib.el | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 337b20ac..1f743eff 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -768,23 +768,23 @@ signaled error. This function does not return." (error "%s" (concat msg (when extra " (see *Notmuch errors* for more details)")))) -(defun notmuch-check-async-exit-status (proc msg &optional command err-file) +(defun notmuch-check-async-exit-status (proc msg &optional command err) "If PROC exited abnormally, pop up an error buffer and signal an error. This is a wrapper around `notmuch-check-exit-status' for asynchronous process sentinels. PROC and MSG must be the -arguments passed to the sentinel. COMMAND and ERR-FILE, if -provided, are passed to `notmuch-check-exit-status'. If COMMAND -is not provided, it is taken from `process-command'." +arguments passed to the sentinel. COMMAND and ERR, if provided, +are passed to `notmuch-check-exit-status'. If COMMAND is not +provided, it is taken from `process-command'." (let ((exit-status (case (process-status proc) ((exit) (process-exit-status proc)) ((signal) msg)))) (when exit-status (notmuch-check-exit-status exit-status (or command (process-command proc)) - nil err-file)))) + nil err)))) -(defun notmuch-check-exit-status (exit-status command &optional output err-file) +(defun notmuch-check-exit-status (exit-status command &optional output err) "If EXIT-STATUS is non-zero, pop up an error buffer and signal an error. If EXIT-STATUS is non-zero, pop up a notmuch error buffer @@ -793,9 +793,9 @@ be a number indicating the exit status code of a process or a string describing the signal that terminated the process (such as returned by `call-process'). COMMAND must be a list giving the command and its arguments. OUTPUT, if provided, is a string -giving the output of command. ERR-FILE, if provided, is the name -of a file containing the error output of command. OUTPUT and the -contents of ERR-FILE will be included in the error message." +giving the output of command. ERR, if provided, is the error +output of command. OUTPUT and ERR will be included in the error +message." (cond ((eq exit-status 0) t) @@ -808,12 +808,7 @@ You may need to restart Emacs or upgrade your notmuch Emacs package.")) Emacs requested a newer output format than supported by the notmuch CLI. You may need to restart Emacs or upgrade your notmuch package.")) (t - (let* ((err (when err-file - (with-temp-buffer - (insert-file-contents err-file) - (unless (eobp) - (buffer-string))))) - (command-string + (let* ((command-string (mapconcat (lambda (arg) (shell-quote-argument (cond ((stringp arg) arg) @@ -889,9 +884,13 @@ error." (with-temp-buffer (let ((err-file (make-temp-file "nmerr"))) (unwind-protect - (let ((status (notmuch-call-notmuch--helper (list t err-file) args))) + (let ((status (notmuch-call-notmuch--helper (list t err-file) args)) + (err (with-temp-buffer + (insert-file-contents err-file) + (unless (eobp) + (buffer-string))))) (notmuch-check-exit-status status (cons notmuch-command args) - (buffer-string) err-file) + (buffer-string) err) (goto-char (point-min)) (read (current-buffer))) (delete-file err-file))))) @@ -931,9 +930,14 @@ status." proc)) (defun notmuch-start-notmuch-sentinel (proc event) - (let ((err-file (process-get proc 'err-file)) - (sub-sentinel (process-get proc 'sub-sentinel)) - (real-command (process-get proc 'real-command))) + "Process sentinel function used by `notmuch-start-notmuch'." + (let* ((err-file (process-get proc 'err-file)) + (err (with-temp-buffer + (insert-file-contents err-file) + (unless (eobp) + (buffer-string)))) + (sub-sentinel (process-get proc 'sub-sentinel)) + (real-command (process-get proc 'real-command))) (condition-case err (progn ;; Invoke the sub-sentinel, if any @@ -945,12 +949,13 @@ status." ;; and there's no point in telling the user that (but we ;; still check for and report stderr output below). (when (buffer-live-p (process-buffer proc)) - (notmuch-check-async-exit-status proc event real-command err-file)) + (notmuch-check-async-exit-status proc event real-command err)) ;; If that didn't signal an error, then any error output was ;; really warning output. Show warnings, if any. (let ((warnings (with-temp-buffer (unless (= (second (insert-file-contents err-file)) 0) + (goto-char (point-min)) (end-of-line) ;; Show first line; stuff remaining lines in the ;; errors buffer. -- 2.13.3