Skip to content

Commit

Permalink
log error when at least one list units request fails
Browse files Browse the repository at this point in the history
Relates to:
#567
#568

When list units for all nodes is run and the requests are submitted,
it might happen that one of those is failing. Previously, this led
to a failure when reading the message for the node where the request
failed - which got propagated to the caller.
Now, an additional error log in BlueChi is made and the error code
is extracted from the sd_bus_message.
Also removes the top-most error print in the client to avoid printing
errors twice.

Signed-off-by: Michael Engel <[email protected]>
  • Loading branch information
engelmi authored and dougsland committed Nov 17, 2023
1 parent 843317a commit 180e3c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ int main(int argc, char *argv[]) {
_cleanup_client_ Client *client = new_client(op, opargc, opargv, opt_filter_glob);
r = client_call_manager(client);
if (r < 0) {
fprintf(stderr, "Call to manager failed: %s\n", strerror(-r));
return EXIT_FAILURE;
}

Expand Down
19 changes: 16 additions & 3 deletions src/manager/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,12 @@ static int manager_method_list_units_encode_reply(ListUnitsRequest *req, sd_bus_
continue;
}

const sd_bus_error *err = sd_bus_message_get_error(m);
if (err != NULL) {
bc_log_errorf("Failed to list units for node '%s': %s", node_name, err->message);
return -sd_bus_message_get_errno(m);
}

r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, UNIT_INFO_STRUCT_TYPESTRING);
if (r < 0) {
return r;
Expand Down Expand Up @@ -562,9 +568,6 @@ static void manager_method_list_units_done(ListUnitsRequest *req) {

_cleanup_sd_bus_message_ sd_bus_message *reply = NULL;
int r = sd_bus_message_new_method_return(req->request_message, &reply);
if (r >= 0) {
r = manager_method_list_units_encode_reply(req, reply);
}
if (r < 0) {
sd_bus_reply_method_errorf(
req->request_message,
Expand All @@ -574,6 +577,16 @@ static void manager_method_list_units_done(ListUnitsRequest *req) {
return;
}

r = manager_method_list_units_encode_reply(req, reply);
if (r < 0) {
sd_bus_reply_method_errorf(
req->request_message,
SD_BUS_ERROR_FAILED,
"List units request to at least one node failed: %s",
strerror(-r));
return;
}

r = sd_bus_message_send(reply);
if (r < 0) {
bc_log_errorf("Failed to send reply message: %s", strerror(-r));
Expand Down
6 changes: 3 additions & 3 deletions src/manager/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -1129,17 +1129,17 @@ int agent_request_start(AgentRequest *req) {
AgentRequest *node_request_list_units(
Node *node, agent_request_response_t cb, void *userdata, free_func_t free_userdata) {
if (!node_has_agent(node)) {
return false;
return NULL;
}

_cleanup_agent_request_ AgentRequest *req = NULL;
node_create_request(&req, node, "ListUnits", cb, userdata, free_userdata);
if (req == NULL) {
return false;
return NULL;
}

if (agent_request_start(req) < 0) {
return false;
return NULL;
}

return steal_pointer(&req);
Expand Down

0 comments on commit 180e3c5

Please sign in to comment.