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:
@@ -374,8 +374,13 @@ static gboolean playerctl_player_manager_initable_init(GInitable *initable,
|
|||||||
"org.freedesktop.DBus", NULL,
|
"org.freedesktop.DBus", NULL,
|
||||||
&tmp_error);
|
&tmp_error);
|
||||||
if (tmp_error != NULL) {
|
if (tmp_error != NULL) {
|
||||||
g_propagate_error(error, tmp_error);
|
if (tmp_error->domain == G_IO_ERROR && tmp_error->code == G_IO_ERROR_NOT_FOUND) {
|
||||||
return FALSE;
|
// 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 =
|
manager->priv->system_proxy =
|
||||||
g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
|
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,
|
"org.freedesktop.DBus", NULL,
|
||||||
&tmp_error);
|
&tmp_error);
|
||||||
if (tmp_error != NULL) {
|
if (tmp_error != NULL) {
|
||||||
g_propagate_error(error, tmp_error);
|
if (tmp_error->domain == G_IO_ERROR && tmp_error->code == G_IO_ERROR_NOT_FOUND) {
|
||||||
return FALSE;
|
// 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);
|
manager->priv->player_names = playerctl_list_players(&tmp_error);
|
||||||
@@ -395,12 +405,17 @@ static gboolean playerctl_player_manager_initable_init(GInitable *initable,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_signal_connect(G_DBUS_PROXY(manager->priv->session_proxy), "g-signal",
|
if (manager->priv->session_proxy) {
|
||||||
G_CALLBACK(dbus_name_owner_changed_callback),
|
g_signal_connect(G_DBUS_PROXY(manager->priv->session_proxy), "g-signal",
|
||||||
manager);
|
G_CALLBACK(dbus_name_owner_changed_callback),
|
||||||
g_signal_connect(G_DBUS_PROXY(manager->priv->system_proxy), "g-signal",
|
manager);
|
||||||
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;
|
manager->priv->initted = TRUE;
|
||||||
|
|
||||||
|
@@ -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);
|
"/org/freedesktop/DBus", "org.freedesktop.DBus", NULL, &tmp_error);
|
||||||
|
|
||||||
if (tmp_error != NULL) {
|
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);
|
g_propagate_error(err, tmp_error);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1001,6 +1010,11 @@ static gboolean playerctl_player_initable_init(GInitable *initable,
|
|||||||
bus_name_for_player_name(player->priv->player_name,
|
bus_name_for_player_name(player->priv->player_name,
|
||||||
bus_types[i], &tmp_error);
|
bus_types[i], &tmp_error);
|
||||||
if (tmp_error != NULL) {
|
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);
|
g_propagate_error(err, tmp_error);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user