diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index 985f7366..17bb14c3 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,33 @@ using namespace Sexp; using DocId = unsigned; +static std::atomic 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 { Context() {} Context (MuStore *storearg): store{storearg} { @@ -754,6 +782,9 @@ help_handler (Context& context, const Parameters& params) static MuError index_msg_cb (MuIndexStats *stats, void *user_data) { + if (MuTerminate) + return MU_STOP; + if (stats->_processed % 1000) return MU_OK; diff --git a/mu4e/mu4e-proc.el b/mu4e/mu4e-proc.el index 66768283..357d6451 100644 --- a/mu4e/mu4e-proc.el +++ b/mu4e/mu4e-proc.el @@ -277,9 +277,9 @@ Start the process if needed." (when proc (let ((delete-exited-processes t)) (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 - (signal-process proc 'SIGINT)))) + (signal-process proc 'SIGINT)))) (setq mu4e~proc-process nil mu4e~proc-buf nil)) @@ -405,7 +405,6 @@ MY-ADDRESSES is a list of 'my' email addresses (see :cleanup ,cleanup :lazy-check ,lazy-check))) - (defun mu4e~proc-mkdir (path) "Create a new maildir-directory at filesystem 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) :noview ,no-view)))) - (defun mu4e~proc-ping (&optional queries) "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 @@ -513,6 +511,5 @@ result will be delivered to the function registered as :images ,images :decrypt ,decrypt))) - (provide 'mu4e-proc) ;;; mu4e-proc.el ends here