Skip to content

Commit

Permalink
attempt handling invalid bus address settings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acrisci committed May 1, 2019
1 parent 6a2b026 commit 2330b64
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
35 changes: 25 additions & 10 deletions playerctl/playerctl-player-manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions playerctl/playerctl-player.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 2330b64

Please sign in to comment.