server: re-introduce signal handler

This still needed to be ported from the old server code.
This commit is contained in:
Dirk-Jan C. Binnema 2020-02-04 01:04:28 +02:00
parent 029a4c245e
commit 3fc2a5f3f8
2 changed files with 33 additions and 5 deletions

View File

@ -24,6 +24,7 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <algorithm> #include <algorithm>
#include <atomic>
#include <glib.h> #include <glib.h>
#include <glib/gprintf.h> #include <glib/gprintf.h>
@ -63,6 +64,33 @@ using namespace Sexp;
using DocId = unsigned; using DocId = unsigned;
static std::atomic<bool> MuTerminate{false};
static void
sig_handler (int sig)
{
MuTerminate = true;
}
static void
install_sig_handler (void)
{
struct sigaction action;
int i, sigs[] = { SIGINT, SIGHUP, SIGTERM, SIGPIPE };
MuTerminate = false;
action.sa_handler = sig_handler;
sigemptyset(&action.sa_mask);
action.sa_flags = SA_RESETHAND;
for (i = 0; i != G_N_ELEMENTS(sigs); ++i)
if (sigaction (sigs[i], &action, NULL) != 0)
g_critical ("set sigaction for %d failed: %s",
sigs[i], strerror (errno));;
}
struct Context { struct Context {
Context() {} Context() {}
Context (MuStore *storearg): store{storearg} { Context (MuStore *storearg): store{storearg} {
@ -754,6 +782,9 @@ help_handler (Context& context, const Parameters& params)
static MuError static MuError
index_msg_cb (MuIndexStats *stats, void *user_data) index_msg_cb (MuIndexStats *stats, void *user_data)
{ {
if (MuTerminate)
return MU_STOP;
if (stats->_processed % 1000) if (stats->_processed % 1000)
return MU_OK; return MU_OK;

View File

@ -277,9 +277,9 @@ Start the process if needed."
(when proc (when proc
(let ((delete-exited-processes t)) (let ((delete-exited-processes t))
(mu4e~call-mu '(quit))) (mu4e~call-mu '(quit)))
;; try sending SIGINT (C-c) to process, so it can exit gracefully ;; try sending SIGINT (C-c) to process, so it can exit gracefully
(ignore-errors (ignore-errors
(signal-process proc 'SIGINT)))) (signal-process proc 'SIGINT))))
(setq (setq
mu4e~proc-process nil mu4e~proc-process nil
mu4e~proc-buf nil)) mu4e~proc-buf nil))
@ -405,7 +405,6 @@ MY-ADDRESSES is a list of 'my' email addresses (see
:cleanup ,cleanup :cleanup ,cleanup
:lazy-check ,lazy-check))) :lazy-check ,lazy-check)))
(defun mu4e~proc-mkdir (path) (defun mu4e~proc-mkdir (path)
"Create a new maildir-directory at filesystem PATH." "Create a new maildir-directory at filesystem PATH."
;;(mu4e~proc-send-command "cmd:mkdir path:%s" (mu4e~escape path)) ;;(mu4e~proc-send-command "cmd:mkdir path:%s" (mu4e~escape path))
@ -469,7 +468,6 @@ Returns either (:update ... ) or (:error ) sexp, which are handled my
:rename ,(and maildir mu4e-change-filenames-when-moving) :rename ,(and maildir mu4e-change-filenames-when-moving)
:noview ,no-view)))) :noview ,no-view))))
(defun mu4e~proc-ping (&optional queries) (defun mu4e~proc-ping (&optional queries)
"Sends a ping to the mu server, expecting a (:pong ...) in response. "Sends a ping to the mu server, expecting a (:pong ...) in response.
QUERIES is a list of queries for the number of results with read/unread status QUERIES is a list of queries for the number of results with read/unread status
@ -513,6 +511,5 @@ result will be delivered to the function registered as
:images ,images :images ,images
:decrypt ,decrypt))) :decrypt ,decrypt)))
(provide 'mu4e-proc) (provide 'mu4e-proc)
;;; mu4e-proc.el ends here ;;; mu4e-proc.el ends here