From 0332a0ef2bbe6954f080cb6c9d3f0cc2517a1ab1 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Thu, 24 Aug 2017 15:53:56 +0200 Subject: [PATCH] Minor improvements for tramp-interrupt-process, documentation * doc/lispref/processes.texi (Signals to Processes): * etc/NEWS: Document interrupt-process-functions. * lisp/net/tramp.el (tramp-interrupt-process): Test also for `process-live-p'. * src/process.c (Vinterrupt_process_functions): Fix docstring. * test/lisp/net/tramp-tests.el (tramp-test28-interrupt-process): Extend test. --- doc/lispref/processes.texi | 16 ++++++++++++++++ etc/NEWS | 10 ++++++++++ lisp/net/tramp.el | 2 +- src/process.c | 4 ++-- test/lisp/net/tramp-tests.el | 12 ++++++++++-- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 292d55d50c5..45e04a5ab88 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -1351,6 +1351,22 @@ integer); that allows you to send signals to processes that are not children of Emacs. @xref{System Processes}. @end deffn +Sometimes, it is necessary to send a signal to a non-local +asynchronous process. This is possible by writing an own +@code{interrupt-process} implementation. This function must be added +then to @code{interrupt-process-functions}. + +@defvar interrupt-process-functions +This variable is a list of functions to be called for +@code{interrupt-process}. The arguments of the functions are the same +as for @code{interrupt-process}. These functions are called in the +order of the list, until one of them returns non-@code{nil}. The +default function, which shall always be the last in this list, is +@code{internal-default-interrupt-process}. + +This is the mechanism, how Tramp implements @code{interrupt-process}. +@end defvar + @node Output from Processes @section Receiving Output from Processes @cindex process output diff --git a/etc/NEWS b/etc/NEWS index a9e2f5ae3f1..bf59749a62b 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -335,6 +335,13 @@ probability of data corruption due to techniques Emacs uses to recover in these situations. +++ +** 'interrupt-process' consults now the list +'interrupt-process-functions', which function has to be called in +order to deliver the SIGINT signal. This allows Tramp to send the +SIGINT signal to remote asynchronous processes. The hitherto existing +implementation has been moved to 'internal-default-interrupt-process'. + ++++ ** File local and directory local variables are now initialized each time the major mode is set, not just when the file is first visited. These local variables will thus not vanish on setting a major mode. @@ -988,6 +995,9 @@ manual documents how to configure ssh and PuTTY accordingly. initialization files. --- +*** Tramp is able now to send SIGINT to remote asynchronous processes. + +--- *** Variable 'tramp-completion-mode' is obsoleted. --- diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 2aa9a6b9859..ef3e62ccce3 100644 --- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -4393,7 +4393,7 @@ Only works for Bourne-like shells." (t process))) pid) ;; If it's a Tramp process, send the INT signal remotely. - (when (and (processp proc) + (when (and (processp proc) (process-live-p proc) (setq pid (process-get proc 'remote-pid))) (tramp-message proc 5 "Interrupt process %s with pid %s" proc pid) ;; This is for tramp-sh.el. Other backends do not support this (yet). diff --git a/src/process.c b/src/process.c index e7ee99ab3d9..730caea677f 100644 --- a/src/process.c +++ b/src/process.c @@ -8192,8 +8192,8 @@ The variable takes effect when `start-process' is called. */); Vprocess_adaptive_read_buffering = Qt; DEFVAR_LISP ("interrupt-process-functions", Vinterrupt_process_functions, - doc: /* List of functions to be called for `interrupt-function'. -The arguments of the functions are the same as for `interrupt-function'. + doc: /* List of functions to be called for `interrupt-process'. +The arguments of the functions are the same as for `interrupt-process'. These functions are called in the order of the list, until one of them returns non-`nil'. */); Vinterrupt_process_functions = list1 (Qinternal_default_interrupt_process); diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 85ed6467220..55f4b52ccdf 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2966,9 +2966,17 @@ This tests also `make-symbolic-link', `file-truename' and `add-name-to-file'." (with-temp-buffer (setq proc (start-file-process "test" (current-buffer) "sleep" "10")) (should (processp proc)) + (should (process-live-p proc)) (should (equal (process-status proc) 'run)) - (interrupt-process proc) - (should (equal (process-status proc) 'signal))) + (should (interrupt-process proc)) + ;; Let the process accept the interrupt. + (accept-process-output proc 1 nil 0) + (should-not (process-live-p proc)) + (should (equal (process-status proc) 'signal)) + ;; An interrupted process cannot be interrupted, again. + ;; Does not work reliable. + ;; (should-error (interrupt-process proc))) + ) ;; Cleanup. (ignore-errors (delete-process proc))))) -- 2.11.4.GIT