log_debug("apply: %s", pp);
for (;;) {
_cleanup_free_ char *line = NULL;
- char *l;
int k;
- k = read_line(f, LONG_LINE_MAX, &line);
+ k = read_stripped_line(f, LONG_LINE_MAX, &line);
if (k < 0)
return log_error_errno(k, "Failed to read file '%s': %m", pp);
if (k == 0)
break;
- l = strstrip(line);
- if (isempty(l))
+ if (isempty(line))
continue;
- if (strchr(COMMENTS, *l))
+ if (strchr(COMMENTS, *line))
continue;
- k = module_load_and_warn(ctx, l, true);
+ k = module_load_and_warn(ctx, line, true);
if (k == -ENOENT)
continue;
- if (k < 0 && r >= 0)
- r = k;
+ RET_GATHER(r, k);
}
return r;
log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
ctx = kmod_new(NULL, NULL);
- if (!ctx) {
- log_error("Failed to allocate memory for kmod.");
- return -ENOMEM;
- }
+ if (!ctx)
+ return log_oom();
kmod_load_resources(ctx);
kmod_set_log_fn(ctx, systemd_kmod_log, NULL);
r = 0;
if (argc > optind) {
- for (int i = optind; i < argc; i++) {
- k = apply_file(ctx, argv[i], false);
- if (k < 0 && r == 0)
- r = k;
- }
+ for (int i = optind; i < argc; i++)
+ RET_GATHER(r, apply_file(ctx, argv[i], false));
} else {
_cleanup_strv_free_ char **files = NULL;
k = module_load_and_warn(ctx, *i, true);
if (k == -ENOENT)
continue;
- if (k < 0 && r == 0)
- r = k;
+ RET_GATHER(r, k);
}
k = conf_files_list_nulstr(&files, ".conf", NULL, 0, conf_file_dirs);
- if (k < 0) {
- log_error_errno(k, "Failed to enumerate modules-load.d files: %m");
- if (r == 0)
- r = k;
- return r;
- }
+ if (k < 0)
+ return log_error_errno(k, "Failed to enumerate modules-load.d files: %m");
- STRV_FOREACH(fn, files) {
- k = apply_file(ctx, *fn, true);
- if (k < 0 && r == 0)
- r = k;
- }
+ STRV_FOREACH(fn, files)
+ RET_GATHER(r, apply_file(ctx, *fn, true));
}
return r;