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

systemd / systemd / 15263807472

26 May 2025 08:53PM UTC coverage: 72.046% (-0.002%) from 72.048%
15263807472

push

github

yuwata
src/core/manager.c: log preset activity on first boot

This gives us a little more information about what units were enabled
or disabled on that first boot and will be useful for OS developers
tracking down the source of unit state.

An example with this enabled looks like:

```
NET: Registered PF_VSOCK protocol family
systemd[1]: Applying preset policy.
systemd[1]: Unit /etc/systemd/system/dnsmasq.service is masked, ignoring.
systemd[1]: Unit /etc/systemd/system/systemd-repart.service is masked, ignoring.
systemd[1]: Removed '/etc/systemd/system/sockets.target.wants/systemd-resolved-monitor.socket'.
systemd[1]: Removed '/etc/systemd/system/sockets.target.wants/systemd-resolved-varlink.socket'.
systemd[1]: Created symlink '/etc/systemd/system/multi-user.target.wants/var-mnt-workdir.mount' → '/etc/systemd/system/var-mnt-workdir.mount'.
systemd[1]: Created symlink '/etc/systemd/system/multi-user.target.wants/var-mnt-workdir\x2dtmp.mount' → '/etc/systemd/system/var-mnt-workdir\x2dtmp.mount'.
systemd[1]: Created symlink '/etc/systemd/system/afterburn-sshkeys.target.requires/afterburn-sshkeys@core.service' → '/usr/lib/systemd/system/afterburn-sshkeys@.service'.
systemd[1]: Created symlink '/etc/systemd/system/sockets.target.wants/systemd-resolved-varlink.socket' → '/usr/lib/systemd/system/systemd-resolved-varlink.socket'.
systemd[1]: Created symlink '/etc/systemd/system/sockets.target.wants/systemd-resolved-monitor.socket' → '/usr/lib/systemd/system/systemd-resolved-monitor.socket'.
systemd[1]: Populated /etc with preset unit settings.
```

Considering it only happens on first boot and not on every boot I think
the extra information is worth the extra verbosity in the logs just for
that boot.

5 of 6 new or added lines in 1 file covered. (83.33%)

5463 existing lines in 165 files now uncovered.

299151 of 415222 relevant lines covered (72.05%)

702386.45 hits per line

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

98.66
/src/basic/ether-addr-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <net/ethernet.h>
4
#include <stdio.h>
5

6
#include "ether-addr-util.h"
7
#include "hash-funcs.h"
8
#include "hexdecoct.h"
9
#include "in-addr-util.h"
10
#include "memory-util.h"
11
#include "siphash24.h"
12
#include "string-util.h"
13

14
char* hw_addr_to_string_full(
7,307✔
15
                const struct hw_addr_data *addr,
16
                HardwareAddressToStringFlags flags,
17
                char buffer[static HW_ADDR_TO_STRING_MAX]) {
18

19
        assert(addr);
7,307✔
20
        assert(buffer);
7,307✔
21
        assert(addr->length <= HW_ADDR_MAX_SIZE);
7,307✔
22

23
        for (size_t i = 0, j = 0; i < addr->length; i++) {
53,045✔
24
                buffer[j++] = hexchar(addr->bytes[i] >> 4);
45,738✔
25
                buffer[j++] = hexchar(addr->bytes[i] & 0x0f);
45,738✔
26
                if (!FLAGS_SET(flags, HW_ADDR_TO_STRING_NO_COLON))
45,738✔
27
                        buffer[j++] = ':';
45,708✔
28
        }
29

30
        buffer[addr->length == 0 || FLAGS_SET(flags, HW_ADDR_TO_STRING_NO_COLON) ?
7,307✔
31
               addr->length * 2 :
7,312✔
32
               addr->length * 3 - 1] = '\0';
7,302✔
33
        return buffer;
7,307✔
34
}
35

36
struct hw_addr_data *hw_addr_set(struct hw_addr_data *addr, const uint8_t *bytes, size_t length) {
250✔
37
        assert(addr);
250✔
38
        assert(length <= HW_ADDR_MAX_SIZE);
250✔
39

40
        addr->length = length;
250✔
41
        memcpy_safe(addr->bytes, bytes, length);
250✔
42
        return addr;
250✔
43
}
44

45
int hw_addr_compare(const struct hw_addr_data *a, const struct hw_addr_data *b) {
12,432✔
46
        int r;
12,432✔
47

48
        assert(a);
12,432✔
49
        assert(b);
12,432✔
50

51
        r = CMP(a->length, b->length);
12,432✔
52
        if (r != 0)
9,431✔
53
                return r;
3,844✔
54

55
        return memcmp(a->bytes, b->bytes, a->length);
8,588✔
56
}
57

