• 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

75.36
/src/basic/memfd-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdio.h>
4
#include <sys/prctl.h>
5
#include <sys/stat.h>
6
#include <unistd.h>
7

8
#include "alloc-util.h"
9
#include "errno-util.h"
10
#include "fd-util.h"
11
#include "memfd-util.h"
12
#include "missing_mman.h"
13
#include "missing_sched.h"
14
#include "string-util.h"
15
#include "utf8.h"
16

17
int memfd_create_wrapper(const char *name, unsigned mode) {
4,691✔
18
        unsigned mode_compat;
4,691✔
19
        int mfd;
4,691✔
20

21
        assert(name);
4,691✔
22

23
        /* Wrapper around memfd_create() which adds compat with older kernels where memfd_create() didn't
24
         * support MFD_EXEC/MFD_NOEXEC_SEAL. (kernel 6.3+) */
25

26
        mfd = RET_NERRNO(memfd_create(name, mode));
4,691✔
UNCOV
27
        if (mfd != -EINVAL)
×
28
                return mfd;
4,691✔
29

UNCOV
30
        mode_compat = mode & ~(MFD_EXEC | MFD_NOEXEC_SEAL);
×
31

UNCOV
32
        if (mode == mode_compat)
×
33
                return mfd;
34

UNCOV
35
        return RET_NERRNO(memfd_create(name, mode_compat));
×
36
}
37

38
int memfd_new_full(const char *name, unsigned extra_flags) {
4,690✔
39
        _cleanup_free_ char *g = NULL;
4,690✔
40

41
        if (!name) {
4,690✔
UNCOV
42
                char pr[TASK_COMM_LEN] = {};
×
43

44
                /* If no name is specified we generate one. We include
45
                 * a hint indicating our library implementation, and
46
                 * add the thread name to it */
47

UNCOV
48
                assert_se(prctl(PR_GET_NAME, (unsigned long) pr) >= 0);
×
49

UNCOV
50
                if (isempty(pr))
×
51
                        name = "sd";
52
                else {
UNCOV
53
                        _cleanup_free_ char *e = NULL;
×
54

UNCOV
55
                        e = utf8_escape_invalid(pr);
×
UNCOV
56
                        if (!e)
×
57
                                return -ENOMEM;
58

59
                        g = strjoin("sd-", e);
×
60
                        if (!g)
×
61
                                return -ENOMEM;
62

63
                        name = g;
×
64
                }
65
        }
66

67
        return memfd_create_wrapper(
4,690✔
68
                        name,
69
                        MFD_CLOEXEC | MFD_NOEXEC_SEAL | extra_flags);
70
}
71

72
static int memfd_add_seals(int fd, unsigned seals) {
4,581✔
73
        assert(fd >= 0);
4,581✔
74

75
        return RET_NERRNO(fcntl(fd, F_ADD_SEALS, seals));
4,581✔
76
}
77

78
static int memfd_get_seals(int fd, unsigned *ret_seals) {
2✔
79
        int r;
2✔
80

81
        assert(fd >= 0);
2✔
82

83
        r = RET_NERRNO(fcntl(fd, F_GET_SEALS));
2✔
UNCOV
84
        if (r < 0)
×
85
                return r;
86

87
        if (ret_seals)
2✔
88
                *ret_seals = r;
2✔
89
        return 0;
90
}
91

92
int memfd_set_sealed(int fd) {
4,581✔
93
        return memfd_add_seals(fd, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
4,581✔
94
}
95

96
int memfd_get_sealed(int fd) {
2✔
97
        unsigned seals;
2✔
98
        int r;
2✔
99

100
        r = memfd_get_seals(fd, &seals);
2✔
101
        if (r < 0)
2✔
102
                return r;
2✔
103

104
        /* We ignore F_SEAL_EXEC here to support older kernels. */
105
        return FLAGS_SET(seals, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_WRITE);
2✔
106
}
107

108
int memfd_get_size(int fd, uint64_t *ret) {
3✔
109
        struct stat stat;
3✔
110

111
        assert(fd >= 0);
3✔
112
        assert(ret);
3✔
113

114
        if (fstat(fd, &stat) < 0)
3✔
UNCOV
115
                return -errno;
×
116

117
        *ret = stat.st_size;
3✔
118
        return 0;
3✔
119
}
120

121
int memfd_set_size(int fd, uint64_t sz) {
2✔
122
        assert(fd >= 0);
2✔
123

124
        return RET_NERRNO(ftruncate(fd, sz));
2✔
125
}
126

127
int memfd_new_and_seal(const char *name, const void *data, size_t sz) {
184✔
128
        _cleanup_close_ int fd = -EBADF;
184✔
129
        int r;
184✔
130

131
        assert(data || sz == 0);
184✔
132

133
        if (sz == SIZE_MAX)
184✔
134
                sz = strlen(data);
183✔
135

136
        fd = memfd_new_full(name, MFD_ALLOW_SEALING);
184✔
137
        if (fd < 0)
184✔
138
                return fd;
139

140
        if (sz > 0) {
184✔
141
                ssize_t n = pwrite(fd, data, sz, 0);
184✔
142
                if (n < 0)
184✔
UNCOV
143
                        return -errno;
×
144
                if ((size_t) n != sz)
184✔
145
                        return -EIO;
146
        }
147

148
        r = memfd_set_sealed(fd);
184✔
149
        if (r < 0)
184✔
UNCOV
150
                return r;
×
151

152
        return TAKE_FD(fd);
153
}
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