From a6e9a3ec9e723e2d3af9121b6b2f91dd62c00c72 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Thu, 3 Jul 2014 00:06:47 +0200 Subject: add error handling to notify() --- journal-notify.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/journal-notify.c b/journal-notify.c index d3951ff..c524221 100644 --- a/journal-notify.c +++ b/journal-notify.c @@ -19,10 +19,29 @@ const char * program = NULL; #define OPTSTRING "ehi:m:nr:" #define DEFAULTICON "dialog-information" -void notify(const char * summary, const char * body, const char * icon) { - NotifyNotification * notification = notify_notification_new(summary, body, icon); - notify_notification_show(notification, NULL); +int notify(const char * summary, const char * body, const char * icon) { + NotifyNotification * notification; + int rc = -1; + + notification = +#if NOTIFY_CHECK_VERSION(0, 7, 0) + notify_notification_new(summary, body, icon); +#else + notify_notification_new(summary, body, icon, NULL); +#endif + + if (notification == NULL) + return rc; + + if (notify_notification_show(notification, NULL) == FALSE) + goto out; + + rc = 0; + +out: g_object_unref(G_OBJECT(notification)); + + return rc; } int main(int argc, char **argv) { @@ -144,10 +163,16 @@ int main(int argc, char **argv) { /* show notification */ if (have_regex > 0) { if (regexec(®ex, message, 0, NULL, 0) == 0) { - notify(summary, message, icon); + if ((rc = notify(summary, message, icon)) < 0) { + fprintf(stderr, "Failed to show notification.\n"); + goto out40; + } } } else { - notify(summary, message, icon); + if ((rc = notify(summary, message, icon)) < 0) { + fprintf(stderr, "Failed to show notification.\n"); + goto out40; + } } free(summary); -- cgit v1.2.3-54-g00ecf