• 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

97.83
/src/basic/extract-word.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "alloc-util.h"
4
#include "escape.h"
5
#include "extract-word.h"
6
#include "log.h"
7
#include "string-util.h"
8
#include "utf8.h"
9

10
int extract_first_word(const char **p, char **ret, const char *separators, ExtractFlags flags) {
14,165,416✔
11
        _cleanup_free_ char *s = NULL;
14,165,416✔
12
        size_t sz = 0;
14,165,416✔
13
        char quote = 0;                 /* 0 or ' or " */
14,165,416✔
14
        bool backslash = false;         /* whether we've just seen a backslash */
14,165,416✔
15
        char c;
14,165,416✔
16
        int r;
14,165,416✔
17

18
        assert(p);
14,165,416✔
19
        assert(ret);
14,165,416✔
20
        assert(!FLAGS_SET(flags, EXTRACT_KEEP_QUOTE | EXTRACT_UNQUOTE));
14,165,416✔
21

22
        /* Bail early if called after last value or with no input */
23
        if (!*p)
14,165,416✔
24
                goto finish;
1,550,747✔
25
        c = **p;
12,614,669✔
26

27
        if (!separators)
12,614,669✔
28
                separators = WHITESPACE;
8,841,714✔
29

30
        /* Parses the first word of a string, and returns it in
31
         * *ret. Removes all quotes in the process. When parsing fails
32
         * (because of an uneven number of quotes or similar), leaves
33
         * the pointer *p at the first invalid character. */
34

35
        if (flags & EXTRACT_DONT_COALESCE_SEPARATORS)
12,614,669✔
36
                if (!GREEDY_REALLOC(s, sz+1))
430,261✔
37
                        return -ENOMEM;
38

39
        for (;; (*p)++, c = **p) {
1,507✔
40
                if (c == 0)
12,616,176✔
41
                        goto finish_force_terminate;
225,572✔
42
                else if (strchr(separators, c)) {
12,390,604✔
43
                        if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
106,398✔
44
                                if (!(flags & EXTRACT_RETAIN_SEPARATORS))
104,891✔
45
                                        (*p)++;
104,867✔
46
                                goto finish_force_next;
104,891✔
47
                        }
48
                } else {
49
                        /* We found a non-blank character, so we will always
50
                         * want to return a string (even if it is empty),
51
                         * allocate it here. */
52
                        if (!GREEDY_REALLOC(s, sz+1))
12,284,206✔
53
                                return -ENOMEM;
54
                        break;
55
                }
56
        }
57

