|
|
7b8ed6 |
From d530d52df61731f1e36071a89e4d2a8719a3cfbf Mon Sep 17 00:00:00 2001
|
|
|
7b8ed6 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
7b8ed6 |
Date: Tue, 12 May 2020 10:12:26 -0400
|
|
|
7b8ed6 |
Subject: [PATCH] notify-send: Give failing exit code if showing notification
|
|
|
7b8ed6 |
fails
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
Right now notify-send will quietly return a successful exit status
|
|
|
7b8ed6 |
even if showing the notification fails.
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
This commit changes the behavior to instead fail on failure.
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
https://gitlab.gnome.org/GNOME/libnotify/-/merge_requests/13
|
|
|
7b8ed6 |
---
|
|
|
7b8ed6 |
tools/notify-send.c | 18 ++++++++++++++----
|
|
|
7b8ed6 |
1 file changed, 14 insertions(+), 4 deletions(-)
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
diff --git a/tools/notify-send.c b/tools/notify-send.c
|
|
|
7b8ed6 |
index c0b9eeb..f8d59de 100644
|
|
|
7b8ed6 |
--- a/tools/notify-send.c
|
|
|
7b8ed6 |
+++ b/tools/notify-send.c
|
|
|
7b8ed6 |
@@ -104,61 +104,61 @@ notify_notification_set_hint_variant (NotifyNotification *notification,
|
|
|
7b8ed6 |
N_("Invalid hint type \"%s\". Valid types "
|
|
|
7b8ed6 |
"are int, double, string and byte."),
|
|
|
7b8ed6 |
type);
|
|
|
7b8ed6 |
return FALSE;
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
if (conv_error) {
|
|
|
7b8ed6 |
*error = g_error_new (G_OPTION_ERROR,
|
|
|
7b8ed6 |
G_OPTION_ERROR_BAD_VALUE,
|
|
|
7b8ed6 |
N_("Value \"%s\" of hint \"%s\" could not be "
|
|
|
7b8ed6 |
"parsed as type \"%s\"."), value, key,
|
|
|
7b8ed6 |
type);
|
|
|
7b8ed6 |
return FALSE;
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
return TRUE;
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
int
|
|
|
7b8ed6 |
main (int argc, char *argv[])
|
|
|
7b8ed6 |
{
|
|
|
7b8ed6 |
static const char *summary = NULL;
|
|
|
7b8ed6 |
char *body;
|
|
|
7b8ed6 |
static const char *type = NULL;
|
|
|
7b8ed6 |
static char *app_name = NULL;
|
|
|
7b8ed6 |
static char *icon_str = NULL;
|
|
|
7b8ed6 |
static char *icons = NULL;
|
|
|
7b8ed6 |
static char **n_text = NULL;
|
|
|
7b8ed6 |
static char **hints = NULL;
|
|
|
7b8ed6 |
static gboolean do_version = FALSE;
|
|
|
7b8ed6 |
- static gboolean hint_error = FALSE;
|
|
|
7b8ed6 |
+ static gboolean hint_error = FALSE, show_error = FALSE;
|
|
|
7b8ed6 |
static glong expire_timeout = NOTIFY_EXPIRES_DEFAULT;
|
|
|
7b8ed6 |
GOptionContext *opt_ctx;
|
|
|
7b8ed6 |
NotifyNotification *notify;
|
|
|
7b8ed6 |
GError *error = NULL;
|
|
|
7b8ed6 |
gboolean retval;
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
static const GOptionEntry entries[] = {
|
|
|
7b8ed6 |
{"urgency", 'u', 0, G_OPTION_ARG_CALLBACK,
|
|
|
7b8ed6 |
g_option_arg_urgency_cb,
|
|
|
7b8ed6 |
N_("Specifies the urgency level (low, normal, critical)."),
|
|
|
7b8ed6 |
N_("LEVEL")},
|
|
|
7b8ed6 |
{"expire-time", 't', 0, G_OPTION_ARG_INT, &expire_timeout,
|
|
|
7b8ed6 |
N_
|
|
|
7b8ed6 |
("Specifies the timeout in milliseconds at which to expire the "
|
|
|
7b8ed6 |
"notification."), N_("TIME")},
|
|
|
7b8ed6 |
{"app-name", 'a', 0, G_OPTION_ARG_STRING, &app_name,
|
|
|
7b8ed6 |
N_("Specifies the app name for the icon"), N_("APP_NAME")},
|
|
|
7b8ed6 |
{"icon", 'i', 0, G_OPTION_ARG_FILENAME, &icons,
|
|
|
7b8ed6 |
N_("Specifies an icon filename or stock icon to display."),
|
|
|
7b8ed6 |
N_("ICON[,ICON...]")},
|
|
|
7b8ed6 |
{"category", 'c', 0, G_OPTION_ARG_FILENAME, &type,
|
|
|
7b8ed6 |
N_("Specifies the notification category."),
|
|
|
7b8ed6 |
N_("TYPE[,TYPE...]")},
|
|
|
7b8ed6 |
{"hint", 'h', 0, G_OPTION_ARG_FILENAME_ARRAY, &hints,
|
|
|
7b8ed6 |
N_
|
|
|
7b8ed6 |
("Specifies basic extra data to pass. Valid types are int, double, string and byte."),
|
|
|
7b8ed6 |
N_("TYPE:NAME:VALUE")},
|
|
|
7b8ed6 |
{"version", 'v', 0, G_OPTION_ARG_NONE, &do_version,
|
|
|
7b8ed6 |
N_("Version of the package."),
|
|
|
7b8ed6 |
NULL},
|
|
|
7b8ed6 |
@@ -242,39 +242,49 @@ main (int argc, char *argv[])
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
while ((hint = hints[i++])) {
|
|
|
7b8ed6 |
tokens = g_strsplit (hint, ":", -1);
|
|
|
7b8ed6 |
l = g_strv_length (tokens);
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
if (l != 3) {
|
|
|
7b8ed6 |
fprintf (stderr, "%s\n",
|
|
|
7b8ed6 |
N_("Invalid hint syntax specified. "
|
|
|
7b8ed6 |
"Use TYPE:NAME:VALUE."));
|
|
|
7b8ed6 |
hint_error = TRUE;
|
|
|
7b8ed6 |
} else {
|
|
|
7b8ed6 |
retval = notify_notification_set_hint_variant (notify,
|
|
|
7b8ed6 |
tokens[0],
|
|
|
7b8ed6 |
tokens[1],
|
|
|
7b8ed6 |
tokens[2],
|
|
|
7b8ed6 |
&error);
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
if (!retval) {
|
|
|
7b8ed6 |
fprintf (stderr, "%s\n", error->message);
|
|
|
7b8ed6 |
g_error_free (error);
|
|
|
7b8ed6 |
hint_error = TRUE;
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
g_strfreev (tokens);
|
|
|
7b8ed6 |
if (hint_error)
|
|
|
7b8ed6 |
break;
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
- if (!hint_error)
|
|
|
7b8ed6 |
- notify_notification_show (notify, NULL);
|
|
|
7b8ed6 |
+ if (!hint_error) {
|
|
|
7b8ed6 |
+ retval = notify_notification_show (notify, &error);
|
|
|
7b8ed6 |
+
|
|
|
7b8ed6 |
+ if (!retval) {
|
|
|
7b8ed6 |
+ fprintf (stderr, "%s\n", error->message);
|
|
|
7b8ed6 |
+ g_error_free (error);
|
|
|
7b8ed6 |
+ show_error = TRUE;
|
|
|
7b8ed6 |
+ }
|
|
|
7b8ed6 |
+ }
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
g_object_unref (G_OBJECT (notify));
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
notify_uninit ();
|
|
|
7b8ed6 |
|
|
|
7b8ed6 |
- exit (hint_error);
|
|
|
7b8ed6 |
+ if (hint_error || show_error)
|
|
|
7b8ed6 |
+ exit (1);
|
|
|
7b8ed6 |
+
|
|
|
7b8ed6 |
+ return 0;
|
|
|
7b8ed6 |
}
|
|
|
7b8ed6 |
--
|
|
|
7b8ed6 |
2.32.0
|
|
|
7b8ed6 |
|