attempt handling invalid bus address settings

If the bus address is set to an invalid path, we will get the file not
found error from GIO when connecting to a bus. This might occur very
rarely in environments where there is no system bus (like my test
environment currently) or where the user has set the
DBUS_SESSION_BUS_ADDRESS environment variable to an incorrect value. I
don't believe the first case will ever occur for a normal user, and in
the second case, it is almost certainly user error. So we might just
settle on logging a warning and pretending the bus doesn't exist.
This commit is contained in:
Tony Crisci
2019-05-01 00:57:12 -04:00
parent 6a2b026d0a
commit 2330b64ff9
2 changed files with 39 additions and 10 deletions

View File

@@ -374,8 +374,13 @@ static gboolean playerctl_player_manager_initable_init(GInitable *initable,
"org.freedesktop.DBus", NULL,
&tmp_error);
if (tmp_error != NULL) {
g_propagate_error(error, tmp_error);
return FALSE;
if (tmp_error->domain == G_IO_ERROR && tmp_error->code == G_IO_ERROR_NOT_FOUND) {
// TODO the bus address was set incorrectly so log a warning
g_clear_error(&tmp_error);
} else {
g_propagate_error(error, tmp_error);
return FALSE;
}
}
manager->priv->system_proxy =
g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
@@ -385,8 +390,13 @@ static gboolean playerctl_player_manager_initable_init(GInitable *initable,
"org.freedesktop.DBus", NULL,
&tmp_error);
if (tmp_error != NULL) {
g_propagate_error(error, tmp_error);
return FALSE;
if (tmp_error->domain == G_IO_ERROR && tmp_error->code == G_IO_ERROR_NOT_FOUND) {
// TODO the bus address was set incorrectly so log a warning
g_clear_error(&tmp_error);
} else {
g_propagate_error(error, tmp_error);
return FALSE;
}
}
manager->priv->player_names = playerctl_list_players(&tmp_error);
@@ -395,12 +405,17 @@ static gboolean playerctl_player_manager_initable_init(GInitable *initable,
return FALSE;
}
g_signal_connect(G_DBUS_PROXY(manager->priv->session_proxy), "g-signal",
G_CALLBACK(dbus_name_owner_changed_callback),
manager);
g_signal_connect(G_DBUS_PROXY(manager->priv->system_proxy), "g-signal",
G_CALLBACK(dbus_name_owner_changed_callback),
manager);
if (manager->priv->session_proxy) {
g_signal_connect(G_DBUS_PROXY(manager->priv->session_proxy), "g-signal",
G_CALLBACK(dbus_name_owner_changed_callback),
manager);
}
if (manager->priv->system_proxy) {
g_signal_connect(G_DBUS_PROXY(manager->priv->system_proxy), "g-signal",
G_CALLBACK(dbus_name_owner_changed_callback),
manager);
}
manager->priv->initted = TRUE;

View File

@@ -859,6 +859,15 @@ static GList *list_player_names_on_bus(GBusType bus_type, GError **err) {
"/org/freedesktop/DBus", "org.freedesktop.DBus", NULL, &tmp_error);
if (tmp_error != NULL) {
if (tmp_error->domain == G_IO_ERROR && tmp_error->code == G_IO_ERROR_NOT_FOUND) {
// XXX: This means the dbus socket address is not found which may
// mean that the bus is not running or the address was set
// incorrectly. I think we can pass through here because it is true
// that there are no names on the bus that is supposed to be at
// this socket path. But we need a better way of dealing with this case.
g_clear_error(&tmp_error);
return NULL;
}
g_propagate_error(err, tmp_error);
return NULL;
}
@@ -1001,6 +1010,11 @@ static gboolean playerctl_player_initable_init(GInitable *initable,
bus_name_for_player_name(player->priv->player_name,
bus_types[i], &tmp_error);
if (tmp_error != NULL) {
if (tmp_error->domain == G_IO_ERROR && tmp_error->code == G_IO_ERROR_NOT_FOUND) {
// TODO the bus address was set incorrectly so log a warning
g_clear_error(&tmp_error);
continue;
}
g_propagate_error(err, tmp_error);
return FALSE;
}