• 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

81.82
/src/basic/errno-util.h
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3

4
#include <string.h>
5

6
#include "forward.h"
7

8
/* strerror(3) says that glibc uses a maximum length of 1024 bytes. */
9
#define ERRNO_BUF_LEN           1024
10

11
/* Note: the lifetime of the compound literal is the immediately surrounding block,
12
 * see C11 §6.5.2.5, and
13
 * https://stackoverflow.com/questions/34880638/compound-literal-lifetime-and-if-blocks
14
 *
15
 * Note that we use the GNU variant of strerror_r() here. */
16
#define STRERROR(errnum) strerror_r(ABS(errnum), (char[ERRNO_BUF_LEN]){}, ERRNO_BUF_LEN)
17

18
/* A helper to print an error message or message for functions that return 0 on EOF.
19
 * Note that we can't use ({ … }) to define a temporary variable, so errnum is
20
 * evaluated twice. */
21
#define STRERROR_OR_EOF(errnum) ((errnum) != 0 ? STRERROR(errnum) : "Unexpected EOF")
22

23
static inline void _reset_errno_(int *saved_errno) {
73,218,550✔
24
        if (*saved_errno < 0) /* Invalidated by UNPROTECT_ERRNO? */
73,218,550✔
25
                return;
26

27
        errno = *saved_errno;
73,211,361✔
28
}
29

30
#define PROTECT_ERRNO                           \
31
        _cleanup_(_reset_errno_) _unused_ int _saved_errno_ = errno
32

33
#define UNPROTECT_ERRNO                         \
34
        do {                                    \
35
                errno = _saved_errno_;          \
36
                _saved_errno_ = -1;             \
37
        } while (false)
38

39
#define LOCAL_ERRNO(value)                      \
40
        PROTECT_ERRNO;                          \
41
        errno = ABS(value)
42

43
#define return_with_errno(r, err)                     \
44
        do {                                          \
45
                errno = ABS(err);                     \
46
                return r;                             \
47
        } while (false)
48

49
static inline int negative_errno(void) {
2,767,679✔
50
        /* This helper should be used to shut up gcc if you know 'errno' is
51
         * negative. Instead of "return -errno;", use "return negative_errno();"
52
         * It will suppress bogus gcc warnings in case it assumes 'errno' might
53
         * be 0 and thus the caller's error-handling might not be triggered. */
54
        assert_return(errno > 0, -EINVAL);
2,767,679✔
55

56
        return -errno;
2,767,679✔
57
}
58

59
static inline int RET_NERRNO(int ret) {
39,265,439✔
60

61
        /* Helper to wrap system calls in to make them return negative errno errors. This brings system call
62
         * error handling in sync with how we usually handle errors in our own code, i.e. with immediate
63
         * returning of negative errno. Usage is like this:
64
         *
65
         *     …
66
         *     r = RET_NERRNO(unlink(t));
67
         *     …
68
         *
69
         * or
70
         *
71
         *     …
72
         *     fd = RET_NERRNO(open("/etc/fstab", O_RDONLY|O_CLOEXEC));
73
         *     …
74
         */
75

76
        if (ret < 0)
39,266,229✔
77
                return negative_errno();
2,767,623✔
78

79
        return ret;
80
}
81

82
/* Collect possible errors in <acc>, so that the first error can be returned.
83
 * Returns (possibly updated) <acc>. */
84
#define RET_GATHER(acc, err)                    \
85
        ({                                      \
86
                int *__a = &(acc), __e = (err); \
87
                if (*__a >= 0 && __e < 0)       \
88
                        *__a = __e;             \
89
                *__a;                           \
90
        })
91

92
static inline int errno_or_else(int fallback) {
71,738✔
93
        /* To be used when invoking library calls where errno handling is not defined clearly: we return
94
         * errno if it is set, and the specified error otherwise. The idea is that the caller initializes
95
         * errno to zero before doing an API call, and then uses this helper to retrieve a somewhat useful
96
         * error code */
97
        if (errno > 0)
71,738✔
98
                return -errno;
21✔
99

100
        return -ABS(fallback);
101
}
102

103
/* abs(3) says: Trying to take the absolute value of the most negative integer is not defined. */
104
#define _DEFINE_ABS_WRAPPER(name)                         \
105
        static inline bool ERRNO_IS_##name(intmax_t r) {  \
106
                if (r == INTMAX_MIN)                      \
107
                        return false;                     \
108
                return ERRNO_IS_NEG_##name(-ABS(r));      \
109
        }
110

111
/* For send()/recv() or read()/write(). */
112
static inline bool ERRNO_IS_NEG_TRANSIENT(intmax_t r) {
3,605,183✔
113
        return IN_SET(r,
3,604,958✔
114
                      -EAGAIN,
115
                      -EINTR);
116
}
117
_DEFINE_ABS_WRAPPER(TRANSIENT);
5,958✔
118

