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

systemd / systemd / 13710725352

06 Mar 2025 10:36PM UTC coverage: 71.765% (-0.02%) from 71.788%
13710725352

push

github

web-flow
hostnamectl: show image info in hostnamectl (#36638)

On image-based systems these properties are quite fundamental, hence
show them in the hostnamed output.

2 of 9 new or added lines in 1 file covered. (22.22%)

5360 existing lines in 93 files now uncovered.

294785 of 410763 relevant lines covered (71.77%)

717261.41 hits per line

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

68.18
/src/shared/module-util.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <errno.h>
4

5
#include "module-util.h"
6
#include "proc-cmdline.h"
7
#include "strv.h"
8

9
#if HAVE_KMOD
10

11
static void *libkmod_dl = NULL;
12

13
DLSYM_PROTOTYPE(kmod_list_next) = NULL;
14
DLSYM_PROTOTYPE(kmod_load_resources) = NULL;
15
DLSYM_PROTOTYPE(kmod_module_get_initstate) = NULL;
16
DLSYM_PROTOTYPE(kmod_module_get_module) = NULL;
17
DLSYM_PROTOTYPE(kmod_module_get_name) = NULL;
18
DLSYM_PROTOTYPE(kmod_module_new_from_lookup) = NULL;
19
DLSYM_PROTOTYPE(kmod_module_probe_insert_module) = NULL;
20
DLSYM_PROTOTYPE(kmod_module_unref) = NULL;
21
DLSYM_PROTOTYPE(kmod_module_unref_list) = NULL;
22
DLSYM_PROTOTYPE(kmod_new) = NULL;
23
DLSYM_PROTOTYPE(kmod_set_log_fn) = NULL;
24
DLSYM_PROTOTYPE(kmod_unref) = NULL;
25
DLSYM_PROTOTYPE(kmod_validate_resources) = NULL;
26

27
int dlopen_libkmod(void) {
279✔
28
        ELF_NOTE_DLOPEN("kmod",
279✔
29
                        "Support for loading kernel modules",
30
                        ELF_NOTE_DLOPEN_PRIORITY_RECOMMENDED,
31
                        "libkmod.so.2");
32

33
        return dlopen_many_sym_or_warn(
279✔
34
                        &libkmod_dl,
35
                        "libkmod.so.2",
36
                        LOG_DEBUG,
37
                        DLSYM_ARG(kmod_list_next),
38
                        DLSYM_ARG(kmod_load_resources),
39
                        DLSYM_ARG(kmod_module_get_initstate),
40
                        DLSYM_ARG(kmod_module_get_module),
41
                        DLSYM_ARG(kmod_module_get_name),
42
                        DLSYM_ARG(kmod_module_new_from_lookup),
43
                        DLSYM_ARG(kmod_module_probe_insert_module),
44
                        DLSYM_ARG(kmod_module_unref),
45
                        DLSYM_ARG(kmod_module_unref_list),
46
                        DLSYM_ARG(kmod_new),
47
                        DLSYM_ARG(kmod_set_log_fn),
48
                        DLSYM_ARG(kmod_unref),
49
                        DLSYM_ARG(kmod_validate_resources));
50
}
51

52
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
×
53
        char ***denylist = ASSERT_PTR(data);
×
54
        int r;
×
55

56
        if (proc_cmdline_key_streq(key, "module_blacklist")) {
×
57

58
                if (proc_cmdline_value_missing(key, value))
×
59
                        return 0;
60

61
                r = strv_split_and_extend(denylist, value, ",", /* filter_duplicates = */ true);
×
62
                if (r < 0)
×
63
                        return r;
×
64
        }
65

66
        return 0;
67
}
68

69
int module_load_and_warn(struct kmod_ctx *ctx, const char *module, bool verbose) {
8,067✔
70
        _cleanup_(sym_kmod_module_unref_listp) struct kmod_list *modlist = NULL;
8,067✔
71
        _cleanup_strv_free_ char **denylist = NULL;
8,067✔
72
        bool denylist_parsed = false;
8,067✔
73
        struct kmod_list *itr;
8,067✔
74
        int r;
8,067✔
75

76
        assert(ctx);
8,067✔
77
        assert(module);
8,067✔
78

79
        /* verbose==true means we should log at non-debug level if we
80
         * fail to find or load the module. */
81

82
        log_debug("Loading module: %s", module);
8,067✔
83

84
        r = sym_kmod_module_new_from_lookup(ctx, module, &modlist);
8,067✔
85
        if (r < 0)
8,067✔
86
                return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG, r,
×
87
                                      "Failed to look up module alias '%s': %m", module);
88

89
        if (!modlist)