58
        for (;; (*p)++, c = **p) {
18,784✔
59
                if (backslash) {
12,302,990✔
60
                        if (!GREEDY_REALLOC(s, sz+7))
447✔
61
                                return -ENOMEM;
62

63
                        if (c == 0) {
447✔
64
                                if ((flags & EXTRACT_UNESCAPE_RELAX) &&
28✔
65
                                    (quote == 0 || flags & EXTRACT_RELAX)) {
6✔
66
                                        /* If we find an unquoted trailing backslash and we're in
67
                                         * EXTRACT_UNESCAPE_RELAX mode, keep it verbatim in the
68
                                         * output.
69
                                         *
70
                                         * Unbalanced quotes will only be allowed in EXTRACT_RELAX
71
                                         * mode, EXTRACT_UNESCAPE_RELAX mode does not allow them.
72
                                         */
73
                                        s[sz++] = '\\';
9✔
74
                                        goto finish_force_terminate;
9✔
75
                                }
76
                                if (flags & EXTRACT_RELAX)
15✔
77
                                        goto finish_force_terminate;
5✔
78
                                return -EINVAL;
79
                        }
80

81
                        if (flags & (EXTRACT_CUNESCAPE|EXTRACT_UNESCAPE_SEPARATORS)) {
419✔
82
                                bool eight_bit = false;
304✔
83
                                char32_t u;
304✔
84

85
                                if ((flags & EXTRACT_CUNESCAPE) &&
304✔
86
                                    (r = cunescape_one(*p, SIZE_MAX, &u, &eight_bit, false)) >= 0) {
78✔
87
                                        /* A valid escaped sequence */
88
                                        assert(r >= 1);
44✔
89

90
                                        (*p) += r - 1;
44✔
91

92
                                        if (eight_bit)
44✔
93
                                                s[sz++] = u;
13✔
94
                                        else
95
                                                sz += utf8_encode_unichar(s + sz, u);
31✔
96
                                } else if ((flags & EXTRACT_UNESCAPE_SEPARATORS) &&
260✔
97
                                           (strchr(separators, **p) || **p == '\\'))
235✔
98
                                        /* An escaped separator char or the escape char itself */
99
                                        s[sz++] = c;
166✔
100
                                else if (flags & EXTRACT_UNESCAPE_RELAX) {
94✔
101
                                        s[sz++] = '\\';
81✔
102
                                        s[sz++] = c;
81✔
103
                                } else
104
                                        return -EINVAL;
13✔
105
                        } else
106
                                s[sz++] = c;
115✔
107

108
                        backslash = false;
109

110
                } else if (quote != 0) {     /* inside either single or double quotes */
12,302,543✔
111
                        for (;; (*p)++, c = **p) {
362,321✔
112
                                if (c == 0) {
371,326✔
113
                                        if (flags & EXTRACT_RELAX)
30✔
114
                                                goto finish_force_terminate;
6✔
115
                                        return -EINVAL;
116
                                } else if (c == quote) {        /* found the end quote */
371,296✔
117
                                        quote = 0;
8,944✔
118
                                        if (flags & EXTRACT_UNQUOTE)
8,944✔
119
                                                break;
120
                                } else if (c == '\\' && !(flags & EXTRACT_RETAIN_ESCAPE)) {
362,352✔
121
                                        backslash = true;
122
                                        break;
123
                                }
124

125
                                if (!GREEDY_REALLOC(s, sz+2))
362,330✔
126
                                        return -ENOMEM;
127

128
                                s[sz++] = c;
362,330✔
129

130
                                if (quote == 0)
362,330✔
131
                                        break;
132
                        }
133

134
                } else {
135
                        for (;; (*p)++, c = **p) {
224,377,289✔
136
                                if (c == 0)
236,670,827✔
137
                                        goto finish_force_terminate;
2,251,769✔
138
                                else if (IN_SET(c, '\'', '"') && (flags & (EXTRACT_KEEP_QUOTE | EXTRACT_UNQUOTE))) {
234,419,058✔
139
                                        quote = c;
8,987✔
140
                                        if (flags & EXTRACT_UNQUOTE)
8,987✔
141
                                                break;
142
                                } else if (c == '\\' && !(flags & EXTRACT_RETAIN_ESCAPE)) {
234,410,071✔
143
                                        backslash = true;
144
                                        break;
145
                                } else if (strchr(separators, c)) {
234,409,655✔
146
                                        if (flags & EXTRACT_DONT_COALESCE_SEPARATORS) {
10,032,366✔
147
                                                if (!(flags & EXTRACT_RETAIN_SEPARATORS))
168,042✔
148
                                                        (*p)++;
168,013✔
149
                                                goto finish_force_next;
168,042✔
150
                                        }
151
                                        if (!(flags & EXTRACT_RETAIN_SEPARATORS))
9,864,324✔
152
                                                /* Skip additional coalesced separators. */
153
                                                for (;; (*p)++, c = **p) {
10,009,221✔
154
                                                        if (c == 0)
19,873,515✔
155
                                                                goto finish_force_terminate;
154,733✔
156
                                                        if (!strchr(separators, c))
19,718,782✔
157
                                                                break;
158
                                                }
159
                                        goto finish;
9,709,591✔
160

161
                                }
162

163
                                if (!GREEDY_REALLOC(s, sz+2))
224,377,299✔
164
                                        return -ENOMEM;
165

166
                                s[sz++] = c;
224,377,299✔
167

168
                                if (quote != 0)
224,377,299✔
169
                                        break;
170
                        }
171
                }
172
        }
173

174
finish_force_terminate:
2,632,094✔
175
        *p = NULL;
2,632,094✔
176
finish:
13,892,432✔
177
        if (!s) {
13,892,432✔
178
                *p = NULL;
1,673,154✔
179
                *ret = NULL;
1,673,154✔
180
                return 0;
1,673,154✔
181
        }
182

