diff options
author | Christian Hesse <mail@eworm.de> | 2014-07-03 00:06:47 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2014-07-03 00:06:47 +0200 |
commit | a6e9a3ec9e723e2d3af9121b6b2f91dd62c00c72 (patch) | |
tree | c43a0d42c10f1002c7124fa3a5f3e9347c3f5b3b | |
parent | f24c0d1a1655d152d7a2ac07faa7ecf6119ac7c7 (diff) | |
download | journal-notify-a6e9a3ec9e723e2d3af9121b6b2f91dd62c00c72.tar.gz journal-notify-a6e9a3ec9e723e2d3af9121b6b2f91dd62c00c72.tar.zst |
add error handling to notify()
-rw-r--r-- | journal-notify.c | 35 |
1 files 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); |