• 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

96.55
/src/basic/cap-list.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdio.h>
4

5
#include "alloc-util.h"
6
#include "bitfield.h"
7
#include "cap-list.h"
8
#include "capability-util.h"
9
#include "extract-word.h"
10
#include "log.h"
11
#include "parse-util.h"
12
#include "string-util.h"
13
#include "strv.h"
14

15
static const struct capability_name* lookup_capability(register const char *str, register GPERF_LEN_TYPE len);
16

17
#include "cap-from-name.inc"
18
#include "cap-to-name.inc"
19

20
const char* capability_to_name(int id) {
10,590✔
21
        if (id < 0)
10,590✔
22
                return NULL;
23
        if (id >= capability_list_length())
10,589✔
24
                return NULL;
25

26
        return capability_names[id];
10,585✔
27
}
28

29
const char* capability_to_string(int id, char buf[static CAPABILITY_TO_STRING_MAX]) {
9,863✔
30
        const char *p;
9,863✔
31

32
        if (id < 0)
9,863✔
33
                return NULL;
34
        if (id > CAP_LIMIT) /* refuse caps > 62 since we can't store them in a uint64_t mask anymore, and still retain UINT64_MAX as marker for "unset" */
9,862✔
35
                return NULL;
36

37
        p = capability_to_name(id);
9,861✔
38
        if (p)
9,861✔
39
                return p;
40

41
        sprintf(buf, "0x%x", (unsigned) id); /* numerical fallback */
1✔
42
        return buf;
1✔
43
}
44

45
int capability_from_name(const char *name) {
10,933✔
46
        const struct capability_name *sc;
10,933✔
47
        int r, i;
10,933✔
48

49
        assert(name);
10,933✔
50

51
        /* Try to parse numeric capability */
52
        r = safe_atoi(name, &i);
10,933✔
53
        if (r >= 0) {
10,933✔
54
                if (i < 0 || i > CAP_LIMIT)
23✔
55
                        return -EINVAL;
10,933✔
56

57
                return i;
14✔
58
        }
59

60
        /* Try to parse string capability */
61
        sc = lookup_capability(name, strlen(name));
10,910✔
62
        if (!sc)
10,910✔
63
                return -EINVAL;
64

65
        return sc->id;
10,869✔
66
}
67

68
/* This is the number of capability names we are *compiled* with.  For the max capability number of the
69
 * currently-running kernel, use cap_last_cap(). Note that this one returns the size of the array, i.e. one
70
 * value larger than the last known capability. This is different from cap_last_cap() which returns the
71
 * highest supported capability. Hence with everyone agreeing on the same capabilities list, this function
72
 * will return one higher than cap_last_cap(). */
73
int capability_list_length(void) {
10,717✔
74
        return MIN((int) ELEMENTSOF(capability_names), CAP_LIMIT + 1);
10,717✔
75
}
76

77
int capability_set_to_string(uint64_t set, char **ret) {
486✔
78
        _cleanup_free_ char *str = NULL;
486✔
79

80
        assert(ret);
486✔
81

82
        for (unsigned i = 0; i <= cap_last_cap(); i++) {
20,412✔
83
                const char *p;
19,926✔
84

85
                if (!BIT_SET(set, i))
19,926✔
86
                        continue;
10,113✔
87

88
                p = CAPABILITY_TO_STRING(i);
9,813✔
89
                assert(p);
9,813✔
90

91
                if (!strextend_with_separator(&str, " ", p))
9,813✔
UNCOV
92
                        return -ENOMEM;
×
93
        }
94

95
        if (!str) {
486✔
96
                str = new0(char, 1);
6✔
97
                if (!str)
6✔
98
                        return -ENOMEM;
99
        }
100

101
        *ret = TAKE_PTR(str);
486✔
102
        return 0;
486✔
103
}
104

105
int capability_set_to_string_negative(uint64_t set, char **ret) {
150✔
106
        _cleanup_free_ char *a = NULL, *b = NULL;
150✔
107
        int r;
150✔
108

109
        assert(ret);
150✔
110

111
        /* Format the specified capability mask both in positive way (i.e. just listing caps) and in negative
112
         * way (i.e. listing only caps that are missing from the full set) and return the shorter version of
113
         * the two. */
114

115
        r = capability_set_to_string(set, &a);
150✔
116
        if (r < 0)
150✔
117
                return r;
118

119
        r = capability_set_to_string(~set & all_capabilities(), &b);
150✔
120
        if (r < 0)
150✔
121
                return r;
122

123
        if (strlen(a) <= 1 + strlen(b))
150✔
124
                *ret = TAKE_PTR(a);
71✔
125
        else {
126
                char *c = strjoin("~", b);
79✔
127
                if (!c)
79✔
128
                        return -ENOMEM;
129

130
                *ret = c;
79✔
131
        }
132

133
        return 0;
134
}
135

136
int capability_set_to_strv(uint64_t set, char ***ret) {
4✔
137
        _cleanup_strv_free_ char **l = NULL;
4✔
138
        int r;
4✔
139

140
        assert(ret);
4✔
141

142
        for (unsigned i = 0; i <= cap_last_cap(); i++) {
168✔
143
                const char *p;
164✔
144

145
                if (!BIT_SET(set, i))
164✔
146
                        continue;
158✔
147

148
                p = CAPABILITY_TO_STRING(i);
6✔
149
                assert(p);
6✔
150

151
                r = strv_extend(&l, p);
6✔
152
                if (r < 0)
6✔
UNCOV
153
                        return r;
×
154
        }
155

156
        *ret = TAKE_PTR(l);
4✔
157
        return 0;
4✔
158
}
159

160
int capability_set_from_string(const char *s, uint64_t *ret) {
1,959✔
161
        uint64_t val = 0;
1,959✔
162
        bool good = true;
1,959✔
163

164
        for (const char *p = s;;) {
1,959✔
165
                _cleanup_free_ char *word = NULL;
10,238✔
166
                int r;
12,197✔
167

168
                r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RELAX);
12,197✔
169
                if (r < 0)
12,197✔
UNCOV
170
                        return r;
×
171
                if (r == 0)
12,197✔
172
                        break;
173

174
                r = capability_from_name(word);
10,238✔
175
                if (r < 0) {
10,238✔
176
                        log_debug_errno(r, "Failed to parse capability '%s', ignoring: %m", word);
10,238✔
177
                        good = false;
178
                } else
179
                        val |= UINT64_C(1) << r;
10,194✔
180
        }
181

182
        if (ret)
1,959✔
183
                *ret = val;
1,959✔
184

185
        return good;
1,959✔
186
}
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