183
finish_force_next:
12,219,278✔
184
        s[sz] = 0;
12,492,211✔
185
        *ret = TAKE_PTR(s);
12,492,211✔
186

187
        return 1;
12,492,211✔
188
}
189

190
int extract_first_word_and_warn(
43,971✔
191
                const char **p,
192
                char **ret,
193
                const char *separators,
194
                ExtractFlags flags,
195
                const char *unit,
196
                const char *filename,
197
                unsigned line,
198
                const char *rvalue) {
199

200
        /* Try to unquote it, if it fails, warn about it and try again
201
         * but this time using EXTRACT_UNESCAPE_RELAX to keep the
202
         * backslashes verbatim in invalid escape sequences. */
203

204
        const char *save;
43,971✔
205
        int r;
43,971✔
206

207
        save = *p;
43,971✔
208
        r = extract_first_word(p, ret, separators, flags);
43,971✔
209
        if (r >= 0)
43,971✔
210
                return r;
211

212
        if (r == -EINVAL && !(flags & EXTRACT_UNESCAPE_RELAX)) {
16✔
213

214
                /* Retry it with EXTRACT_UNESCAPE_RELAX. */
215
                *p = save;
16✔
216
                r = extract_first_word(p, ret, separators, flags|EXTRACT_UNESCAPE_RELAX);
16✔
217
                if (r >= 0) {
16✔
218
                        /* It worked this time, hence it must have been an invalid escape sequence. */
219
                        log_syntax(unit, LOG_WARNING, filename, line, EINVAL, "Ignoring unknown escape sequences: \"%s\"", *ret);
9✔
220
                        return r;
9✔
221
                }
222

223
                /* If it's still EINVAL; then it must be unbalanced quoting, report this. */
224
                if (r == -EINVAL)
7✔
225
                        return log_syntax(unit, LOG_ERR, filename, line, r, "Unbalanced quoting, ignoring: \"%s\"", rvalue);
7✔
226
        }
227

228
        /* Can be any error, report it */
UNCOV
229
        return log_syntax(unit, LOG_ERR, filename, line, r, "Unable to decode word \"%s\", ignoring: %m", rvalue);
×
230
}
231

232
/* We pass ExtractFlags as unsigned int (to avoid undefined behaviour when passing
233
 * an object that undergoes default argument promotion as an argument to va_start).
234
 * Let's make sure that ExtractFlags fits into an unsigned int. */
235
assert_cc(sizeof(enum ExtractFlags) <= sizeof(unsigned));
236

237
int extract_many_words_internal(const char **p, const char *separators, unsigned flags, ...) {
1,071,659✔
238
        va_list ap;
1,071,659✔
239
        unsigned n = 0;
1,071,659✔
240
        int r;
1,071,659✔
241

242
        /* Parses a number of words from a string, stripping any quotes if necessary. */
243

244
        assert(p);
1,071,659✔
245

246
        /* Count how many words are expected */
247
        va_start(ap, flags);
1,071,659✔
248
        while (va_arg(ap, char**))
3,500,499✔
249
                n++;
2,428,840✔
250
        va_end(ap);
1,071,659✔
251

252
        if (n == 0)
1,071,659✔
253
                return 0;
1,071,659✔
254

255
        /* Read all words into a temporary array */
256
        char **l = newa0(char*, n);
1,071,658✔
257
        unsigned c;
1,071,658✔
258

259
        for (c = 0; c < n; c++) {
3,430,076✔
260
                r = extract_first_word(p, &l[c], separators, flags);
2,384,450✔
261
                if (r < 0) {
2,384,450✔
UNCOV
262
                        free_many_charp(l, c);
×
UNCOV
263
                        return r;
×
264
                }
265
                if (r == 0)
2,384,450✔
266
                        break;
267
        }
268

269
        /* If we managed to parse all words, return them in the passed in parameters */
270
        va_start(ap, flags);
1,071,658✔
271
        FOREACH_ARRAY(i, l, n) {
3,500,498✔
272
                char **v = ASSERT_PTR(va_arg(ap, char**));
2,428,840✔
273
                *v = *i;
2,428,840✔
274
        }
275
        va_end(ap);
1,071,658✔
276

277
        return c;
1,071,658✔
278
}
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