From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.devel Subject: Re: process-file instead of call-process in proced.el? Date: Sun, 27 Mar 2022 16:08:15 +0200 Message-ID: <87tubjfpyo.fsf@gmx.de> References: <87o81shd6m.fsf@gmx.de> <87pmm8pqcq.fsf@gnu.org> <87k0cgh8g1.fsf@gmx.de> <87pmm8o8gc.fsf@gnu.org> <87bkxrhn1e.fsf@gmx.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29069"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Filipp Gunbin , emacs-devel@gnu.org To: Roland Winkler Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Mar 27 16:10:09 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nYTar-0007Mh-9H for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Mar 2022 16:10:09 +0200 Original-Received: from localhost ([::1]:56934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nYTap-0006BK-Oj for ged-emacs-devel@m.gmane-mx.org; Sun, 27 Mar 2022 10:10:07 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:51786) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYTZB-0004xS-Ts for emacs-devel@gnu.org; Sun, 27 Mar 2022 10:08:25 -0400 Original-Received: from mout.gmx.net ([212.227.17.22]:56815) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nYTZ9-0002Sd-AN; Sun, 27 Mar 2022 10:08:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1648390096; bh=3Jv/bjSlqF0sBQqdFqfvbc3gwBfdxqC9qp0p3BzQwBk=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=JNZGKBjppbAQYUyXiWBiOSuCeghrshs9Hn3uqALW4DkpFLfYmWjYj7fe6nBzT5KiL K/Rd3FCEC72UdyVHhTuU0O5oWyvhP8RuctdMHKOcZx5Zzgof5YpbQ8BNgY6LMuULHF Pp+lsN0SBhuaQkyMU++4qvU+4VU/TUZdiCgthz/g= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from gandalf.gmx.de ([212.91.243.20]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N33Ib-1o2T7d18v7-013OBO; Sun, 27 Mar 2022 16:08:16 +0200 In-Reply-To: <87bkxrhn1e.fsf@gmx.de> (Michael Albinus's message of "Sun, 27 Mar 2022 09:28:29 +0200") X-Provags-ID: V03:K1:dD5QBwLxUaFiyPe0EkjvJ90Ao/imHard/qeYJVjKW4DFWuV9Isw OEXLcbzhwGUhmCRtuzhtCjbdpMSqGNyLDliYqSC/WEQllCHTHRvuW5TiEmFWKwuuQklEmRK nE0SZqldFXUaOTDJzvHGXUVUiE22TWEmfm0huWHA2pR0iepdtMIMKUpzXjhJFX+B1iN0wdV StdtagAiuZmyUj/ppl/BA== X-UI-Out-Filterresults: notjunk:1;V03:K0:br9B4QuuzWc=:BETOvZljYpHci7IDVLLFx6 bxgnQ64YEgRJ11Rl/kRe7PetigysR/h7DG5lhuPGq1rwH/wXtVeKRVd3teAFbLIYkqndjnwbi 36MwY5DuCPalXaZIgixnglBQF+qPN9TWEs18HeOrTQQ+5mACZvEZx18YaUKSmkEaD2QS21iYU XUWRgIFDawsgKgcbTU7UZYLW3Um3uEzWCl7tmOB7GT1Vjb3hii8OAL8hHYl+fsuPriZjIQmAu GNYHXCwT/LYK2GsAD9n9/4tYP7yEkeUuyX6MJkXsbuZ2x1Ee3mqGyNvmNJtGSVl2It46oVOQv 3dQ9LsxD83Qtd/de8mJkHwz9oJm0sKnyvLrYW5eRoo2qrWLYHfFD1bkSKEI4kDYp+3znNPGx0 nmZTQ2qJpW9RY3nG7RjYd+M3jG8GBw3u9AIaD48Fxb7ALulPxKx0zeuguJRPuGLGhe2os88W0 kJR8cP9e2EKl3QTKGEVZjbgF9ikmp838vlQqbUB2haBDQCv2dzL2zbWXptLiiPaRXYTgMhBZP VaYquVhhjcmcoWldSYy2x1qI2GW6G6ntnj3OZGPvw8wUzAPnJZqXhrNLJI60rBPlN5IBYDJb2 AlWANdiBavboSdIbzasRGtgDIwuomHWGmIdMejuUCnBMQXn/gjt0jNc1aN89viOzf+YSag4Ko ekkahk+SaFgvVJY8GZdxbXwAnoz/JkkG8vrggAIQKdmvLqeCxkGDGe8dZVXFk43HkKdmHrFh4 iIv/9S6k+VI5P9HL2k0fxrTAMzyJo/NZCjmy9yhsCZSTuBMByWTzXmywR+YyoMOjSZ0qqzPR Received-SPF: pass client-ip=212.227.17.22; envelope-from=michael.albinus@gmx.de; helo=mout.gmx.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:287508 Archived-At: --=-=-= Content-Type: text/plain Michael Albinus writes: Hi, > I see. So if we don't want to emulate list-system-processes on a remote > host, we need another mean to determine, that a process is killed in a > sudo environment. I've prepared a first version of a patch (still missing documentation), see appended. The changes are: - `signal-process' is capable now to signal remote processes. This is triggered when either the PROCESS object has the property `remote-pid' (set by Tramp), or the PROCESS is just a number, and the additional optional parameter REMOTE is a remote file name. - There is a new user option `proced-remote-directory', which defaults to "/sudo::". When `proced-send-signal' or `proced-renice' are invoked with a prefix arg ("C-u k" or "C-u r" in the *Proced* buffer), the respective signal is sent with the credentials as identified by this user option. Comments? Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Transfer-Encoding: quoted-printable diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el index 0192a63a10..ff42a22765 100644 =2D-- a/lisp/net/tramp.el +++ b/lisp/net/tramp.el @@ -5957,6 +5957,43 @@ tramp-interrupt-process (lambda () (remove-hook 'interrupt-process-functions #'tramp-interrupt-process))) +(defun tramp-signal-process (process sigcode &optional remote) + "Send PROCESS the signal with code SIGCODE. +PROCESS may also be a number specifying the process id of the +process to signal; in this case, the process need not be a child of +this Emacs. Furthermore, if REMOTE is a remote file name, this +number is interpreted as process id on the respective remote +host, which will be the process to signal. +SIGCODE may be an integer, or a symbol whose name is a signal name." + (let (pid vec) + (cond + ((processp process) + (setq pid (process-get process 'remote-pid) + vec (process-get process 'vector))) + ((numberp process) + (setq pid process + vec (and (stringp remote) (tramp-dissect-file-name remote)))) + (t (signal 'wrong-type-argument (list #'processp process)))) + (unless (or (numberp sigcode) (symbolp sigcode)) + (signal 'wrong-type-argument (list #'numberp sigcode))) + ;; If it's a Tramp process, send SIGCODE remotely. + (when (and pid vec) + (tramp-message + vec 5 "Send signal %s to process %s with pid %s" sigcode process p= id) + ;; This is for tramp-sh.el. Other backends do not support this (ye= t). + (if (tramp-compat-funcall + 'tramp-send-command-and-check + vec (format "\\kill -%s %d" sigcode pid)) + 0 -1)))) + +;; `signal-process-functions' exists since Emacs 29.1. +(when (boundp 'signal-process-functions) + (add-hook 'signal-process-functions #'tramp-signal-process) + (add-hook + 'tramp-unload-hook + (lambda () + (remove-hook 'signal-process-functions #'tramp-signal-process)))) + (defun tramp-get-remote-null-device (vec) "Return null device on the remote host identified by VEC. If VEC is `tramp-null-hop', return local null device." diff --git a/lisp/proced.el b/lisp/proced.el index c1d599afc4..7966ccfb08 100644 =2D-- a/lisp/proced.el +++ b/lisp/proced.el @@ -29,10 +29,6 @@ ;; ;; To do: ;; - Interactive temporary customizability of flags in `proced-grammar-al= ist' -;; - Allow "sudo kill PID", "sudo renice PID" -;; `proced-send-signal' operates on multiple processes one by one. -;; With "sudo" we want to execute one "kill" or "renice" command -;; for all marked processes. Is there a `sudo-call-process'? ;; ;; Thoughts and Ideas ;; - Currently, `process-attributes' returns the list of @@ -61,6 +57,14 @@ proced-signal-function the external command (usually \"kill\")." :type '(choice (function :tag "function") (string :tag "command"))) +(make-obsolete-variable 'proced-signal-function "no longer used." "29.1") + +(defcustom proced-remote-directory "/sudo::" + "Remote directory to be used when sending a signal. +It must point to the local host, via a `sudo' or `doas' method, +or alike. See `proced-send-signal' and `proced-renice'." + :version "29.1" + :type '(string :tag "remote directory")) (defcustom proced-renice-command "renice" "Name of renice command." @@ -626,6 +630,9 @@ proced-mode Type \\[proced] to start a Proced session. In a Proced buffer type \\\\[proced-mark] to mark a process for later comma= nds. Type \\[proced-send-signal] to send signals to marked processes. +Type \\[proced-renice] to renice marked processes. +With a prefix argument \\[universal-argument], sending signals to and ren= icing of processes +will be performed with the credentials of `proced-remote-directory'. The initial content of a listing is defined by the variable `proced-filte= r' and the variable `proced-format'. @@ -1766,7 +1773,10 @@ proced-send-signal For backward compatibility SIGNAL and PROCESS-ALIST may be nil. Then PROCESS-ALIST contains the marked processes or the process point is = on and SIGNAL is queried interactively. This noninteractive usage is still -supported but discouraged. It will be removed in a future version of Ema= cs." +supported but discouraged. It will be removed in a future version of Ema= cs. + +With a prefix argument \\[universal-argument], send the signal with the c= redentials of +`proced-remote-directory'." (interactive (let* ((process-alist (proced-marked-processes)) (pnum (if (=3D 1 (length process-alist)) @@ -1808,7 +1818,10 @@ proced-send-signal proced-signal-list nil nil nil nil "TERM")))))) - (let (failures) + (let ((default-directory + (if (and current-prefix-arg (stringp proced-remote-directory)) + proced-remote-directory temporary-file-directory)) + failures) ;; Why not always use `signal-process'? See ;; https://lists.gnu.org/r/emacs-devel/2008-03/msg02955.html (if (functionp proced-signal-function) @@ -1821,7 +1834,8 @@ proced-send-signal (dolist (process process-alist) (condition-case err (unless (zerop (funcall - proced-signal-function (car process) sign= al)) + proced-signal-function (car process) sign= al + (file-remote-p default-directory))) (proced-log "%s\n" (cdr process)) (push (cdr process) failures)) (error ; catch errors from failed signals @@ -1833,7 +1847,7 @@ proced-send-signal (dolist (process process-alist) (with-temp-buffer (condition-case nil - (unless (zerop (call-process + (unless (zerop (process-file proced-signal-function nil t nil signal (number-to-string (car process)))) (proced-log (current-buffer)) @@ -1862,7 +1876,10 @@ proced-renice Interactively, PROCESS-ALIST contains the marked processes. If no process is marked, it contains the process point is on, After renicing all processes in PROCESS-ALIST, this command runs -the normal hook `proced-after-send-signal-hook'." +the normal hook `proced-after-send-signal-hook'. + +With a prefix argument \\[universal-argument], apply renice with the cred= entials of +`proced-remote-directory'." (interactive (let ((process-alist (proced-marked-processes))) (proced-with-processes-buffer process-alist @@ -1871,11 +1888,14 @@ proced-renice proced-mode) (if (numberp priority) (setq priority (number-to-string priority))) - (let (failures) + (let ((default-directory + (if (and current-prefix-arg (stringp proced-remote-directory)) + proced-remote-directory temporary-file-directory)) + failures) (dolist (process process-alist) (with-temp-buffer (condition-case nil - (unless (zerop (call-process + (unless (zerop (process-file proced-renice-command nil t nil priority (number-to-string (car process)))) (proced-log (current-buffer)) diff --git a/src/process.c b/src/process.c index 993e1c5603..fcff9c71ac 100644 =2D-- a/src/process.c +++ b/src/process.c @@ -7034,14 +7034,13 @@ abbr_to_signal (char const *name) return -1; } -DEFUN ("signal-process", Fsignal_process, Ssignal_process, - 2, 2, "sProcess (name or number): \nnSignal code: ", - doc: /* Send PROCESS the signal with code SIGCODE. -PROCESS may also be a number specifying the process id of the -process to signal; in this case, the process need not be a child of -this Emacs. -SIGCODE may be an integer, or a symbol whose name is a signal name. */) - (Lisp_Object process, Lisp_Object sigcode) +DEFUN ("internal-default-signal-process", + Finternal_default_signal_process, + Sinternal_default_signal_process, 2, 3, 0, + doc: /* Default function to send PROCESS the signal with code SIGC= ODE. +It shall be the last element in list `signal-process-functions'. +See function `signal-process' for more details on usage. */) + (Lisp_Object process, Lisp_Object sigcode, Lisp_Object remote) { pid_t pid; int signo; @@ -7091,6 +7090,21 @@ DEFUN ("signal-process", Fsignal_process, Ssignal_p= rocess, return make_fixnum (kill (pid, signo)); } +DEFUN ("signal-process", Fsignal_process, Ssignal_process, + 2, 3, "sProcess (name or number): \nnSignal code: ", + doc: /* Send PROCESS the signal with code SIGCODE. +PROCESS may also be a number specifying the process id of the +process to signal; in this case, the process need not be a child of +this Emacs. Furthermore, if REMOTE is a remote file name, this +number is interpreted as process id on the respective remote +host, which will be the process to signal. +SIGCODE may be an integer, or a symbol whose name is a signal name. */) + (Lisp_Object process, Lisp_Object sigcode, Lisp_Object remote) +{ + return CALLN (Frun_hook_with_args_until_success, Qsignal_process_functi= ons, + process, sigcode, remote); +} + DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0, doc: /* Make PROCESS see end-of-file in its input. EOF comes after any text already sent to it. @@ -8580,6 +8594,13 @@ syms_of_process (void) returns non-nil. */); Vinterrupt_process_functions =3D list1 (Qinternal_default_interrupt_pro= cess); + DEFVAR_LISP ("signal-process-functions", Vsignal_process_functions, + doc: /* List of functions to be called for `signal-process'. +The arguments of the functions are the same as for `signal-process'. +These functions are called in the order of the list, until one of them +returns non-nil. */); + Vsignal_process_functions =3D list1 (Qinternal_default_signal_process); + DEFVAR_LISP ("internal--daemon-sockname", Vinternal__daemon_sockname, doc: /* Name of external socket passed to Emacs, or nil if none. = */); Vinternal__daemon_sockname =3D Qnil; @@ -8600,6 +8621,10 @@ syms_of_process (void) "internal-default-interrupt-process"); DEFSYM (Qinterrupt_process_functions, "interrupt-process-functions"); + DEFSYM (Qinternal_default_signal_process, + "internal-default-signal-process"); + DEFSYM (Qsignal_process_functions, "signal-process-functions"); + DEFSYM (Qnull, "null"); DEFSYM (Qpipe_process_p, "pipe-process-p"); @@ -8654,6 +8679,7 @@ syms_of_process (void) defsubr (&Scontinue_process); defsubr (&Sprocess_running_child_p); defsubr (&Sprocess_send_eof); + defsubr (&Sinternal_default_signal_process); defsubr (&Ssignal_process); defsubr (&Swaiting_for_user_input_p); defsubr (&Sprocess_type); --=-=-=--