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

systemd / systemd / 14766779411

30 Apr 2025 04:55PM UTC coverage: 72.225% (-0.06%) from 72.282%
14766779411

push

github

web-flow
wait-online: handle varlink connection errors while waiting for DNS (#37283)

Currently, if systemd-networkd-wait-online is started with --dns, and
systemd-resolved is not running, it will exit with an error right away.
Similarly, if systemd-resolved is restarted while waiting for DNS
configuration, systemd-networkd-wait-online will not attempt to
re-connect, and will potentially never see subsequent DNS
configurations.

Improve this by adding socket units for the systemd-resolved varlink
servers, and re-establish the connection in systemd-networkd-wait-online
when we receive `SD_VARLINK_ERROR_DISCONNECTED`.

8 of 16 new or added lines in 2 files covered. (50.0%)

5825 existing lines in 217 files now uncovered.

297168 of 411450 relevant lines covered (72.22%)

695892.62 hits per line

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

56.52
/src/shared/devnode-acl.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <errno.h>
4

5
#include "sd-device.h"
6

7
#include "acl-util.h"
8
#include "alloc-util.h"
9
#include "device-util.h"
10
#include "devnode-acl.h"
11
#include "dirent-util.h"
12
#include "fd-util.h"
13
#include "format-util.h"
14
#include "fs-util.h"
15
#include "glyph-util.h"
16
#include "set.h"
17
#include "string-util.h"
18

19
static int flush_acl(acl_t acl) {
133✔
20
        acl_entry_t i;
133✔
21
        int found;
133✔
22
        bool changed = false;
133✔
23

24
        assert(acl);
133✔
25

26
        for (found = acl_get_entry(acl, ACL_FIRST_ENTRY, &i);
133✔
27
             found > 0;
532✔
28
             found = acl_get_entry(acl, ACL_NEXT_ENTRY, &i)) {
399✔
29

30
                acl_tag_t tag;
399✔
31

32
                if (acl_get_tag_type(i, &tag) < 0)
399✔
33
                        return -errno;
×
34

35
                if (tag != ACL_USER)
399✔
36
                        continue;
399✔
37

38
                if (acl_delete_entry(acl, i) < 0)
×
39
                        return -errno;
×
40

41
                changed = true;
×
42
        }
43

44
        if (found < 0)
133✔
45
                return -errno;
×
46

47
        return changed;
133✔
48
}
49

50
int devnode_acl(const char *path,
405✔
51
                bool flush,
52
                bool del, uid_t old_uid,
53
                bool add, uid_t new_uid) {
54

55
        _cleanup_(acl_freep) acl_t acl = NULL;
405✔
56
        int r;
405✔
57
        bool changed = false;
405✔
58

59
        assert(path);
405✔
60

61
        acl = acl_get_file(path, ACL_TYPE_ACCESS);
405✔
62
        if (!acl)
405✔
63
                return -errno;
×
64

65
        if (flush) {
405✔
66

67
                r = flush_acl(acl);
133✔
68
                if (r < 0)
133✔
69
                        return r;
70
                if (r > 0)
133✔
71
                        changed = true;
×
72

73
        } else if (del && old_uid > 0) {
272✔
74
                acl_entry_t entry;
×
75

76
                r = acl_find_uid(acl, old_uid, &entry);
×
77
                if (r < 0)
×
78
                        return r;
×
79

80
                if (r > 0) {
×
81
                        if (acl_delete_entry(acl, entry) < 0)
×
82
                                return -errno;
×
83

84
                        changed = true;
85
                }
86
        }
87

88
        if (add && new_uid > 0) {
405✔
89
                acl_entry_t entry;
×
90
                acl_permset_t permset;
×
91
                int rd, wt;
×
92

93
                r = acl_find_uid(acl, new_uid, &entry);
×
94
                if (r < 0)
×
95
                        return r;
×
96

97
                if (r == 0) {
×
98
                        if (acl_create_entry(&acl, &entry) < 0)
×
99
                                return -errno;
×
100

101
                        if (acl_set_tag_type(entry, ACL_USER) < 0 ||
×
102
                            acl_set_qualifier(entry, &new_uid) < 0)
×
103
                                return -errno;
×
104
                }
105

106
                if (acl_get_permset(entry, &permset) < 0)
×
107
                        return -errno;
×
108

109
                rd = acl_get_perm(permset, ACL_READ);
×
110
                if (rd < 0)
×
111
                        return -errno;
×
112

113
                wt = acl_get_perm(permset, ACL_WRITE);
×
114
                if (wt < 0)
×
115
                        return -errno;
×
116

117
                if (!rd || !wt) {
×
118

119
                        if (acl_add_perm(permset, ACL_READ|ACL_WRITE) < 0)
×
120
                                return -errno;
×
121

122
                        changed = true;
123
                }
124
        }
125

126
        if (!changed)
405✔
127
                return 0;
128

129
        if (acl_calc_mask(&acl) < 0)
×
130
                return -errno;
×
131

132
        if (acl_set_file(path, ACL_TYPE_ACCESS, acl) < 0)
×
133
                return -errno;
×
134

135
        return 0;
136
}
137

138
int devnode_acl_all(const char *seat,
68✔
139
                    bool flush,
140
                    bool del, uid_t old_uid,
141
                    bool add, uid_t new_uid) {
142

143
        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
68✔
144
        _cleanup_set_free_ Set *nodes = NULL;
×
145
        _cleanup_closedir_ DIR *dir = NULL;
68✔
146
        char *n;
68✔
147
        int r;
68✔
148

149
        r = sd_device_enumerator_new(&e);
68✔
150
        if (r < 0)
68✔
151
                return r;
152

153
        if (isempty(seat))
68✔
154
                seat = "seat0";
155

156
        /* We can only match by one tag in libudev. We choose
157
         * "uaccess" for that. If we could match for two tags here we
158
         * could add the seat name as second match tag, but this would
159
         * be hardly optimizable in libudev, and hence checking the
160
         * second tag manually in our loop is a good solution. */
161
        r = sd_device_enumerator_add_match_tag(e, "uaccess");
68✔
162
        if (r < 0)
68✔
163
                return r;
164

165
        FOREACH_DEVICE(e, d) {
204✔
166
                const char *node, *sn;
136✔
167

168
                /* Make sure the tag is still in place */
169
                if (sd_device_has_current_tag(d, "uaccess") <= 0)
136✔
170
                        continue;
×
171

172
                if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
136✔
173
                        sn = "seat0";
136✔
174

175
                if (!streq(seat, sn))
136✔
176
                        continue;
×
177

178
                /* In case people mistag devices with nodes, we need to ignore this */
179
                if (sd_device_get_devname(d, &node) < 0)
136✔
180
                        continue;
×
181

182
                log_device_debug(d, "Found udev node %s for seat %s", node, seat);
136✔
183
                r = set_put_strdup_full(&nodes, &path_hash_ops_free, node);
136✔
184
                if (r < 0)
136✔
185
                        return r;
×
186
        }
187

188
        /* udev exports "dead" device nodes to allow module on-demand loading,
189
         * these devices are not known to the kernel at this moment */
190
        dir = opendir("/run/udev/static_node-tags/uaccess");
68✔
191
        if (dir) {
68✔
192
                FOREACH_DIRENT(de, dir, return -errno) {
340✔
193
                        r = readlinkat_malloc(dirfd(dir), de->d_name, &n);
136✔
194
                        if (r == -ENOENT)
136✔
195
                                continue;
×
196
                        if (r < 0) {
136✔
197
                                log_debug_errno(r,
×
198
                                                "Unable to read symlink '/run/udev/static_node-tags/uaccess/%s', ignoring: %m",
199
                                                de->d_name);
200
                                continue;
×
201
                        }
202

203
                        log_debug("Found static node %s for seat %s", n, seat);
136✔
204
                        r = set_ensure_consume(&nodes, &path_hash_ops_free, n);
136✔
205
                        if (r < 0)
136✔
206
                                return r;
207
                }
208
        }
209

210
        r = 0;
68✔
211
        SET_FOREACH(n, nodes) {
340✔
212
                int k;
272✔
213

214
                log_debug("Changing ACLs at %s for seat %s (uid "UID_FMT"%s"UID_FMT"%s%s)",
680✔
215
                          n, seat, old_uid, glyph(GLYPH_ARROW_RIGHT), new_uid,
216
                          del ? " del" : "", add ? " add" : "");
217

218
                k = devnode_acl(n, flush, del, old_uid, add, new_uid);
272✔
219
                if (k == -ENOENT)
272✔
UNCOV
220
                        log_debug("Device %s disappeared while setting ACLs", n);
×
221
                else
222
                        RET_GATHER(r, k);
272✔
223
        }
224

225
        return r;
68✔
226
}
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