[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/sweeprolog 68db64e554 2/3: Handle SIGHUP in daemon mode wh
|
From: |
ELPA Syncer |
|
Subject: |
[nongnu] elpa/sweeprolog 68db64e554 2/3: Handle SIGHUP in daemon mode when killing a tty top-level |
|
Date: |
Thu, 9 Nov 2023 16:00:14 -0500 (EST) |
branch: elpa/sweeprolog
commit 68db64e554fa7e551d1c3e561b1ce9aa15a02aaf
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>
Handle SIGHUP in daemon mode when killing a tty top-level
When Emacs is running as a daemon, and deletes the process of a
top-level that uses a tty, the top-level receives SIGHUP. But since
the top-level is a thread is the same process as Emacs itself, this
results in 'kill-emacs'. To prevent this unfortunate outcome, set a
no-op handler for SIGHUP before deleting the top-level process and
restore the original handler afterwards.
* sweep.pl (sweep_nohup/2): New predicate.
* sweeprolog.el (sweeprolog-top-level-filter): New function.
(sweeprolog-top-level-buffer): Use it.
---
sweep.pl | 6 +++++-
sweeprolog.el | 22 ++++++++++++++--------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/sweep.pl b/sweep.pl
index 954b3b501a..51ebf4d48d 100644
--- a/sweep.pl
+++ b/sweep.pl
@@ -106,7 +106,8 @@
sweep_options_collection/2,
sweep_option_arguments_collection/2,
sweep_functions_collection/2,
- sweep_function_functors_collection/2
+ sweep_function_functors_collection/2,
+ sweep_nohup/2
]).
:- use_module(library(pldoc)).
@@ -2179,3 +2180,6 @@ sweep_extract_lambda_1(Clause, ClauseVarNames, Func,
Shared, Args, GoalPos, Offs
-> Exists = "true"
; Exists = []
).
+
+sweep_nohup(1, _) :- on_signal(hup, _, atom).
+sweep_nohup(0, _) :- on_signal(hup, _, default).
diff --git a/sweeprolog.el b/sweeprolog.el
index 3387a0fdd5..02246c65e1 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -3415,6 +3415,19 @@ function with PROC and MSG."
#'sweeprolog-top-level-sentinel)
(add-hook 'kill-buffer-hook #'comint-write-input-ring nil t)))
+(defun sweeprolog-top-level-filter (process string)
+ (let ((sweeprolog-top-level-output-filter t))
+ (comint-output-filter process string))
+ (when (string-match (rx "Sweep top-level thread exited") string)
+ (with-current-buffer (process-buffer process)
+ (setq sweeprolog-top-level-thread-id nil))
+ (if (or (eq (process-type process) 'network)
+ (not (daemonp)))
+ (delete-process process)
+ (sweeprolog--query-once "sweep" "sweep_nohup" 1)
+ (delete-process process)
+ (sweeprolog--query-once "sweep" "sweep_nohup" 0))))
+
(defun sweeprolog-top-level-buffer (&optional name)
"Return a Prolog top-level buffer named NAME.
@@ -3447,14 +3460,7 @@ top-level."
sweeprolog-prolog-server-port))
(sweeprolog--query-once "sweep"
"sweep_accept_top_level_client" nil)))
(let ((proc (get-buffer-process buf)))
- (set-process-filter proc
- (lambda (process string)
- (let ((sweeprolog-top-level-output-filter t))
- (comint-output-filter process string))
- (when (string-match (rx "Sweep top-level
thread exited") string)
- (delete-process process)
- (with-current-buffer buf
- (setq sweeprolog-top-level-thread-id
nil)))))
+ (set-process-filter proc #'sweeprolog-top-level-filter)
(unless comint-last-prompt buf (accept-process-output proc 1))
(set-process-query-on-exit-flag proc nil)
(setq-local comint-input-ring-file-name