• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eclipse-bluechi / bluechi / 16572578197

28 Jul 2025 03:00PM UTC coverage: 70.652% (-3.8%) from 74.418%
16572578197

push

github

engelmi
Release BlueChi v1.1.0

Signed-off-by: Michael Engel <mengel@redhat.com>

4858 of 6876 relevant lines covered (70.65%)

947.13 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

49.12
/src/client/method-reset-failed.c
1
/*
2
 * Copyright Contributors to the Eclipse BlueChi project
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 */
6
#include "method-reset-failed.h"
7
#include "client.h"
8
#include "usage.h"
9

10
#include "libbluechi/common/opt.h"
11

12
static int method_reset_failed_on_units(Client *client, Command *commands) {
×
13
        char *node_name = commands->opargv[0];
×
14
        int units_count = 1;
×
15
        int r = 0;
×
16
        _cleanup_sd_bus_error_ sd_bus_error error = SD_BUS_ERROR_NULL;
×
17
        _cleanup_sd_bus_message_ sd_bus_message *result = NULL;
×
18

19
        r = assemble_object_path_string(NODE_OBJECT_PATH_PREFIX, node_name, &client->object_path);
×
20
        if (r < 0) {
×
21
                return r;
22
        }
23

24
        while (commands->opargv[units_count] != NULL) {
×
25
                printf("%i %s\n", units_count, commands->opargv[units_count]);
×
26
                r = sd_bus_call_method(
×
27
                                client->api_bus,
28
                                BC_INTERFACE_BASE_NAME,
29
                                client->object_path,
×
30
                                NODE_INTERFACE,
31
                                "ResetFailedUnit",
32
                                &error,
33
                                &result,
34
                                "s",
35
                                commands->opargv[units_count]);
×
36

37
                if (r < 0) {
×
38
                        fprintf(stderr, "Failed to issue method call: %s\n", error.message);
×
39
                        return r;
40
                }
41
                units_count++;
×
42
        }
43
        return r;
44
}
45

46
static int method_reset_failed_on_node(Client *client, char *node_name) {
3✔
47

48
        _cleanup_sd_bus_error_ sd_bus_error error = SD_BUS_ERROR_NULL;
×
49
        _cleanup_sd_bus_message_ sd_bus_message *result = NULL;
3✔
50
        int r = 0;
3✔
51

52
        r = assemble_object_path_string(NODE_OBJECT_PATH_PREFIX, node_name, &client->object_path);
3✔
53
        if (r < 0) {
3✔
54
                return r;
55
        }
56

57
        r = sd_bus_call_method(
6✔
58
                        client->api_bus,
59
                        BC_INTERFACE_BASE_NAME,
60
                        client->object_path,
3✔
61
                        NODE_INTERFACE,
62
                        "ResetFailed",
63
                        &error,
64
                        &result,
65
                        "");
66
        if (r < 0) {
3✔
67
                fprintf(stderr,
3✔
68
                        "Couldn't reset failed state of all units on node '%s': %s\n",
69
                        node_name,
70
                        error.message);
71
                return r;
72
        }
73

74
        return r;
75
}
76

77
static int method_reset_failed_on_all_nodes(Client *client) {
1✔
78

79
        int r = 0;
1✔
80

81
        _cleanup_sd_bus_error_ sd_bus_error error = SD_BUS_ERROR_NULL;
×
82
        _cleanup_sd_bus_message_ sd_bus_message *result = NULL;
1✔
83
        r = sd_bus_call_method(
1✔
84
                        client->api_bus,
85
                        BC_INTERFACE_BASE_NAME,
86
                        BC_OBJECT_PATH,
87
                        CONTROLLER_INTERFACE,
88
                        "ListNodes",
89
                        &error,
90
                        &result,
91
                        "",
92
                        NULL);
93
        if (r < 0) {
1✔
94
                fprintf(stderr, "Failed to issue method call: %s\n", error.message);
×
95
                return r;
96
        }
97

98
        r = sd_bus_message_enter_container(result, SD_BUS_TYPE_ARRAY, "(soss)");
1✔
99
        if (r < 0) {
1✔
100
                fprintf(stderr, "Failed to open result array: %s\n", strerror(-r));
1✔
101
                return r;
102
        }
103
        while (sd_bus_message_at_end(result, false) == 0) {
3✔
104
                const char *name = NULL;
2✔
105

106
                r = sd_bus_message_read(result, "(soss)", &name, NULL, NULL, NULL);
2✔
107
                if (r < 0) {
2✔
108
                        fprintf(stderr, "Failed to read node information: %s\n", strerror(-r));
×
109
                        return r;
×
110
                }
111

112
                _cleanup_free_ char *node_name = strdup(name);
2✔
113
                r = method_reset_failed_on_node(client, node_name);
2✔
114
        }
115

116
        return r;
117
}
118

119
int method_reset_failed(Command *command, void *userdata) {
2✔
120
        if (command->opargv[0] != NULL) {
2✔
121
                if (command->opargv[1] != NULL) {
1✔
122
                        return method_reset_failed_on_units(userdata, command);
×
123
                }
124
                return method_reset_failed_on_node(userdata, command->opargv[0]);
1✔
125
        }
126
        return method_reset_failed_on_all_nodes(userdata);
1✔
127
}
128

129
void usage_method_reset_failed() {
×
130
        usage_print_header();
×
131
        usage_print_description("Reset the failed state of units");
×
132
        usage_print_usage("bluechictl reset-failed [nodename] [unit1, unit2, ...]");
×
133
        printf("  If [nodename] and unit(s) are not given, the failed state is reset for all units on all nodes.\n");
×
134
        printf("  If no unit(s) are given, the failed state is reset for all units on the given node.\n");
×
135
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc