[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master de953a6fe3: Improve 'desktop--emacs-pid-running-p'
From: |
Eli Zaretskii |
Subject: |
master de953a6fe3: Improve 'desktop--emacs-pid-running-p' |
Date: |
Sat, 26 Mar 2022 03:29:53 -0400 (EDT) |
branch: master
commit de953a6fe39d8e547ce4d40f39cd2c10b71a1e3c
Author: Eli Zaretskii <eliz@gnu.org>
Commit: Eli Zaretskii <eliz@gnu.org>
Improve 'desktop--emacs-pid-running-p'
* lisp/desktop.el (desktop--emacs-pid-running-p): Avoid false
negatives on MS-Windows and with some symlinks to Emacs
executables. (Bug#1474)
---
lisp/desktop.el | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/lisp/desktop.el b/lisp/desktop.el
index 773f0f050f..7e3d66bdf1 100644
--- a/lisp/desktop.el
+++ b/lisp/desktop.el
@@ -673,10 +673,26 @@ DIRNAME omitted or nil means use `desktop-dirname'."
owner)))
(defun desktop--emacs-pid-running-p (pid)
- "Return t if an Emacs process with PID exists."
+ "Return non-nil if an Emacs process whose ID is PID might still be running."
(when-let ((attr (process-attributes pid)))
- (equal (alist-get 'comm attr)
- (file-name-nondirectory (car command-line-args)))))
+ (let ((proc-cmd (alist-get 'comm attr))
+ (my-cmd (file-name-nondirectory (car command-line-args)))
+ (case-fold-search t))
+ (or (equal proc-cmd my-cmd)
+ (and (eq system-type 'windows-nt)
+ (eq t (compare-strings proc-cmd
+ nil
+ (if (string-suffix-p ".exe" proc-cmd t)
+ -4)
+ my-cmd
+ nil
+ (if (string-suffix-p ".exe" my-cmd t)
+ -4))))
+ ;; We should err on the safe side here: if any of the
+ ;; executables is something like "emacs-nox" or "emacs-42.1"
+ ;; or "gemacs" or "xemacs", let's recognize them as well.
+ (and (string-match-p "emacs" proc-cmd)
+ (string-match-p "emacs" my-cmd))))))
(defun desktop--load-locked-desktop-p (owner)
"Return t if a locked desktop should be loaded.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master de953a6fe3: Improve 'desktop--emacs-pid-running-p',
Eli Zaretskii <=