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

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

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

28.24
/src/shared/bus-object.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "alloc-util.h"
4
#include "bus-introspect.h"
5
#include "bus-object.h"
6
#include "log.h"
7
#include "macro.h"
8
#include "string-util.h"
9
#include "strv.h"
10

11
int bus_add_implementation(sd_bus *bus, const BusObjectImplementation *impl, void *userdata) {
16,635✔
12
        int r;
16,635✔
13

14
        log_debug("Registering bus object implementation for path=%s iface=%s", impl->path, impl->interface);
16,635✔
15

16
        for (const sd_bus_vtable **p = impl->vtables; p && *p; p++) {
20,227✔
17
                r = sd_bus_add_object_vtable(bus, NULL,
7,184✔
18
                                             impl->path,
3,592✔
19
                                             impl->interface,
3,592✔
20
                                             *p,
21
                                             userdata);
22
                if (r < 0)
3,592✔
UNCOV
23
                        return log_error_errno(r, "Failed to register bus path %s with interface %s: %m",
×
24
                                               impl->path,
25
                                               impl->interface);
26
        }
27

28
        for (const BusObjectVtablePair *p = impl->fallback_vtables; p && p->vtable; p++) {
46,037✔
29
                r = sd_bus_add_fallback_vtable(bus, NULL,
58,804✔
30
                                               impl->path,
29,402✔
31
                                               impl->interface,
29,402✔
32
                                               p->vtable,
33
                                               p->object_find,
29,402✔
34
                                               userdata);
35
                if (r < 0)
29,402✔
UNCOV
36
                        return log_error_errno(r, "Failed to register bus path %s with interface %s: %m",
×
37
                                               impl->path,
38
                                               impl->interface);
39
        }
40

41
        if (impl->node_enumerator) {
16,635✔
42
                r = sd_bus_add_node_enumerator(bus, NULL,
8,948✔
43
                                               impl->path,
4,474✔
44
                                               impl->node_enumerator,
45
                                               userdata);
46
                if (r < 0)
4,474✔
UNCOV
47
                        return log_error_errno(r, "Failed to add node enumerator for %s: %m",
×
48
                                               impl->path);
49
        }
50

51
        if (impl->manager) {
16,635✔
52
                r = sd_bus_add_object_manager(bus, NULL, impl->path);
102✔
53
                if (r < 0)
102✔
UNCOV
54
                        return log_error_errno(r, "Failed to add object manager for %s: %m", impl->path);
×
55
        }
56

57
        for (size_t i = 0; impl->children && impl->children[i]; i++) {
29,678✔
58
                r = bus_add_implementation(bus, impl->children[i], userdata);
13,043✔
59
                if (r < 0)
13,043✔
60
                        return r;
61
        }
62

63
        return 0;
64
}
65

UNCOV
66
static const BusObjectImplementation* find_implementation(
×
67
                const char *pattern,
68
                const BusObjectImplementation* const* bus_objects) {
69

70
        for (size_t i = 0; bus_objects && bus_objects[i]; i++) {
×
UNCOV
71
                const BusObjectImplementation *impl = bus_objects[i];
×
72

73
                if (STR_IN_SET(pattern, impl->path, impl->interface))
×
UNCOV
74
                        return impl;
×
75

76
                impl = find_implementation(pattern, impl->children);
×
UNCOV
77
                if (impl)
×
78
                        return impl;
79
        }
80

81
        return NULL;
82
}
83

UNCOV
84
static int bus_introspect_implementation(
×
85
                struct introspect *intro,
86
                const BusObjectImplementation *impl) {
UNCOV
87
        int r;
×
88

89
        for (const sd_bus_vtable **p = impl->vtables; p && *p; p++) {
×
90
                r = introspect_write_interface(intro, impl->interface, *p);
×
91
                if (r < 0)
×
UNCOV
92
                        return log_error_errno(r, "Failed to write introspection data: %m");
×
93
        }
94

95
        for (const BusObjectVtablePair *p = impl->fallback_vtables; p && p->vtable; p++) {
×
96
                r = introspect_write_interface(intro, impl->interface, p->vtable);
×
97
                if (r < 0)
×
UNCOV
98
                        return log_error_errno(r, "Failed to write introspection data: %m");
×
99
        }
100

101
        return 0;
102
}
103

UNCOV
104
static void list_paths(
×
105
                FILE *out,
106
                const BusObjectImplementation* const* bus_objects) {
107

108
        for (size_t i = 0; bus_objects[i]; i++) {
×
109
                fprintf(out, "%s\t%s\n", bus_objects[i]->path, bus_objects[i]->interface);
×
110
                if (bus_objects[i]->children)
×
UNCOV
111
                        list_paths(out, bus_objects[i]->children);
×
112
        }
UNCOV
113
}
×
114

UNCOV
115
int bus_introspect_implementations(
×
116
                FILE *out,
117
                const char *pattern,
118
                const BusObjectImplementation* const* bus_objects) {
119

120
        const BusObjectImplementation *impl, *main_impl = NULL;
×
121
        _cleanup_free_ char *s = NULL;
×
UNCOV
122
        int r;
×
123

124
        if (streq(pattern, "list")) {
×
UNCOV
125
                list_paths(out, bus_objects);
×
126
                return 0;
127
        }
128

129
        struct introspect intro = {};
×
UNCOV
130
        bool is_interface = sd_bus_interface_name_is_valid(pattern);
×
131

132
        impl = find_implementation(pattern, bus_objects);
×
133
        if (!impl)
×
UNCOV
134
                return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
×
135
                                       "%s %s not found",
136
                                       is_interface ? "Interface" : "Object path",
137
                                       pattern);
138

139
        /* We use trusted=false here to get all the @org.freedesktop.systemd1.Privileged annotations. */
140
        r = introspect_begin(&intro, false);
×
141
        if (r < 0)
×
UNCOV
142
                return log_error_errno(r, "Failed to write introspection data: %m");
×
143

144
        r = introspect_write_default_interfaces(&intro, impl->manager);
×
145
        if (r < 0)
×
UNCOV
146
                return log_error_errno(r, "Failed to write introspection data: %m");
×
147

148
        /* Check if there is a non-fallback path that applies to the given interface, also
149
         * print it. This is useful in the case of units: o.fd.systemd1.Service is declared
150
         * as a fallback vtable for o/fd/systemd1/unit, and we also want to print
151
         * o.fd.systemd1.Unit, which is the non-fallback implementation. */
152
        if (impl->fallback_vtables && is_interface)
×
UNCOV
153
                main_impl = find_implementation(impl->path, bus_objects);
×
154

155
        if (main_impl)
×
UNCOV
156
                bus_introspect_implementation(&intro, main_impl);
×
157

158
        if (impl != main_impl)
×
UNCOV
159
                bus_introspect_implementation(&intro, impl);
×
160

UNCOV
161
        _cleanup_ordered_set_free_ OrderedSet *nodes = NULL;
×
162

163
        for (size_t i = 0; impl->children && impl->children[i]; i++) {
×
164
                r = ordered_set_put_strdup(&nodes, impl->children[i]->path);
×
165
                if (r < 0)
×
UNCOV
166
                        return log_oom();
×
167
        }
168

169
        r = introspect_write_child_nodes(&intro, nodes, impl->path);
×
UNCOV
170
        if (r < 0)
×
171
                return r;
172

173
        r = introspect_finish(&intro, &s);
×
174
        if (r < 0)
×
UNCOV
175
                return log_error_errno(r, "Failed to write introspection data: %m");
×
176

UNCOV
177
        fputs(s, out);
×
178
        return 0;
179
}
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