diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-07-15 01:50:30 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-07-15 01:50:30 +0800 |
commit | 794bc489206ab19a6f819f2fdf477fbcf8109d23 (patch) | |
tree | 7e4f90f56d6d9e4d8732a21d48f9132d8f702203 /modules | |
parent | 0d3c32b33cdac3ef36aeb6c42cbed1bd7df8f91d (diff) | |
download | gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.tar gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.tar.gz gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.tar.bz2 gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.tar.lz gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.tar.xz gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.tar.zst gsoc2013-evolution-794bc489206ab19a6f819f2fdf477fbcf8109d23.zip |
SpamAssassin: Try harder to kill spamd on exit.
References to EMailSession are leaking like crazy, so the module's
finalize() method never gets called, and we never kill our spamd.
Until I can track down all the reference leaks, kill the spamd process
in response to a "EShell::prepare-for-quit" signal instead of from the
module's finalize() method. (Maybe that's a better long-term solution
anyway?)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/spamassassin/evolution-spamassassin.c | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/modules/spamassassin/evolution-spamassassin.c b/modules/spamassassin/evolution-spamassassin.c index 1fcd369592..10cb3083a6 100644 --- a/modules/spamassassin/evolution-spamassassin.c +++ b/modules/spamassassin/evolution-spamassassin.c @@ -23,6 +23,7 @@ #include <camel/camel.h> +#include <shell/e-shell.h> #include <e-util/e-mktemp.h> #include <e-util/gconf-bridge.h> #include <mail/e-mail-junk-filter.h> @@ -512,6 +513,49 @@ spam_assassin_test_spamd_running (ESpamAssassin *extension, return (exit_code == 0); } +static void +spam_assassin_kill_our_own_daemon (ESpamAssassin *extension) +{ + gint pid; + gchar *contents = NULL; + GError *error = NULL; + + g_mutex_lock (extension->socket_path_mutex); + + g_free (extension->socket_path); + extension->socket_path = NULL; + + g_mutex_unlock (extension->socket_path_mutex); + + if (extension->pid_file == NULL) + return; + + g_file_get_contents (extension->pid_file, &contents, NULL, &error); + + if (error != NULL) { + g_warn_if_fail (contents == NULL); + g_warning ("%s", error->message); + g_error_free (error); + return; + } + + g_return_if_fail (contents != NULL); + + pid = atoi (contents); + g_free (contents); + + if (pid > 0 && kill (pid, SIGTERM) == 0) + waitpid (pid, NULL, 0); +} + +static void +spam_assassin_prepare_for_quit (EShell *shell, + EActivity *activity, + ESpamAssassin *extension) +{ + spam_assassin_kill_our_own_daemon (extension); +} + static gboolean spam_assassin_start_our_own_daemon (ESpamAssassin *extension) { @@ -571,6 +615,15 @@ spam_assassin_start_our_own_daemon (ESpamAssassin *extension) g_free (extension->socket_path); extension->socket_path = socket_path; socket_path = NULL; + + /* XXX EMailSession is too prone to reference leaks to leave + * this for our finalize() method. We want to be sure to + * kill the spamd process we started when Evolution shuts + * down, so connect to an EShell signal instead. */ + g_signal_connect ( + e_shell_get_default (), "prepare-for-quit", + G_CALLBACK (spam_assassin_prepare_for_quit), + extension); } exit: @@ -583,41 +636,6 @@ exit: } static void -spam_assassin_kill_our_own_daemon (ESpamAssassin *extension) -{ - gint pid; - gchar *contents = NULL; - GError *error = NULL; - - g_mutex_lock (extension->socket_path_mutex); - - g_free (extension->socket_path); - extension->socket_path = NULL; - - g_mutex_unlock (extension->socket_path_mutex); - - if (extension->pid_file == NULL) - return; - - g_file_get_contents (extension->pid_file, &contents, NULL, &error); - - if (error != NULL) { - g_warn_if_fail (contents == NULL); - g_warning ("%s", error->message); - g_error_free (error); - return; - } - - g_return_if_fail (contents != NULL); - - pid = atoi (contents); - g_free (contents); - - if (pid > 0 && kill (pid, SIGTERM) == 0) - waitpid (pid, NULL, 0); -} - -static void spam_assassin_test_spamd (ESpamAssassin *extension) { const gchar *spamd_binary; @@ -764,9 +782,6 @@ spam_assassin_finalize (GObject *object) { ESpamAssassin *extension = E_SPAM_ASSASSIN (object); - /* If we started our own daemon, kill it. */ - spam_assassin_kill_our_own_daemon (extension); - g_mutex_free (extension->socket_path_mutex); g_free (extension->pid_file); |