• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 15199265962

22 May 2025 09:40PM UTC coverage: 72.061% (-0.02%) from 72.079%
15199265962

push

github

bluca
tests: fix TEST-74-AUX-UTILS.varlinkctl.sh (#37562)

per Daan's explanation:
other subtests running as testuser apparently use systemd-run --user
--machine testuser@.host which turns user tracking in logind into "by
pin" mode. when the last pinning session exits it terminates the user.

299156 of 415145 relevant lines covered (72.06%)

703915.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.0
/src/core/kmod-setup.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <unistd.h>
4

5
#include "alloc-util.h"
6
#include "capability-util.h"
7
#include "efi-api.h"
8
#include "fileio.h"
9
#include "kmod-setup.h"
10
#include "log.h"
11
#include "module-util.h"
12
#include "recurse-dir.h"
13
#include "string-util.h"
14
#include "strv.h"
15
#include "virt.h"
16

17
#if HAVE_KMOD
18
static int match_modalias_recurse_dir_cb(
20,740✔
19
                RecurseDirEvent event,
20
                const char *path,
21
                int dir_fd,
22
                int inode_fd,
23
                const struct dirent *de,
24
                const struct statx *sx,
25
                void *userdata) {
26

27
        _cleanup_free_ char *alias = NULL;
20,740✔
28
        char **modaliases = ASSERT_PTR(userdata);
20,740✔
29
        int r;
20,740✔
30

31
        if (event != RECURSE_DIR_ENTRY)
20,740✔
32
                return RECURSE_DIR_CONTINUE;
33

34
        if (de->d_type != DT_REG)
15,114✔
35
                return RECURSE_DIR_CONTINUE;
36

37
        if (!streq(de->d_name, "modalias"))
13,629✔
38
                return RECURSE_DIR_CONTINUE;
39

40
        r = read_one_line_file(path, &alias);
565✔
41
        if (r < 0) {
565✔
42
                log_debug_errno(r, "Failed to read %s, ignoring: %m", path);
×
43
                return RECURSE_DIR_LEAVE_DIRECTORY;
×
44
        }
45

46
        if (startswith_strv(alias, modaliases))
565✔
47
                return 1;
45✔
48

49
        return RECURSE_DIR_LEAVE_DIRECTORY;
50
}
51

52
static bool has_virtio_feature(const char *name, char **modaliases) {
60✔
53
        int r;
60✔
54

55
        /* Directory traversal might be slow, hence let's do a cheap check first if it's even worth it */
56
        if (detect_vm() == VIRTUALIZATION_NONE)
60✔
57
                return false;
58

59
        r = recurse_dir_at(
60✔
60
                        AT_FDCWD,
61
                        "/sys/devices/pci0000:00",
62
                        /* statx_mask= */ 0,
63
                        /* n_depth_max= */ 3,
64
                        RECURSE_DIR_ENSURE_TYPE,
65
                        match_modalias_recurse_dir_cb,
66
                        modaliases);
67
        if (r < 0)
60✔
68
                log_debug_errno(r, "Failed to determine whether host has %s device, ignoring: %m", name);
×
69

70
        return r > 0;
60✔
71
}
72

73
static bool has_virtio_rng(void) {
15✔
74
        return has_virtio_feature("virtio-rng", STRV_MAKE("pci:v00001AF4d00001005", "pci:v00001AF4d00001044"));
15✔
75
}
76

77
static bool has_virtio_console(void) {
15✔
78
        return has_virtio_feature("virtio-console", STRV_MAKE("virtio:d00000003v", "virtio:d0000000Bv"));
15✔
79
}
80

81
static bool has_virtio_vsock(void) {
15✔
82
        return has_virtio_feature("virtio-vsock", STRV_MAKE("virtio:d00000013v"));
15✔
83
}
84

85
static bool has_virtiofs(void) {
15✔
86
        return has_virtio_feature("virtiofs", STRV_MAKE("virtio:d0000001Av"));
15✔
87
}
88

89
static bool has_virtio_pci(void) {
×
90
        return has_virtio_feature("virtio-pci", STRV_MAKE("pci:v00001AF4d"));
×
91
}
92

93
static bool in_qemu(void) {
12✔
94
        return IN_SET(detect_vm(), VIRTUALIZATION_KVM, VIRTUALIZATION_QEMU);
12✔
95
}
96
#endif
97

98
int kmod_setup(void) {
33✔
99
#if HAVE_KMOD
100
        static const struct {
33✔
101
                const char *module;
102
                const char *path;
103
                bool warn_if_unavailable;
104
                bool warn_if_module;
105
                bool (*condition_fn)(void);
106
        } kmod_table[] = {
107
                /* This one we need to load explicitly, since auto-loading on use doesn't work
108
                 * before udev created the ghost device nodes, and we need it earlier than that. */
109
                { "autofs4",                    "/sys/class/misc/autofs",    true,  false, NULL               },
110

111
                /* This one we need to load explicitly, since auto-loading of IPv6 is not done when
112
                 * we try to configure ::1 on the loopback device. */
113
                { "ipv6",                       "/sys/module/ipv6",          false, true,  NULL               },
114

115
                /* This should never be a module */
116
                { "unix",                       "/proc/net/unix",            true,  true,  NULL               },
117

118
#if HAVE_LIBIPTC
119
                /* netfilter is needed by networkd, nspawn among others, and cannot be autoloaded */
120
                { "ip_tables",                  "/proc/net/ip_tables_names", false, false, NULL               },
121
#endif
122
                /* virtio_rng would be loaded by udev later, but real entropy might be needed very early */
123
                { "virtio_rng",                 NULL,                        false, false, has_virtio_rng     },
124

125
                /* we want early logging to hvc consoles if possible, and make sure systemd-getty-generator
126
                 * can rely on all consoles being probed already. */
127
                { "virtio_console",             NULL,                        false, false, has_virtio_console },
128

129
                /* Make sure we can send sd-notify messages over vsock as early as possible. */
130
                { "vmw_vsock_virtio_transport", NULL,                        false, false, has_virtio_vsock   },
131

132
                /* We can't wait for specific virtiofs tags to show up as device nodes so we have to load the
133
                 * virtiofs and virtio_pci modules early to make sure the virtiofs tags are found when
134
                 * sysroot.mount is started.
135
                 *
136
                 * TODO: Remove these again once https://gitlab.com/virtio-fs/virtiofsd/-/issues/128 is
137
                 * resolved and the kernel fix is widely available. */
138
                { "virtiofs",                   "/sys/module/virtiofs",      false, false, has_virtiofs       },
139
                { "virtio_pci",                 "/sys/module/virtio_pci",    false, false, has_virtio_pci     },
140

141
                /* qemu_fw_cfg would be loaded by udev later, but we want to import credentials from it super early */
142
                { "qemu_fw_cfg",                "/sys/firmware/qemu_fw_cfg", false, false, in_qemu            },
143

144
                /* dmi-sysfs is needed to import credentials from it super early */
145
                { "dmi-sysfs",                  "/sys/firmware/dmi/entries", false, false, NULL               },
146

147
#if HAVE_TPM2
148
                /* Make sure the tpm subsystem is available which ConditionSecurity=tpm2 depends on. */
149
                { "tpm",                        "/sys/class/tpmrm",          false, false, efi_has_tpm2       },
150
#endif
151
        };
152

153
        int r;
33✔
154

155
        if (have_effective_cap(CAP_SYS_MODULE) <= 0)
33✔
156
                return 0;
33✔
157

158
        _cleanup_(sym_kmod_unrefp) struct kmod_ctx *ctx = NULL;
15✔
159
        FOREACH_ELEMENT(kmod, kmod_table) {
195✔
160
                if (kmod->path && access(kmod->path, F_OK) >= 0)
180✔
161
                        continue;
93✔
162

163
                if (kmod->condition_fn && !kmod->condition_fn())
87✔
164
                        continue;
15✔
165

166
                if (kmod->warn_if_module)
72✔
167
                        log_debug("Your kernel apparently lacks built-in %s support. Might be "
×
168
                                  "a good idea to compile it in. We'll now try to work around "
169
                                  "this by loading the module...", kmod->module);
170

171
                if (!ctx) {
72✔
172
                        r = module_setup_context(&ctx);
15✔
173
                        if (r < 0)
15✔
174
                                return log_error_errno(r, "Failed to initialize kmod context: %m");
×
175
                }
176

177
                (void) module_load_and_warn(ctx, kmod->module, kmod->warn_if_unavailable);
72✔
178
        }
179

180
#endif
181
        return 0;
182
}
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