58
void hw_addr_hash_func(const struct hw_addr_data *p, struct siphash *state) {
2,228✔
59
        assert(p);
2,228✔
60
        assert(state);
2,228✔
61

62
        siphash24_compress_typesafe(p->length, state);
2,228✔
63
        siphash24_compress_safe(p->bytes, p->length, state);
2,228✔
64
}
2,228✔
65

66
bool hw_addr_is_null(const struct hw_addr_data *addr) {
5,716✔
67
        assert(addr);
5,716✔
68
        return addr->length == 0 || memeqzero(addr->bytes, addr->length);
5,716✔
69
}
70

71
DEFINE_HASH_OPS(hw_addr_hash_ops, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare);
72
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(hw_addr_hash_ops_free, struct hw_addr_data, hw_addr_hash_func, hw_addr_compare, free);
17✔
73

74
char* ether_addr_to_string(const struct ether_addr *addr, char buffer[ETHER_ADDR_TO_STRING_MAX]) {
29✔
75
        assert(addr);
29✔
76
        assert(buffer);
29✔
77

78
        /* Like ether_ntoa() but uses %02x instead of %x to print
79
         * ethernet addresses, which makes them look less funny. Also,
80
         * doesn't use a static buffer. */
81

82
        sprintf(buffer, "%02x:%02x:%02x:%02x:%02x:%02x",
29✔
83
                addr->ether_addr_octet[0],
29✔
84
                addr->ether_addr_octet[1],
29✔
85
                addr->ether_addr_octet[2],
29✔
86
                addr->ether_addr_octet[3],
29✔
87
                addr->ether_addr_octet[4],
29✔
88
                addr->ether_addr_octet[5]);
29✔
89

90
        return buffer;
29✔
91
}
92

93
int ether_addr_compare(const struct ether_addr *a, const struct ether_addr *b) {
12,651✔
94
        return memcmp(a, b, ETH_ALEN);
12,651✔
95
}
96

97
static void ether_addr_hash_func(const struct ether_addr *p, struct siphash *state) {
37✔
98
        siphash24_compress_typesafe(*p, state);
37✔
99
}
37✔
100

101
bool ether_addr_is_broadcast(const struct ether_addr *addr) {
1,240✔
102
        assert(addr);
1,240✔
103
        return memeqbyte(0xff, addr->ether_addr_octet, ETH_ALEN);
1,240✔
104
}
105

106
DEFINE_HASH_OPS(ether_addr_hash_ops, struct ether_addr, ether_addr_hash_func, ether_addr_compare);
107
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(ether_addr_hash_ops_free, struct ether_addr, ether_addr_hash_func, ether_addr_compare, free);
3✔
108

109
static int parse_hw_addr_one_field(const char **s, char sep, size_t len, uint8_t *buf) {
3,862✔
110
        const char *hex = HEXDIGITS, *p;
3,862✔
111
        uint16_t data = 0;
3,862✔
112
        bool cont;
3,862✔
113

114
        assert(s);
3,862✔
115
        assert(*s);
3,862✔
116
        assert(IN_SET(len, 1, 2));
3,862✔
117
        assert(buf);
3,862✔
118

119
        p = *s;
120

121
        for (size_t i = 0; i < len * 2; i++) {
11,646✔
122
                const char *hexoff;
7,859✔
123
                size_t x;
7,859✔
124

125
                if (*p == '\0' || *p == sep) {
7,859✔
126
                        if (i == 0)
68✔
127
                                return -EINVAL;
128
                        break;
129
                }
130

131
                hexoff = strchr(hex, *p);
7,791✔
132
                if (!hexoff)
7,791✔
133
                        return -EINVAL;
134

135
                assert(hexoff >= hex);
7,784✔
136
                x = hexoff - hex;
7,784✔
137
                if (x >= 16)
7,784✔
138
                        x -= 6; /* A-F */
70✔
139

140
                assert(x < 16);
70✔
141
                data <<= 4;
7,784✔
142
                data += x;
7,784✔
143

144
                p++;
7,784✔
145
        }
146

147
        if (*p != '\0' && *p != sep)
3,847✔
148
                return -EINVAL;
149

150
        switch (len) {
3,834✔
151
        case 1:
3,741✔
152
                buf[0] = data;
3,741✔
153
                break;
3,741✔
154
        case 2:
93✔
155
                buf[0] = (data & 0xff00) >> 8;
93✔
156
                buf[1] = data & 0xff;
93✔
157
                break;
93✔
UNCOV
158
        default:
×
UNCOV
159
                assert_not_reached();
×
160
        }
161

162
        cont = *p == sep;
3,834✔
163
        *s = p + cont;
3,834✔
164
        return cont;
3,834✔
165
}
166

