Skip to content

Commit

Permalink
Emit ControllerAddress changed signal in SwitchController method
Browse files Browse the repository at this point in the history
The changed signal for the agents ControllerAddress property
was emitted only in the agent_reconnect function when a
change in the address has been detected. This, however, led
to the agent first emitting a status disconnected signal
and then the address changed signal when the SwitchAddress
API has been called. The order of these signals should be
reversed.
The address changed signal is now also emitted inside the
SwitchController API function which changes the address.
In order to get the up-to-date value in the orch_addr field,
the new value is set here as well.
The ControllerAddress property changed signal will still be
emitted in the reconnect function to ensure any change in
the address due to name resolution is considered.

Signed-off-by: Michael Engel <[email protected]>
  • Loading branch information
engelmi committed Oct 28, 2024
1 parent 93644fb commit 95ffd63
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/agent/agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1939,12 +1939,16 @@ static int agent_method_switch_controller(sd_bus_message *m, void *userdata, UNU
"Failed to switch controller because already connected to the controller");
}

if (!agent_set_controller_address(agent, dbus_address)) {
if (!agent_set_controller_address(agent, dbus_address) ||
!agent_set_orch_address(agent, dbus_address)) {
bc_log_error("Failed to set CONTROLLER ADDRESS");
return sd_bus_reply_method_errorf(m, SD_BUS_ERROR_FAILED, "Failed to set CONTROLLER ADDRESS");
}

bc_log_infof("CONTROLLER ADDRESS changed to %s", dbus_address);
r = sd_bus_emit_properties_changed(
agent->api_bus, BC_AGENT_OBJECT_PATH, AGENT_INTERFACE, "ControllerAddress", NULL);
if (r < 0) {
bc_log_errorf("Failed to emit controller address property changed: %s", strerror(-r));
}

agent_disconnected(NULL, userdata, NULL);

Expand Down

0 comments on commit 95ffd63

Please sign in to comment.