Improve dbus error handling

* Improve error reporting to also include the glib error messages
* Call g_error_free after an error to avoid leaking memory.
This commit is contained in:
Nikos Tsipinakis 2017-02-20 18:04:24 +02:00
parent 37628f3dc4
commit f624c42432

View File

@ -354,7 +354,7 @@ static void on_get_server_information(GDBusConnection * connection,
void notification_closed(notification * n, int reason) void notification_closed(notification * n, int reason)
{ {
if (!dbus_conn) { if (!dbus_conn) {
fprintf(stderr, "ERROR: notification_closed but not (yet) connected\n"); fprintf(stderr, "ERROR: Tried to close notification but dbus connection not set!\n");
return; return;
} }
@ -368,7 +368,8 @@ void notification_closed(notification * n, int reason)
"NotificationClosed", body, &err); "NotificationClosed", body, &err);
if (err) { if (err) {
fprintf(stderr, "notification_closed ERROR\n"); fprintf(stderr, "Unable to close notification: %s\n", err->message);
g_error_free(err);
} }
} }
@ -385,7 +386,8 @@ void action_invoked(notification * n, const char *identifier)
"ActionInvoked", body, &err); "ActionInvoked", body, &err);
if (err) { if (err) {
fprintf(stderr, "ActionInvoked ERROR\n"); fprintf(stderr, "Unable to invoke action: %s\n", err->message);
g_error_free(err);
} }
} }
@ -398,15 +400,16 @@ static void on_bus_acquired(GDBusConnection * connection,
{ {
guint registration_id; guint registration_id;
GError *err = NULL;
registration_id = g_dbus_connection_register_object(connection, registration_id = g_dbus_connection_register_object(connection,
"/org/freedesktop/Notifications", "/org/freedesktop/Notifications",
introspection_data-> introspection_data->interfaces[0],
interfaces[0],
&interface_vtable, &interface_vtable,
NULL, NULL, NULL); NULL, NULL, &err);
if (registration_id <= 0) { if (registration_id == 0) {
fprintf(stderr, "Unable to register\n"); fprintf(stderr, "Unable to register dbus connection: %s\n", err->message);
exit(1); exit(1);
} }
} }