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

systemd / systemd / 14895667988

07 May 2025 08:57PM UTC coverage: 72.225% (-0.007%) from 72.232%
14895667988

push

github

yuwata
network: log_link_message_debug_errno() automatically append %m if necessary

Follow-up for d28746ef5.
Fixes CID#1609753.

0 of 1 new or added line in 1 file covered. (0.0%)

20297 existing lines in 338 files now uncovered.

297407 of 411780 relevant lines covered (72.22%)

695716.85 hits per line

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

90.59
/src/modules-load/modules-load.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <errno.h>
4
#include <getopt.h>
5
#include <limits.h>
6
#include <sys/stat.h>
7

8
#include "alloc-util.h"
9
#include "build.h"
10
#include "conf-files.h"
11
#include "constants.h"
12
#include "errno-util.h"
13
#include "fd-util.h"
14
#include "fileio.h"
15
#include "log.h"
16
#include "main-func.h"
17
#include "module-util.h"
18
#include "pretty-print.h"
19
#include "proc-cmdline.h"
20
#include "string-util.h"
21
#include "strv.h"
22

23
static char **arg_proc_cmdline_modules = NULL;
24
static const char conf_file_dirs[] = CONF_PATHS_NULSTR("modules-load.d");
25

26
STATIC_DESTRUCTOR_REGISTER(arg_proc_cmdline_modules, strv_freep);
69✔
27

28
static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
2,867✔
29
        int r;
2,867✔
30

31
        if (proc_cmdline_key_streq(key, "modules_load")) {
2,867✔
32

33
                if (proc_cmdline_value_missing(key, value))
4✔
34
                        return 0;
35

36
                r = strv_split_and_extend(&arg_proc_cmdline_modules, value, ",", /* filter_duplicates = */ true);
4✔
37
                if (r < 0)
4✔
UNCOV
38
                        return log_error_errno(r, "Failed to parse modules_load= kernel command line option: %m");
×
39
        }
40

41
        return 0;
42
}
43

44
static int apply_file(struct kmod_ctx *ctx, const char *path, bool ignore_enoent) {
68✔
45
        _cleanup_fclose_ FILE *f = NULL;
68✔
46
        _cleanup_free_ char *pp = NULL;
68✔
47
        int r;
68✔
48

49
        assert(ctx);
68✔
50
        assert(path);
68✔
51

52
        r = search_and_fopen_nulstr(path, "re", NULL, conf_file_dirs, &f, &pp);
68✔
53
        if (r < 0) {
68✔
54
                if (ignore_enoent && r == -ENOENT)
1✔
55
                        return 0;
56

57
                return log_error_errno(r, "Failed to open %s: %m", path);
1✔
58
        }
59

60
        log_debug("apply: %s", pp);
67✔
61
        for (;;) {
150✔
62
                _cleanup_free_ char *line = NULL;
83✔
63
                int k;
150✔
64

65
                k = read_stripped_line(f, LONG_LINE_MAX, &line);
150✔
66
                if (k < 0)
150✔
UNCOV
67
                        return log_error_errno(k, "Failed to read file '%s': %m", pp);
×
68
                if (k == 0)
150✔
69
                        break;
70

71
                if (isempty(line))
83✔
72
                        continue;
2✔
73
                if (strchr(COMMENTS, *line))
81✔
74
                        continue;
65✔
75

76
                k = module_load_and_warn(ctx, line, true);
16✔
77
                if (k == -ENOENT)
16✔
78
                        continue;
7✔
79
                RET_GATHER(r, k);
9✔
80
        }
81

82
        return r;
67✔
83
}
84

85
static int help(void) {
1✔
86
        _cleanup_free_ char *link = NULL;
1✔
87
        int r;
1✔
88

89
        r = terminal_urlify_man("systemd-modules-load.service", "8", &link);
1✔
90
        if (r < 0)
1✔
UNCOV
91
                return log_oom();
×
92

93
        printf("%s [OPTIONS...] [CONFIGURATION FILE...]\n\n"
1✔
94
               "Loads statically configured kernel modules.\n\n"
95
               "  -h --help             Show this help\n"
96
               "     --version          Show package version\n"
97
               "\nSee the %s for details.\n",
98
               program_invocation_short_name,
99
               link);
100

101
        return 0;
102
}
103

104
static int parse_argv(int argc, char *argv[]) {
69✔
105
        enum {
69✔
106
                ARG_VERSION = 0x100,
107
        };
108

109
        static const struct option options[] = {
69✔
110
                { "help",      no_argument,       NULL, 'h'           },
111
                { "version",   no_argument,       NULL, ARG_VERSION   },
112
                {}
113
        };
114

115
        int c;
69✔
116

117
        assert(argc >= 0);
69✔
118
        assert(argv);
69✔
119

120
        while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
69✔
121
                switch (c) {
3✔
122

123
                case 'h':
1✔
124
                        return help();
1✔
125

126
                case ARG_VERSION:
1✔
127
                        return version();
1✔
128

129
                case '?':
130
                        return -EINVAL;
131

132
                default:
×
UNCOV
133
                        assert_not_reached();
×
134
                }
135

136
        return 1;
137
}
138

139
static int run(int argc, char *argv[]) {
69✔
140
        _cleanup_(sym_kmod_unrefp) struct kmod_ctx *ctx = NULL;
69✔
141
        int r, k;
69✔
142

143
        r = parse_argv(argc, argv);
69✔
144
        if (r <= 0)
69✔
145
                return r;
146

147
        log_setup();
66✔
148

149
        umask(0022);
66✔
150

151
        r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
66✔
152
        if (r < 0)
66✔
UNCOV
153
                log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
×
154

155
        r = module_setup_context(&ctx);
66✔
156
        if (r < 0)
66✔
UNCOV
157
                return log_error_errno(r, "Failed to initialize libkmod context: %m");
×
158

159
        r = 0;
66✔
160

161
        if (argc > optind) {
66✔
162
                for (int i = optind; i < argc; i++)
4✔
163
                        RET_GATHER(r, apply_file(ctx, argv[i], false));
2✔
164

165
        } else {
166
                _cleanup_strv_free_ char **files = NULL;
64✔
167

168
                STRV_FOREACH(i, arg_proc_cmdline_modules) {
66✔
169
                        k = module_load_and_warn(ctx, *i, true);
2✔
170
                        if (k == -ENOENT)
2✔
171
                                continue;
1✔
172
                        RET_GATHER(r, k);
1✔
173
                }
174

175
                k = conf_files_list_nulstr(&files, ".conf", NULL, 0, conf_file_dirs);
64✔
176
                if (k < 0)
64✔
UNCOV
177
                        return log_error_errno(k, "Failed to enumerate modules-load.d files: %m");
×
178

179
                STRV_FOREACH(fn, files)
130✔
180
                        RET_GATHER(r, apply_file(ctx, *fn, true));
66✔
181
        }
182

183
        return r;
184
}
185

186
DEFINE_MAIN_FUNCTION(run);
69✔
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