• 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

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

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

7
#include "alloc-util.h"
8
#include "errno-util.h"
9
#include "fd-util.h"
10
#include "fs-util.h"
11
#include "log.h"
12
#include "path-util.h"
13
#include "string-util.h"
14
#include "sync-util.h"
15

16
int fsync_directory_of_file(int fd) {
1,789,098✔
17
        _cleanup_close_ int dfd = -EBADF;
1,789,098✔
18
        struct stat st;
1,789,098✔
19
        int r;
1,789,098✔
20

21
        assert(fd >= 0);
1,789,098✔
22

23
        /* We only reasonably can do this for regular files and directories, or for O_PATH fds, hence check
24
         * for the inode type first */
25
        if (fstat(fd, &st) < 0)
1,789,098✔
UNCOV
26
                return -errno;
×
27

28
        if (S_ISDIR(st.st_mode)) {
1,789,098✔
29
                dfd = openat(fd, "..", O_RDONLY|O_DIRECTORY|O_CLOEXEC, 0);
46✔
30
                if (dfd < 0)
46✔
UNCOV
31
                        return -errno;
×
32

33
        } else if (!S_ISREG(st.st_mode)) { /* Regular files are OK regardless if O_PATH or not, for all other
1,789,052✔
34
                                            * types check O_PATH flag */
35
                r = fd_is_opath(fd);
4✔
36
                if (r < 0)
4✔
37
                        return r;
38
                if (!r) /* If O_PATH this refers to the inode in the fs, in which case we can sensibly do
4✔
39
                         * what is requested. Otherwise this refers to a socket, fifo or device node, where
40
                         * the concept of a containing directory doesn't make too much sense. */
41
                        return -ENOTTY;
42
        }
43

44
        if (dfd < 0) {
45
                _cleanup_free_ char *path = NULL;
1,789,052✔
46

47
                r = fd_get_path(fd, &path);
1,789,052✔
48
                if (r < 0) {
1,789,052✔
UNCOV
49
                        log_debug_errno(r, "Failed to query /proc/self/fd/%d%s: %m",
×
50
                                        fd,
51
                                        r == -ENOSYS ? ", ignoring" : "");
52

UNCOV
53
                        if (r == -ENOSYS)
×
54
                                /* If /proc is not available, we're most likely running in some
55
                                 * chroot environment, and syncing the directory is not very
56
                                 * important in that case. Let's just silently do nothing. */
57
                                return 0;
58

UNCOV
59
                        return r;
×
60
                }
61

62
                if (!path_is_absolute(path))
1,789,052✔
63
                        return -EINVAL;
64

65
                dfd = open_parent(path, O_CLOEXEC|O_NOFOLLOW, 0);
1,789,052✔
66
                if (dfd < 0)
1,789,052✔
67
                        return dfd;
68
        }
69

70
        return RET_NERRNO(fsync(dfd));
1,789,098✔
71
}
72

73
int fsync_full(int fd) {
1,787,159✔
74
        int r, q;
1,787,159✔
75

76
        /* Sync both the file and the directory */
77

78
        r = RET_NERRNO(fsync(fd));
1,787,159✔
79

80
        q = fsync_directory_of_file(fd);
1,787,159✔
81
        if (r < 0) /* Return earlier error */
1,787,159✔
82
                return r;
83
        if (q == -ENOTTY) /* Ignore if the 'fd' refers to a block device or so which doesn't really have a
1,787,159✔
84
                           * parent dir */
UNCOV
85
                return 0;
×
86
        return q;
87
}
88

89
int fsync_path_at(int at_fd, const char *path) {
1✔
90
        _cleanup_close_ int opened_fd = -EBADF;
1✔
91
        int fd;
1✔
92

93
        if (isempty(path)) {
1✔
94
                if (at_fd == AT_FDCWD) {
×
95
                        opened_fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
×
96
                        if (opened_fd < 0)
×
UNCOV
97
                                return -errno;
×
98

99
                        fd = opened_fd;
100
                } else
101
                        fd = at_fd;
102
        } else {
103
                opened_fd = openat(at_fd, path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
1✔
104
                if (opened_fd < 0)
1✔
UNCOV
105
                        return -errno;
×
106

107
                fd = opened_fd;
108
        }
109

110
        return RET_NERRNO(fsync(fd));
1✔
111
}
112

113
int fsync_parent_at(int at_fd, const char *path) {
132✔
114
        _cleanup_close_ int opened_fd = -EBADF;
132✔
115

116
        if (isempty(path)) {
132✔
117
                if (at_fd != AT_FDCWD)
×
UNCOV
118
                        return fsync_directory_of_file(at_fd);
×
119

120
                opened_fd = open("..", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
×
121
                if (opened_fd < 0)
×
UNCOV
122
                        return -errno;
×
123

UNCOV
124
                return RET_NERRNO(fsync(opened_fd));
×
125
        }
126

127
        opened_fd = openat(at_fd, path, O_PATH|O_CLOEXEC|O_NOFOLLOW);
132✔
128
        if (opened_fd < 0)
132✔
UNCOV
129
                return -errno;
×
130

131
        return fsync_directory_of_file(opened_fd);
132✔
132
}
133

134
int fsync_path_and_parent_at(int at_fd, const char *path) {
32✔
135
        _cleanup_close_ int opened_fd = -EBADF;
32✔
136

137
        if (isempty(path)) {
32✔
138
                if (at_fd != AT_FDCWD)
×
UNCOV
139
                        return fsync_full(at_fd);
×
140

UNCOV
141
                opened_fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
×
142
        } else
143
                opened_fd = openat(at_fd, path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC);
32✔
144
        if (opened_fd < 0)
32✔
UNCOV
145
                return -errno;
×
146

147
        return fsync_full(opened_fd);
32✔
148
}
149

150
int syncfs_path(int at_fd, const char *path) {
617✔
151
        _cleanup_close_ int fd = -EBADF;
617✔
152

153
        if (isempty(path)) {
617✔
154
                if (at_fd != AT_FDCWD)
×
UNCOV
155
                        return RET_NERRNO(syncfs(at_fd));
×
156

UNCOV
157
                fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
×
158
        } else
159
                fd = openat(at_fd, path, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
617✔
160
        if (fd < 0)
617✔
UNCOV
161
                return -errno;
×
162

163
        return RET_NERRNO(syncfs(fd));
617✔
164
}
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