119
/* Hint #1: ENETUNREACH happens if we try to connect to "non-existing" special IP addresses, such as ::5.
120
 *
121
 * Hint #2: The kernel sends e.g., EHOSTUNREACH or ENONET to userspace in some ICMP error cases.  See the
122
 *          icmp_err_convert[] in net/ipv4/icmp.c in the kernel sources.
123
 *
124
 * Hint #3: When asynchronous connect() on TCP fails because the host never acknowledges a single packet,
125
 *          kernel tells us that with ETIMEDOUT, see tcp(7). */
126
static inline bool ERRNO_IS_NEG_DISCONNECT(intmax_t r) {
659,415✔
127
        return IN_SET(r,
659,415✔
128
                      -ECONNABORTED,
129
                      -ECONNREFUSED,
130
                      -ECONNRESET,
131
                      -EHOSTDOWN,
132
                      -EHOSTUNREACH,
133
                      -ENETDOWN,
134
                      -ENETRESET,
135
                      -ENETUNREACH,
136
                      -ENONET,
137
                      -ENOPROTOOPT,
138
                      -ENOTCONN,
139
                      -EPIPE,
140
                      -EPROTO,
141
                      -ESHUTDOWN,
142
                      -ETIMEDOUT);
143
}
144
_DEFINE_ABS_WRAPPER(DISCONNECT);
2,653✔
145

146
/* Transient errors we might get on accept() that we should ignore. As per error handling comment in
147
 * the accept(2) man page. */
UNCOV
148
static inline bool ERRNO_IS_NEG_ACCEPT_AGAIN(intmax_t r) {
×
UNCOV
149
        return ERRNO_IS_NEG_DISCONNECT(r) ||
×
150
                ERRNO_IS_NEG_TRANSIENT(r) ||
×
151
                r == -EOPNOTSUPP;
152
}
UNCOV
153
_DEFINE_ABS_WRAPPER(ACCEPT_AGAIN);
×
154

155
/* Resource exhaustion, could be our fault or general system trouble */
156
static inline bool ERRNO_IS_NEG_RESOURCE(intmax_t r) {
1,297✔
157
        return IN_SET(r,
1,297✔
158
                      -EMFILE,
159
                      -ENFILE,
160
                      -ENOMEM);
161
}
UNCOV
162
_DEFINE_ABS_WRAPPER(RESOURCE);
×
163

164
/* Seven different errors for "operation/system call/socket feature not supported" */
165
static inline bool ERRNO_IS_NEG_NOT_SUPPORTED(intmax_t r) {
302,193✔
166
        return IN_SET(r,
98,236✔
167
                      -EOPNOTSUPP,
168
                      -ENOTTY,
169
                      -ENOSYS,
170
                      -EAFNOSUPPORT,
171
                      -EPFNOSUPPORT,
172
                      -EPROTONOSUPPORT,
173
                      -ESOCKTNOSUPPORT,
174
                      -ENOPROTOOPT);
175
}
176
_DEFINE_ABS_WRAPPER(NOT_SUPPORTED);
9,041✔
177

178
/* ioctl() with unsupported command/arg might additionally return EINVAL */
179
static inline bool ERRNO_IS_NEG_IOCTL_NOT_SUPPORTED(intmax_t r) {
200,064✔
180
        return ERRNO_IS_NEG_NOT_SUPPORTED(r) || r == -EINVAL;
200,064✔
181
}
182
_DEFINE_ABS_WRAPPER(IOCTL_NOT_SUPPORTED);
200,064✔
183

184
/* Two different errors for access problems */
185
static inline bool ERRNO_IS_NEG_PRIVILEGE(intmax_t r) {
699,684✔
186
        return IN_SET(r,
695,907✔
187
                      -EACCES,
188
                      -EPERM);
189
}
190
_DEFINE_ABS_WRAPPER(PRIVILEGE);
3,845✔
191

192
/* Three different errors for "not enough disk space" */
UNCOV
193
static inline bool ERRNO_IS_NEG_DISK_SPACE(intmax_t r) {
×
UNCOV
194
        return IN_SET(r,
×
195
                      -ENOSPC,
196
                      -EDQUOT,
197
                      -EFBIG);
198
}
UNCOV
199
_DEFINE_ABS_WRAPPER(DISK_SPACE);
×
200

201
/* Three different errors for "this device does not quite exist" */
202
static inline bool ERRNO_IS_NEG_DEVICE_ABSENT(intmax_t r) {
1,211,522✔
203
        return IN_SET(r,
1,211,522✔
204
                      -ENODEV,
205
                      -ENXIO,
206
                      -ENOENT);
207
}
208
_DEFINE_ABS_WRAPPER(DEVICE_ABSENT);
136,002✔
209

210
/* Quite often we want to handle cases where the backing FS doesn't support extended attributes at all and
211
 * where it simply doesn't have the requested xattr the same way */
212
static inline bool ERRNO_IS_NEG_XATTR_ABSENT(intmax_t r) {
41,997✔
213
        return r == -ENODATA ||
41,997✔
214
                ERRNO_IS_NEG_NOT_SUPPORTED(r);
41,997✔
215
}
216
_DEFINE_ABS_WRAPPER(XATTR_ABSENT);
31,813✔
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