[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dtache 668f6aca83 157/158: Improve dtache-kill-session
From: |
ELPA Syncer |
Subject: |
[elpa] externals/dtache 668f6aca83 157/158: Improve dtache-kill-session |
Date: |
Wed, 19 Jan 2022 18:58:10 -0500 (EST) |
branch: externals/dtache
commit 668f6aca83405a68a6e6f27eed483af58b85f55f
Author: Niklas Eklund <niklas.eklund@posteo.net>
Commit: Niklas Eklund <niklas.eklund@posteo.net>
Improve dtache-kill-session
Simplify the underlying detection of the session's pid and child
pids. This patch should work on remote hosts as well as local hosts.
---
dtache.el | 41 ++++++++++++++++-------------------------
test/dtache-test.el | 11 -----------
2 files changed, 16 insertions(+), 36 deletions(-)
diff --git a/dtache.el b/dtache.el
index 1961d592e9..e3da9e07e2 100644
--- a/dtache.el
+++ b/dtache.el
@@ -380,7 +380,8 @@ Optionally SUPPRESS-OUTPUT."
(interactive
(list (dtache-completing-read (dtache-get-sessions))))
(when (dtache-valid-session session)
- (let* ((pid (dtache--session-pid session)))
+ (let* ((default-directory (dtache--session-directory session))
+ (pid (dtache--session-pid session)))
(when pid
(dtache--kill-processes pid)))))
@@ -751,29 +752,17 @@ Optionally CONCAT the command return command into a
string."
(defun dtache--session-pid (session)
"Return SESSION's pid."
(let* ((socket
- (concat
- (dtache--session-directory session)
- (symbol-name (dtache--session-id session))
- ".socket"))
- (regexp (rx-to-string `(and "dtach " (or "-n " "-c ") ,socket)))
- (ps-args '("aux" "-w")))
- (with-temp-buffer
- (apply #'process-file `("ps" nil t nil ,@ps-args))
- (goto-char (point-min))
- (when (search-forward-regexp regexp nil t)
- (elt (split-string (thing-at-point 'line) " " t) 1)))))
-
-(defun dtache--session-child-pids (pid)
- "Return a list of pids for all child processes including PID."
- (let ((pids `(,pid))
- (child-processes
- (split-string
- (shell-command-to-string (format "pgrep -P %s" pid))
- "\n" t)))
- (seq-do (lambda (pid)
- (push (dtache--session-child-pids pid) pids))
- child-processes)
- pids))
+ (expand-file-name
+ (concat (symbol-name (dtache--session-id session)) ".socket")
+ (or
+ (file-remote-p default-directory 'localname)
+ default-directory))))
+ (car
+ (split-string
+ (with-temp-buffer
+ (apply #'process-file `("pgrep" nil t nil "-f" ,(shell-quote-argument
(format "dtach -. %s" socket))))
+ (buffer-string))
+ "\n" t))))
(defun dtache--session-truncate-command (session)
"Return a truncated string representation of SESSION's command."
@@ -1033,7 +1022,9 @@ Optionally make the path LOCAL to host."
"Kill PID and all of its children."
(let ((child-processes
(split-string
- (shell-command-to-string (format "pgrep -P %s" pid))
+ (with-temp-buffer
+ (apply #'process-file `("pgrep" nil t nil "-P" ,pid))
+ (buffer-string))
"\n" t)))
(seq-do (lambda (pid) (dtache--kill-processes pid)) child-processes)
(apply #'process-file `("kill" nil nil nil ,pid))))
diff --git a/test/dtache-test.el b/test/dtache-test.el
index 68822aadae..c8f499d71f 100644
--- a/test/dtache-test.el
+++ b/test/dtache-test.el
@@ -242,17 +242,6 @@
(should (dtache-attachable-command-p "cd"))
(should (not (dtache-attachable-command-p "ls -la")))))
-(ert-deftest dtache-test-session-pid ()
- (cl-letf* (((symbol-function #'process-file) (lambda (_program _infile
_buffer _display &rest _args)
- (insert "\"USER PID
%CPU %MEM VSZ RSS TTY STAT START TIME COMMAND\nuser 6699 0.0
0.0 4752 2304 ? Ss 13:06 0:00 dtach -n /tmp/foo.socket\nuser
6698 0.0 0.0 4752 2304 ? Ss 13:07 0:00 dtach -c
/tmp/bar.socket\n")))
-
- (session1 (dtache--session-create :id 'foo :directory "/tmp/"))
- (session2 (dtache--session-create :id 'bar :directory "/tmp/"))
- (session3 (dtache--session-create :id 'baz :directory "/tmp/")))
- (should (string= "6699" (dtache--session-pid session1)))
- (should (string= "6698" (dtache--session-pid session2)))
- (should (not (dtache--session-pid session3)))))
-
;;;;; String representations
(ert-deftest dtache-test-duration-str ()
- [elpa] externals/dtache 2354197acb 096/158: Fix error in dtache-compile, (continued)
- [elpa] externals/dtache 2354197acb 096/158: Fix error in dtache-compile, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 5da693be75 100/158: Update CHANGELOG, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 0c8241a33d 107/158: Update actions from defvar to defcustom, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 848f3a943a 108/158: Update attach naming, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 52c82428ac 110/158: Remove documentation directory, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 9f948349a3 112/158: Rename dtache-detach to dtache-detach-dwim, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4c47fa3ddb 122/158: Fix error in dtache-attach, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 71d7e3ad35 119/158: Update how duration is determined, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 5d78cfb3b3 142/158: Add attach command, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 94f207eeeb 149/158: Make dtache utilize notifications library, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 668f6aca83 157/158: Improve dtache-kill-session,
ELPA Syncer <=
- [elpa] externals/dtache e3af56003d 063/158: Remove unnecessary header declarations, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache dd9c2a0095 066/158: Add contributions section in README, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 59f2ac4ab5 084/158: Rename dtache--dtach-mode to dtache-session-mode, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 1cbeb7167e 136/158: Rename magic-command to dtache-command, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 954b642659 074/158: Demote attach commands to functions, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4778eda4df 085/158: Rename compile-session to post-compile-session, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 06cb91da1d 097/158: Make dtache-session-directory have a default value, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 4284951870 103/158: Make dtache-delete-sessions a command, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache f34f5b8a24 105/158: Harmonize function names, ELPA Syncer, 2022/01/19
- [elpa] externals/dtache 9756c43885 114/158: Improve dtache header, ELPA Syncer, 2022/01/19