• 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

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

3
#include <stdio.h>
4

5
#include "af-list.h"
6
#include "alloc-util.h"
7
#include "fileio.h"
8
#include "hashmap.h"
9
#include "log.h"
10
#include "parse-util.h"
11
#include "path-util.h"
12
#include "socket-util.h"
13
#include "string-util.h"
14
#include "sysctl-util.h"
15

16
char* sysctl_normalize(char *s) {
31,607✔
17
        char *n;
31,607✔
18

19
        n = strpbrk(s, "/.");
31,607✔
20

21
        /* If the first separator is a slash, the path is
22
         * assumed to be normalized and slashes remain slashes
23
         * and dots remains dots. */
24

25
        if (n && *n == '.')
31,607✔
26
                /* Dots become slashes and slashes become dots. Fun. */
27
                do {
61,080✔
28
                        if (*n == '.')
61,080✔
29
                                *n = '/';
61,078✔
30
                        else
31
                                *n = '.';
2✔
32

33
                        n = strpbrk(n + 1, "/.");
61,080✔
34
                } while (n);
61,080✔
35

36
        path_simplify(s);
31,607✔
37

38
        /* Kill the leading slash, but keep the first character of the string in the same place. */
39
        if (s[0] == '/' && s[1] != 0)
31,607✔
40
                memmove(s, s+1, strlen(s));
3,662✔
41

42
        return s;
31,607✔
43
}
44

45
static int shadow_update(Hashmap **shadow, const char *property, const char *value) {
9,809✔
46
        _cleanup_free_ char *k = NULL, *v = NULL, *cur_k = NULL, *cur_v = NULL;
9,809✔
47
        int r;
9,809✔
48

49
        assert(property);
9,809✔
50
        assert(value);
9,809✔
51

52
        if (!shadow)
9,809✔
53
                return 0;
54

55
        k = strdup(property);
4,066✔
56
        if (!k)
4,066✔
57
                return -ENOMEM;
58

59
        v = strdup(value);
4,066✔
60
        if (!v)
4,066✔
61
                return -ENOMEM;
62

63
        cur_v = hashmap_remove2(*shadow, k, (void**)&cur_k);
4,066✔
64

65
        r = hashmap_ensure_put(shadow, &path_hash_ops_free_free, k, v);
4,066✔
66
        if (r < 0) {
4,066✔
UNCOV
67
                assert(r != -EEXIST);
×
68

69
                return r;
70
        }
71

72
        TAKE_PTR(k);
73
        TAKE_PTR(v);
74

75
        return 0;
76
}
77

78
int sysctl_write_full(const char *property, const char *value, Hashmap **shadow) {
9,809✔
79
        char *p;
9,809✔
80
        int r;
9,809✔
81

82
        assert(property);
9,809✔
83
        assert(value);
9,809✔
84

85
        p = strjoina("/proc/sys/", property);
49,045✔
86

87
        path_simplify(p);
9,809✔
88
        if (!path_is_normalized(p))
9,809✔
89
                return -EINVAL;
90

91
        log_debug("Setting '%s' to '%s'", p, value);
9,809✔
92

93
        r = shadow_update(shadow, p, value);
9,809✔
94
        if (r < 0)
9,809✔
95
                return r;
96

97
        return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER | WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL);
9,809✔
98
}
99

100
int sysctl_writef(const char *property, const char *format, ...) {
45✔
101
        _cleanup_free_ char *v = NULL;
45✔
102
        va_list ap;
45✔
103
        int r;
45✔
104

105
        va_start(ap, format);
45✔
106
        r = vasprintf(&v, format, ap);
45✔
107
        va_end(ap);
45✔
108

109
        if (r < 0)
45✔
110
                return -ENOMEM;
111

112
        return sysctl_write(property, v);
45✔
113
}
114

115
static const char* af_to_sysctl_dir(int af) {
106,994✔
116
        if (af == AF_MPLS)
106,994✔
117
                return "mpls";
118

119
        return af_to_ipv4_ipv6(af);
106,993✔
120
}
121

122
int sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value, Hashmap **shadow) {
4,036✔
123
        const char *p;
4,036✔
124

125
        assert(property);
4,036✔
126
        assert(value);
4,036✔
127

128
        if (!IN_SET(af, AF_INET, AF_INET6, AF_MPLS))
4,036✔
129
                return -EAFNOSUPPORT;
130

131
        if (ifname) {
4,036✔
132
                if (!ifname_valid_full(ifname, IFNAME_VALID_SPECIAL))
4,035✔
133
                        return -EINVAL;
134

135
                p = strjoina("net/", af_to_sysctl_dir(af), "/conf/", ifname, "/", property);
52,455✔
136
        } else
137
                p = strjoina("net/", af_to_sysctl_dir(af), "/", property);
9✔
138

139
        return sysctl_write_full(p, value, shadow);
4,036✔
140
}
141

