• 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

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

3
#include <fcntl.h>
4
#include <sys/ioctl.h>
5
#include <sys/stat.h>
6

7
#include "bitfield.h"
8
#include "chattr-util.h"
9
#include "errno-util.h"
10
#include "fd-util.h"
11
#include "fs-util.h"
12
#include "log.h"
13
#include "string-util.h"
14

15
int chattr_full(
1,078✔
16
              int dir_fd,
17
              const char *path,
18
              unsigned value,
19
              unsigned mask,
20
              unsigned *ret_previous,
21
              unsigned *ret_final,
22
              ChattrApplyFlags flags) {
23

24
        _cleanup_close_ int fd = -EBADF;
1,078✔
25
        unsigned old_attr, new_attr;
1,078✔
26
        int set_flags_errno = 0;
1,078✔
27
        struct stat st;
1,078✔
28

29
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
1,078✔
30

31
        fd = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
1,078✔
32
        if (fd < 0)
1,078✔
33
                return fd;
34

35
        if (fstat(fd, &st) < 0)
1,071✔
UNCOV
36
                return -errno;
×
37

38
        /* Explicitly check whether this is a regular file or directory. If it is anything else (such
39
         * as a device node or fifo), then the ioctl will not hit the file systems but possibly
40
         * drivers, where the ioctl might have different effects. Notably, DRM is using the same
41
         * ioctl() number. */
42

43
        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
1,071✔
44
                return -ENOTTY;
45

46
        if (mask == 0 && !ret_previous && !ret_final)
1,071✔
47
                return 0;
48

49
        if (ioctl(fd, FS_IOC_GETFLAGS, &old_attr) < 0)
1,071✔
UNCOV
50
                return -errno;
×
51

52
        new_attr = (old_attr & ~mask) | (value & mask);
1,071✔
53
        if (new_attr == old_attr) {
1,071✔
54
                if (ret_previous)
124✔
UNCOV
55
                        *ret_previous = old_attr;
×
56
                if (ret_final)
124✔
57
                        *ret_final = old_attr;
×
58
                return 0;
124✔
59
        }
60

61
        if (ioctl(fd, FS_IOC_SETFLAGS, &new_attr) >= 0) {
947✔
62
                unsigned attr;
17✔
63

64
                /* Some filesystems (BTRFS) silently fail when a flag cannot be set. Let's make sure our
65
                 * changes actually went through by querying the flags again and verifying they're equal to
66
                 * the flags we tried to configure. */
67

68
                if (ioctl(fd, FS_IOC_GETFLAGS, &attr) < 0)
17✔
69
                        return -errno;
17✔
70

71
                if (new_attr == attr) {
17✔
72
                        if (ret_previous)
17✔
73
                                *ret_previous = old_attr;
2✔
74
                        if (ret_final)
17✔
UNCOV
75
                                *ret_final = new_attr;
×
76
                        return 1;
17✔
77
                }
78

79
                /* Trigger the fallback logic. */
UNCOV
80
                errno = EINVAL;
×
81
        }
82

83
        if (!ERRNO_IS_IOCTL_NOT_SUPPORTED(errno) || !FLAGS_SET(flags, CHATTR_FALLBACK_BITWISE))
930✔
84
                return -errno;
875✔
85

86
        /* When -EINVAL is returned, incompatible attributes might be simultaneously specified. E.g.,
87
         * compress(c) and nocow(C) attributes cannot be set to files on btrfs. As a fallback, let's try to
88
         * set attributes one by one.
89
         *
90
         * Alternatively, when we get EINVAL or EOPNOTSUPP (or a similar error code) we assume a flag might
91
         * just not be supported, and we can ignore it too */
92

93
        unsigned current_attr = old_attr;
55✔
94

95
        BIT_FOREACH(i, mask) {
137✔
96
                unsigned new_one, mask_one = 1u << i;
82✔
97

98
                new_one = UPDATE_FLAG(current_attr, mask_one, FLAGS_SET(value, mask_one));
82✔
99
                if (new_one == current_attr)
82✔
100
                        continue;
57✔
101

102
                if (ioctl(fd, FS_IOC_SETFLAGS, &new_one) < 0) {
82✔
103
                        if (!ERRNO_IS_IOCTL_NOT_SUPPORTED(errno))
57✔
UNCOV
104
                                return -errno;
×
105

106
                        log_full_errno(FLAGS_SET(flags, CHATTR_WARN_UNSUPPORTED_FLAGS) ? LOG_WARNING : LOG_DEBUG,
112✔
107
                                       errno,
108
                                       "Unable to set file attribute 0x%x on %s, ignoring: %m", mask_one, strna(path));
109

110
                        /* Ensures that we record whether only EOPNOTSUPP&friends are encountered, or if a more serious
111
                         * error (thus worth logging at a different level, etc) was seen too. */
112
                        if (set_flags_errno == 0 || !ERRNO_IS_IOCTL_NOT_SUPPORTED(errno))
57✔
113
                                set_flags_errno = -errno;
55✔
114

115
                        continue;
57✔
116
                }
117

118
                if (ioctl(fd, FS_IOC_GETFLAGS, &current_attr) < 0)
25✔
UNCOV
119
                        return -errno;
×
120
        }
121

122
        if (ret_previous)
55✔
123
                *ret_previous = old_attr;
46✔
124
        if (ret_final)
55✔
125
                *ret_final = current_attr;
46✔
126

127
        /* -ENOANO indicates that some attributes cannot be set. ERRNO_IS_IOCTL_NOT_SUPPORTED indicates that
128
         * all encountered failures were due to flags not supported by the FS, so return a specific error in
129
         * that case, so callers can handle it properly (e.g.: tmpfiles.d can use debug level logging). */
130
        return current_attr == new_attr ? 1 : ERRNO_IS_IOCTL_NOT_SUPPORTED(set_flags_errno) ? set_flags_errno : -ENOANO;
55✔
131
}
132

133
int read_attr_fd(int fd, unsigned *ret) {
401,934✔
134
        struct stat st;
401,934✔
135

136
        assert(fd >= 0);
401,934✔
137
        assert(ret);
401,934✔
138

139
        if (fstat(fd, &st) < 0)
401,934✔
UNCOV
140
                return -errno;
×
141

142
        if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
401,934✔
143
                return -ENOTTY;
144

145
        _cleanup_close_ int fd_close = -EBADF;
401,934✔
146
        fd = fd_reopen_condition(fd, O_RDONLY|O_CLOEXEC|O_NOCTTY, O_PATH, &fd_close); /* drop O_PATH if it is set */
401,928✔
147
        if (fd < 0)
401,928✔
148
                return fd;
149

150
        return RET_NERRNO(ioctl(fd, FS_IOC_GETFLAGS, ret));
599,743✔
151
}
152

153
int read_attr_at(int dir_fd, const char *path, unsigned *ret) {
398,119✔
154
        _cleanup_close_ int fd_close = -EBADF;
398,119✔
155
        int fd;
398,119✔
156

157
        assert(dir_fd >= 0 || dir_fd == AT_FDCWD);
398,119✔
158
        assert(ret);
398,119✔
159

160
        if (isempty(path) && dir_fd != AT_FDCWD)
398,119✔
161
                fd = dir_fd;
162
        else {
163
                fd_close = xopenat(dir_fd, path, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NOFOLLOW);
1,574✔
164
                if (fd_close < 0)
1,574✔
165
                        return fd_close;
166

167
                fd = fd_close;
168
        }
169

170
        return read_attr_fd(fd, ret);
397,880✔
171
}
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