167
int parse_hw_addr_full(const char *s, size_t expected_len, struct hw_addr_data *ret) {
718✔
168
        size_t field_size, max_len, len = 0;
718✔
169
        uint8_t bytes[HW_ADDR_MAX_SIZE];
718✔
170
        char sep;
718✔
171
        int r;
718✔
172

173
        assert(s);
718✔
174
        assert(expected_len <= HW_ADDR_MAX_SIZE || expected_len == SIZE_MAX);
718✔
175
        assert(ret);
718✔
176

177
        /* This accepts the following formats:
178
         *
179
         * Dot separated 2 bytes format: xxyy.zzaa.bbcc
180
         * Colon separated 1 bytes format: xx:yy:zz:aa:bb:cc
181
         * Hyphen separated 1 bytes format: xx-yy-zz-aa-bb-cc
182
         *
183
         * Moreover, if expected_len == 0, 4, or 16, this also accepts:
184
         *
185
         * IPv4 format: used by IPv4 tunnel, e.g. ipgre
186
         * IPv6 format: used by IPv6 tunnel, e.g. ip6gre
187
         *
188
         * The expected_len argument controls the length of acceptable addresses:
189
         *
190
         * 0: accepts 4 (AF_INET), 16 (AF_INET6), 6 (ETH_ALEN), or 20 (INFINIBAND_ALEN).
191
         * SIZE_MAX: accepts arbitrary length, but at least one separator must be included.
192
         * Otherwise: accepts addresses with matching length.
193
         */
194

195
        if (IN_SET(expected_len, 0, sizeof(struct in_addr), sizeof(struct in6_addr))) {
718✔
196
                union in_addr_union a;
93✔
197
                int family;
93✔
198

199
                if (expected_len == 0)
93✔
200
                        r = in_addr_from_string_auto(s, &family, &a);
80✔
201
                else {
202
                        family = expected_len == sizeof(struct in_addr) ? AF_INET : AF_INET6;
13✔
203
                        r = in_addr_from_string(family, s, &a);
13✔
204
                }
205
                if (r >= 0) {
93✔
206
                        ret->length = FAMILY_ADDRESS_SIZE(family);
30✔
207
                        memcpy(ret->bytes, a.bytes, ret->length);
30✔
208
                        return 0;
30✔
209
                }
210
        }
211

212
        max_len =
28✔
213
                expected_len == 0 ? INFINIBAND_ALEN :
688✔
214
                expected_len == SIZE_MAX ? HW_ADDR_MAX_SIZE : expected_len;
627✔
215
        sep = s[strspn(s, HEXDIGITS)];
688✔
216

217
        if (sep == '.')
688✔
218
                field_size = 2;
219
        else if (IN_SET(sep, ':', '-'))
650✔
220
                field_size = 1;
221
        else
222
                return -EINVAL;
223

224
        if (max_len % field_size != 0)
677✔
225
                return -EINVAL;
226

227
        for (size_t i = 0; i < max_len / field_size; i++) {
3,870✔
228
                r = parse_hw_addr_one_field(&s, sep, field_size, bytes + i * field_size);
3,862✔
229
                if (r < 0)
3,862✔
230
                        return r;
231
                if (r == 0) {
3,834✔
232
                        len = (i + 1) * field_size;
641✔
233
                        break;
641✔
234
                }
235
        }
236

237
        if (len == 0)
649✔
238
                return -EINVAL;
239

240
        if (expected_len == 0) {
641✔
241
                if (!IN_SET(len, 4, 16, ETH_ALEN, INFINIBAND_ALEN))
61✔
242
                        return -EINVAL;
243
        } else if (expected_len != SIZE_MAX) {
580✔
244
                if (len != expected_len)
567✔
245
                        return -EINVAL;
246
        }
247

248
        ret->length = len;
630✔
249
        memcpy(ret->bytes, bytes, ret->length);
630✔
250
        return 0;
630✔
251
}
252

253
int parse_ether_addr(const char *s, struct ether_addr *ret) {
123✔
254
        struct hw_addr_data a;
123✔
255
        int r;
123✔
256

257
        assert(s);
123✔
258
        assert(ret);
123✔
259

260
        r = parse_hw_addr_full(s, ETH_ALEN, &a);
123✔
261
        if (r < 0)
123✔
262
                return r;
123✔
263

264
        *ret = a.ether;
85✔
265
        return 0;
85✔
266
}
267

268
void ether_addr_mark_random(struct ether_addr *addr) {
76✔
269
        assert(addr);
76✔
270

271
        /* see eth_random_addr in the kernel */
272
        addr->ether_addr_octet[0] &= 0xfe;        /* clear multicast bit */
76✔
273
        addr->ether_addr_octet[0] |= 0x02;        /* set local assignment bit (IEEE802) */
76✔
274
}
76✔
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