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

systemd / systemd / 15199265962

22 May 2025 09:40PM UTC coverage: 72.061% (-0.02%) from 72.079%
15199265962

push

github

bluca
tests: fix TEST-74-AUX-UTILS.varlinkctl.sh (#37562)

per Daan's explanation:
other subtests running as testuser apparently use systemd-run --user
--machine testuser@.host which turns user tracking in logind into "by
pin" mode. when the last pinning session exits it terminates the user.

299156 of 415145 relevant lines covered (72.06%)

703915.84 hits per line

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

85.96
/src/network/networkctl-misc.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "sd-bus.h"
4
#include "sd-netlink.h"
5

6
#include "bus-error.h"
7
#include "bus-locator.h"
8
#include "bus-util.h"
9
#include "errno-util.h"
10
#include "fd-util.h"
11
#include "format-ifname.h"
12
#include "log.h"
13
#include "netlink-util.h"
14
#include "networkctl.h"
15
#include "networkctl-misc.h"
16
#include "networkctl-util.h"
17
#include "parse-util.h"
18
#include "polkit-agent.h"
19
#include "set.h"
20
#include "string-util.h"
21
#include "varlink-util.h"
22

23
static int link_up_down_send_message(sd_netlink *rtnl, char *command, int index) {
5✔
24
        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
5✔
25
        int r;
5✔
26

27
        assert(rtnl);
5✔
28
        assert(index >= 0);
5✔
29

30
        r = sd_rtnl_message_new_link(rtnl, &req, RTM_SETLINK, index);
5✔
31
        if (r < 0)
5✔
32
                return rtnl_log_create_error(r);
×
33

34
        if (streq(command, "up"))
5✔
35
                r = sd_rtnl_message_link_set_flags(req, IFF_UP, IFF_UP);
3✔
36
        else
37
                r = sd_rtnl_message_link_set_flags(req, 0, IFF_UP);
2✔
38
        if (r < 0)
5✔
39
                return log_error_errno(r, "Could not set link flags: %m");
×
40

41
        r = sd_netlink_call(rtnl, req, 0, NULL);
5✔
42
        if (r < 0)
5✔
43
                return r;
×
44

45
        return 0;
46
}
47

48
int link_up_down(int argc, char *argv[], void *userdata) {
5✔
49
        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
5✔
50
        _cleanup_set_free_ Set *indexes = NULL;
5✔
51
        int index, r;
5✔
52
        void *p;
5✔
53

54
        r = sd_netlink_open(&rtnl);
5✔
55
        if (r < 0)
5✔
56
                return log_error_errno(r, "Failed to connect to netlink: %m");
×
57

58
        indexes = set_new(NULL);
5✔
59
        if (!indexes)
5✔
60
                return log_oom();
×
61

62
        for (int i = 1; i < argc; i++) {
14✔
63
                index = rtnl_resolve_interface_or_warn(&rtnl, argv[i]);
9✔
64
                if (index < 0)
9✔
65
                        return index;
66

67
                r = set_put(indexes, INT_TO_PTR(index));
9✔
68
                if (r < 0)
9✔
69
                        return log_oom();
×
70
        }
71

72
        SET_FOREACH(p, indexes) {
10✔
73
                index = PTR_TO_INT(p);
5✔
74
                r = link_up_down_send_message(rtnl, argv[0], index);
5✔
75
                if (r < 0)
5✔
76
                        return log_error_errno(r, "Failed to bring %s interface %s: %m",
×
77
                                               argv[0], FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX));
78
        }
79

80
        return r;
5✔
81
}
82

83
static int link_delete_send_message(sd_netlink *rtnl, int index) {
2✔
84
        _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
2✔
85
        int r;
2✔
86

87
        assert(rtnl);
2✔
88
        assert(index >= 0);
2✔
89

90
        r = sd_rtnl_message_new_link(rtnl, &req, RTM_DELLINK, index);
2✔
91
        if (r < 0)
2✔
92
                return rtnl_log_create_error(r);
×
93

94
        r = sd_netlink_call(rtnl, req, 0, NULL);
2✔
95
        if (r < 0)
2✔
96
                return r;
×
97

98
        return 0;
99
}
100

