diff options
author | Christian Hammond <chipx86@chipx86.com> | 2005-07-27 08:50:35 +0000 |
---|---|---|
committer | Christian Hammond <chipx86@chipx86.com> | 2005-07-27 08:50:35 +0000 |
commit | bd4f01f03312a34aae2f0f6b489c4f3cc2f87461 (patch) | |
tree | 470456f36c55c651a1a986cf498cf6ba1dc8cf8e | |
parent | be828ca9ce2710aaa9a1810981b945e9fffc5445 (diff) | |
download | libnotify-bd4f01f03312a34aae2f0f6b489c4f3cc2f87461.tar.gz |
Handle SIGINT and SIGTERM When raised, we call notify_uninit. notify_uninit now checks if there are any non-expiring notifications and closes them. This is a best-effort to preventing stale notifications from a dead process from displaying on the screen. Of course, we can't handle SIGKILL, so we're stuck there.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | libnotify/notify.c | 33 |
2 files changed, 38 insertions, 4 deletions
@@ -1,3 +1,12 @@ +Wed Jul 27 01:47:25 PDT 2005 Christian Hammond <chipx86@chipx86.com> + + * libnotify/notify.c: + - Handle SIGINT and SIGTERM When raised, we call notify_uninit. + notify_uninit now checks if there are any non-expiring notifications + and closes them. This is a best-effort to preventing stale + notifications from a dead process from displaying on the screen. Of + course, we can't handle SIGKILL, so we're stuck there. + Wed Jul 27 01:13:12 PDT 2005 Christian Hammond <chipx86@chipx86.com> * libnotify/notify.c: diff --git a/libnotify/notify.c b/libnotify/notify.c index 27450eb..54239ab 100644 --- a/libnotify/notify.c +++ b/libnotify/notify.c @@ -34,6 +34,7 @@ #include <dbus/dbus.h> #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> @@ -48,6 +49,7 @@ struct _NotifyHandle guint32 id; guint32 replaces; + gboolean expires; gpointer user_data; @@ -325,6 +327,22 @@ _notify_disconnect(void) _dbus_conn = NULL; } +static void +sig_handler(int sig) +{ + static volatile sig_atomic_t in_progress = 0; + + if (in_progress) + raise(sig); + + in_progress = 1; + + notify_uninit(); + + signal(sig, SIG_DFL); + raise(sig); +} + gboolean notify_init(const char *app_name) { @@ -348,9 +366,9 @@ notify_init(const char *app_name) _handles = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, (GFreeFunc)_notify_handle_destroy); -#ifdef HAVE_ATEXIT - atexit(notify_uninit); -#endif /* HAVE_ATEXIT */ + g_atexit(notify_uninit); + signal(SIGINT, sig_handler); + signal(SIGTERM, sig_handler); _initted = TRUE; @@ -368,10 +386,16 @@ notify_glib_init(const char *app_name, GMainContext *context) return TRUE; } +static void +foreach_handle(int *id, NotifyHandle *handle, gpointer user_data) +{ + if (!handle->expires) + notify_close(handle); +} + void notify_uninit(void) { - _init_ref_count--; if (_init_ref_count != 0) @@ -385,6 +409,7 @@ notify_uninit(void) if (_handles != NULL) { + g_hash_table_foreach(_handles, (GHFunc)foreach_handle, NULL); g_hash_table_destroy(_handles); _handles = NULL; } |