142
int sysctl_write_ip_property_boolean(int af, const char *ifname, const char *property, bool value, Hashmap **shadow) {
2,357✔
143
        return sysctl_write_ip_property(af, ifname, property, one_zero(value), shadow);
3,822✔
144
}
145

146
int sysctl_write_ip_neighbor_property(int af, const char *ifname, const char *property, const char *value, Hashmap **shadow) {
32✔
147
        const char *p;
32✔
148

149
        assert(property);
32✔
150
        assert(value);
32✔
151
        assert(ifname);
32✔
152

153
        if (!IN_SET(af, AF_INET, AF_INET6))
32✔
154
                return -EAFNOSUPPORT;
155

156
        if (ifname) {
32✔
157
                if (!ifname_valid_full(ifname, IFNAME_VALID_SPECIAL))
32✔
158
                        return -EINVAL;
159
                p = strjoina("net/", af_to_ipv4_ipv6(af), "/neigh/", ifname, "/", property);
416✔
160
        } else
161
                p = strjoina("net/", af_to_ipv4_ipv6(af), "/neigh/default/", property);
×
162

163
        return sysctl_write_full(p, value, shadow);
32✔
164
}
165

166
int sysctl_write_ip_neighbor_property_uint32(int af, const char *ifname, const char *property, uint32_t value, Hashmap **shadow) {
32✔
167
        char buf[DECIMAL_STR_MAX(uint32_t)];
32✔
168
        xsprintf(buf, "%u", value);
32✔
169
        return sysctl_write_ip_neighbor_property(af, ifname, property, buf, shadow);
32✔
170
}
171

172
int sysctl_read(const char *property, char **ret) {
102,960✔
173
        char *p;
102,960✔
174
        int r;
102,960✔
175

176
        assert(property);
102,960✔
177

178
        p = strjoina("/proc/sys/", property);
514,800✔
179

180
        path_simplify(p);
102,960✔
181
        if (!path_is_normalized(p)) /* Filter out attempts to write to /proc/sys/../../…, just in case */
102,960✔
182
                return -EINVAL;
183

184
        r = read_full_virtual_file(p, ret, NULL);
102,960✔
185
        if (r < 0)
102,960✔
186
                return r;
187
        if (ret)
102,959✔
188
                delete_trailing_chars(*ret, NEWLINE);
102,959✔
189

190
        return r;
191
}
192

193
int sysctl_read_ip_property(int af, const char *ifname, const char *property, char **ret) {
102,958✔
194
        const char *p;
102,958✔
195

196
        assert(property);
102,958✔
197

198
        if (!IN_SET(af, AF_INET, AF_INET6, AF_MPLS))
102,958✔
199
                return -EAFNOSUPPORT;
200

201
        if (ifname) {
102,958✔
202
                if (!ifname_valid_full(ifname, IFNAME_VALID_SPECIAL))
102,813✔
203
                        return -EINVAL;
204

205
                p = strjoina("net/", af_to_sysctl_dir(af), "/conf/", ifname, "/", property);
1,336,569✔
206
        } else
207
                p = strjoina("net/", af_to_sysctl_dir(af), "/", property);
1,305✔
208

209
        return sysctl_read(p, ret);
102,958✔
210
}
211

212
int sysctl_read_ip_property_int(int af, const char *ifname, const char *property, int *ret) {
144✔
213
        _cleanup_free_ char *s = NULL;
144✔
214
        int r;
144✔
215

216
        assert(ret);
144✔
217

218
        r = sysctl_read_ip_property(af, ifname, property, &s);
144✔
219
        if (r < 0)
144✔
220
                return r;
221

222
        return safe_atoi(s, ret);
144✔
223
}
224

225
int sysctl_read_ip_property_uint32(int af, const char *ifname, const char *property, uint32_t *ret) {
46✔
226
        _cleanup_free_ char *s = NULL;
46✔
227
        int r;
46✔
228

229
        assert(ret);
46✔
230

231
        r = sysctl_read_ip_property(af, ifname, property, &s);
46✔
232
        if (r < 0)
46✔
233
                return r;
234

235
        return safe_atou32(s, ret);
46✔
236
}
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