101
int link_delete(int argc, char *argv[], void *userdata) {
1✔
102
        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
1✔
103
        _cleanup_set_free_ Set *indexes = NULL;
1✔
104
        int index, r;
1✔
105
        void *p;
1✔
106

107
        r = sd_netlink_open(&rtnl);
1✔
108
        if (r < 0)
1✔
109
                return log_error_errno(r, "Failed to connect to netlink: %m");
×
110

111
        indexes = set_new(NULL);
1✔
112
        if (!indexes)
1✔
113
                return log_oom();
×
114

115
        for (int i = 1; i < argc; i++) {
3✔
116
                index = rtnl_resolve_interface_or_warn(&rtnl, argv[i]);
2✔
117
                if (index < 0)
2✔
118
                        return index;
119

120
                r = set_put(indexes, INT_TO_PTR(index));
2✔
121
                if (r < 0)
2✔
122
                        return log_oom();
×
123
        }
124

125
        SET_FOREACH(p, indexes) {
3✔
126
                index = PTR_TO_INT(p);
2✔
127
                r = link_delete_send_message(rtnl, index);
2✔
128
                if (r < 0)
2✔
129
                        return log_error_errno(r, "Failed to delete interface %s: %m",
×
130
                                               FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX));
131
        }
132

133
        return r;
1✔
134
}
135

136
static int link_renew_one(sd_bus *bus, int index, const char *name) {
5✔
137
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
5✔
138
        int r;
5✔
139

140
        assert(bus);
5✔
141
        assert(index >= 0);
5✔
142
        assert(name);
5✔
143

144
        r = bus_call_method(bus, bus_network_mgr, "RenewLink", &error, NULL, "i", index);
5✔
145
        if (r < 0)
5✔
146
                return log_error_errno(r, "Failed to renew dynamic configuration of interface %s: %s",
×
147
                                       name, bus_error_message(&error, r));
148

149
        return 0;
150
}
151

152
int link_renew(int argc, char *argv[], void *userdata) {
3✔
153
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
3✔
154
        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
3✔
155
        int r;
3✔
156

157
        r = acquire_bus(&bus);
3✔
158
        if (r < 0)
3✔
159
                return r;
160

161
        (void) polkit_agent_open_if_enabled(BUS_TRANSPORT_LOCAL, arg_ask_password);
3✔
162

163
        r = 0;
164

165
        for (int i = 1; i < argc; i++) {
8✔
166
                int index;
5✔
167

168
                index = rtnl_resolve_interface_or_warn(&rtnl, argv[i]);
5✔
169
                if (index < 0)
5✔
170
                        return index;
171

172
                RET_GATHER(r, link_renew_one(bus, index, argv[i]));
5✔
173
        }
174

175
        return r;
176
}
177

178
static int link_force_renew_one(sd_bus *bus, int index, const char *name) {
4✔
179
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4✔
180
        int r;
4✔
181

182
        assert(bus);
4✔
183
        assert(index >= 0);
4✔
184
        assert(name);
4✔
185

186
        r = bus_call_method(bus, bus_network_mgr, "ForceRenewLink", &error, NULL, "i", index);
4✔
187
        if (r < 0)
4✔
188
                return log_error_errno(r, "Failed to force renew dynamic configuration of interface %s: %s",
×
189
                                       name, bus_error_message(&error, r));
190

191
        return 0;
192
}
193

194
int link_force_renew(int argc, char *argv[], void *userdata) {
2✔
195
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
2✔
196
        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
2✔
197
        int k = 0, r;
2✔
198

199
        r = acquire_bus(&bus);
2✔
200
        if (r < 0)
2✔
201
                return r;
202

203
        (void) polkit_agent_open_if_enabled(BUS_TRANSPORT_LOCAL, arg_ask_password);
2✔
204

205
        for (int i = 1; i < argc; i++) {
6✔
206
                int index = rtnl_resolve_interface_or_warn(&rtnl, argv[i]);
4✔
207
                if (index < 0)
4✔
208
                        return index;
209

210
                r = link_force_renew_one(bus, index, argv[i]);
4✔
211
                if (r < 0 && k >= 0)
4✔
212
                        k = r;
×
213
        }
214

215
        return k;
216
}
217