8,067✔
90
                return log_full_errno(verbose ? LOG_ERR : LOG_DEBUG,
9,954✔
91
                                      SYNTHETIC_ERRNO(ENOENT),
92
                                      "Failed to find module '%s'", module);
93

94
        sym_kmod_list_foreach(itr, modlist) {
11,095✔
95
                _cleanup_(sym_kmod_module_unrefp) struct kmod_module *mod = NULL;
×
96
                int state, err;
8,009✔
97

98
                mod = sym_kmod_module_get_module(itr);
8,009✔
99
                state = sym_kmod_module_get_initstate(mod);
8,009✔
100

101
                switch (state) {
8,009✔
102
                case KMOD_MODULE_BUILTIN:
103
                        log_full(verbose ? LOG_INFO : LOG_DEBUG,
890✔
104
                                 "Module '%s' is built in", sym_kmod_module_get_name(mod));
105
                        break;
106

107
                case KMOD_MODULE_LIVE:
108
                        log_debug("Module '%s' is already loaded", sym_kmod_module_get_name(mod));
3,767✔
109
                        break;
110

111
                default:
3,797✔
112
                        err = sym_kmod_module_probe_insert_module(
3,797✔
113
                                        mod,
114
                                        KMOD_PROBE_APPLY_BLACKLIST,
115
                                        /* extra_options= */ NULL,
116
                                        /* run_install= */ NULL,
117
                                        /* data= */ NULL,
118
                                        /* print_action= */ NULL);
119
                        if (err == 0)
3,797✔
120
                                log_full(verbose ? LOG_INFO : LOG_DEBUG,
4,996✔
121
                                         "Inserted module '%s'", sym_kmod_module_get_name(mod));
122
                        else if (err == KMOD_PROBE_APPLY_BLACKLIST)
1,297✔
123
                                log_full(verbose ? LOG_INFO : LOG_DEBUG,
8,009✔
124
                                         "Module '%s' is deny-listed (by kmod)", sym_kmod_module_get_name(mod));
125
                        else {
126
                                assert(err < 0);
1,297✔
127

128
                                if (err == -EPERM) {
1,297✔
129
                                        if (!denylist_parsed) {
×
130
                                                r = proc_cmdline_parse(parse_proc_cmdline_item, &denylist, 0);
×
131
                                                if (r < 0)
×
132
                                                        log_full_errno(!verbose ? LOG_DEBUG : LOG_WARNING,
×
133
                                                                       r,
134
                                                                       "Failed to parse kernel command line, ignoring: %m");
135

136
                                                denylist_parsed = true;
137
                                        }
138
                                        if (strv_contains(denylist, sym_kmod_module_get_name(mod))) {
×
139
                                                log_full(verbose ? LOG_INFO : LOG_DEBUG,
×
140
                                                         "Module '%s' is deny-listed (by kernel)", sym_kmod_module_get_name(mod));
141
                                                continue;
×
142
                                        }
143
                                }
144

145
                                log_full_errno(!verbose ? LOG_DEBUG :
1,297✔
146
                                               err == -ENODEV ? LOG_NOTICE :
147
                                               err == -ENOENT ? LOG_WARNING :
148
                                                                LOG_ERR,
149
                                               err,
150
                                               "Failed to insert module '%s': %m",
151
                                               sym_kmod_module_get_name(mod));
152
                                if (!IN_SET(err, -ENODEV, -ENOENT))
1,297✔
UNCOV
153
                                        r = err;
×
154
                        }
155
                }
156
        }
157

158
        return r;
159
}
160

161
_printf_(6,0) static void systemd_kmod_log(
×
162
                void *data,
163
                int priority,
164
                const char *file,
165
                int line,
166
                const char *fn,
167
                const char *format,
168
                va_list args) {
169

170
        log_internalv(priority, 0, file, line, fn, format, args);
×
171
}
×
172

173
int module_setup_context(struct kmod_ctx **ret) {
278✔
174
        _cleanup_(sym_kmod_unrefp) struct kmod_ctx *ctx = NULL;
278✔
175
        int r;
278✔
176

177
        assert(ret);
278✔
178

179
        r = dlopen_libkmod();
278✔
180
        if (r < 0)
278✔
181
                return r;
182

183
        ctx = sym_kmod_new(NULL, NULL);
278✔
184
        if (!ctx)
278✔
185
                return -ENOMEM;
186

187
        (void) sym_kmod_load_resources(ctx);
278✔
188
        sym_kmod_set_log_fn(ctx, systemd_kmod_log, NULL);
278✔
189

190
        *ret = TAKE_PTR(ctx);
278✔
191
        return 0;
278✔
192
}
193

194
#endif
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