218
int verb_reload(int argc, char *argv[], void *userdata) {
127✔
219
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
127✔
220
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
127✔
221
        int r;
127✔
222

223
        r = acquire_bus(&bus);
127✔
224
        if (r < 0)
127✔
225
                return r;
226

227
        (void) polkit_agent_open_if_enabled(BUS_TRANSPORT_LOCAL, arg_ask_password);
127✔
228

229
        r = bus_call_method(bus, bus_network_mgr, "Reload", &error, NULL, NULL);
127✔
230
        if (r < 0)
127✔
231
                return log_error_errno(r, "Failed to reload network settings: %s", bus_error_message(&error, r));
×
232

233
        return 0;
234
}
235

236
int verb_reconfigure(int argc, char *argv[], void *userdata) {
34✔
237
        _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL;
34✔
238
        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
×
239
        _cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
34✔
240
        _cleanup_set_free_ Set *indexes = NULL;
34✔
241
        int index, r;
34✔
242
        void *p;
34✔
243

244
        r = acquire_bus(&bus);
34✔
245
        if (r < 0)
34✔
246
                return r;
247

248
        (void) polkit_agent_open_if_enabled(BUS_TRANSPORT_LOCAL, arg_ask_password);
34✔
249

250
        indexes = set_new(NULL);
34✔
251
        if (!indexes)
34✔
252
                return log_oom();
×
253

254
        for (int i = 1; i < argc; i++) {
70✔
255
                index = rtnl_resolve_interface_or_warn(&rtnl, argv[i]);
36✔
256
                if (index < 0)
36✔
257
                        return index;
258

259
                r = set_put(indexes, INT_TO_PTR(index));
36✔
260
                if (r < 0)
36✔
261
                        return log_oom();
×
262
        }
263

264
        SET_FOREACH(p, indexes) {
70✔
265
                index = PTR_TO_INT(p);
36✔
266
                r = bus_call_method(bus, bus_network_mgr, "ReconfigureLink", &error, NULL, "i", index);
36✔
267
                if (r < 0)
36✔
268
                        return log_error_errno(r, "Failed to reconfigure network interface %s: %s",
×
269
                                               FORMAT_IFNAME_FULL(index, FORMAT_IFNAME_IFINDEX),
270
                                               bus_error_message(&error, r));
271
        }
272

273
        return 0;
34✔
274
}
275

276
int verb_persistent_storage(int argc, char *argv[], void *userdata) {
838✔
277
        _cleanup_(sd_varlink_flush_close_unrefp) sd_varlink *vl = NULL;
838✔
278
        bool ready;
838✔
279
        int r;
838✔
280

281
        r = parse_boolean(argv[1]);
838✔
282
        if (r < 0)
838✔
283
                return log_error_errno(r, "Failed to parse argument: %s", argv[1]);
×
284
        ready = r;
838✔
285

286
        r = varlink_connect_networkd(&vl);
838✔
287
        if (r < 0)
838✔
288
                return r;
289

290
        if (ready) {
837✔
291
                _cleanup_close_ int fd = -EBADF;
838✔
292

293
                fd = open("/var/lib/systemd/network/", O_CLOEXEC | O_DIRECTORY);
419✔
294
                if (fd < 0)
419✔
295
                        return log_error_errno(errno, "Failed to open /var/lib/systemd/network/: %m");
×
296

297
                r = sd_varlink_push_fd(vl, fd);
419✔
298
                if (r < 0)
419✔
299
                        return log_error_errno(r, "Failed to push file descriptor of /var/lib/systemd/network/ into varlink: %m");
×
300

301
                TAKE_FD(fd);
419✔
302
        }
303

304
        return varlink_callbo_and_log(
837✔
305
                        vl,
306
                        "io.systemd.Network.SetPersistentStorage",
307
                        /* reply= */ NULL,
308
                        SD_JSON_BUILD_PAIR_BOOLEAN("Ready", ready));
309
}
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