mkdir-label.c
mkdir.c
mkdir.h
+ module-util.h
mount-util.c
mount-util.h
nss-util.h
--- /dev/null
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2017 Zbigniew Jędrzejewski-Szmek
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <libkmod.h>
+
+#include "macro.h"
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_ctx*, kmod_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_module*, kmod_module_unref);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct kmod_list*, kmod_module_unref_list);
#include "fileio.h"
#include "kmod-setup.h"
#include "macro.h"
+#include "module-util.h"
#include "string-util.h"
#if HAVE_KMOD
/* virtio_rng would be loaded by udev later, but real entropy might be needed very early */
{ "virtio_rng", NULL, false, false, has_virtio_rng },
};
- struct kmod_ctx *ctx = NULL;
+ _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL;
unsigned int i;
int r;
return 0;
for (i = 0; i < ELEMENTSOF(kmod_table); i++) {
- struct kmod_module *mod;
+ _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
if (kmod_table[i].path && access(kmod_table[i].path, F_OK) >= 0)
continue;
log_full_errno(print_warning ? LOG_WARNING : LOG_DEBUG, r,
"Failed to insert module '%s': %m", kmod_module_get_name(mod));
}
-
- kmod_module_unref(mod);
}
- if (ctx)
- kmod_unref(ctx);
-
#endif
return 0;
}
#include "fd-util.h"
#include "fileio.h"
#include "log.h"
+#include "module-util.h"
#include "proc-cmdline.h"
#include "string-util.h"
#include "strv.h"
static int load_module(struct kmod_ctx *ctx, const char *m) {
const int probe_flags = KMOD_PROBE_APPLY_BLACKLIST;
- struct kmod_list *itr, *modlist = NULL;
+ struct kmod_list *itr;
+ _cleanup_(kmod_module_unref_listp) struct kmod_list *modlist = NULL;
int r = 0;
log_debug("load: %s", m);
}
kmod_list_foreach(itr, modlist) {
- struct kmod_module *mod;
+ _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
int state, err;
mod = kmod_module_get_module(itr);
r = err;
}
}
-
- kmod_module_unref(mod);
}
- kmod_module_unref_list(modlist);
-
return r;
}
int main(int argc, char *argv[]) {
int r, k;
- struct kmod_ctx *ctx;
+ _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL;
r = parse_argv(argc, argv);
if (r <= 0)
}
finish:
- kmod_unref(ctx);
strv_free(arg_proc_cmdline_modules);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
#include "sd-netlink.h"
#include "macro.h"
+#include "module-util.h"
#include "util.h"
static int load_module(const char *mod_name) {
- struct kmod_ctx *ctx;
- struct kmod_list *list = NULL, *l;
+ _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL;
+ _cleanup_(kmod_module_unref_listp) struct kmod_list *list = NULL;
+ struct kmod_list *l;
int r;
ctx = kmod_new(NULL, NULL);
- if (!ctx) {
- kmod_unref(ctx);
- return -ENOMEM;
- }
+ if (!ctx)
+ return log_oom();
r = kmod_module_new_from_lookup(ctx, mod_name, &list);
if (r < 0)
return -1;
kmod_list_foreach(l, list) {
- struct kmod_module *mod = kmod_module_get_module(l);
+ _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
+
+ mod = kmod_module_get_module(l);
r = kmod_module_probe_insert_module(mod, 0, NULL, NULL, NULL, NULL);
if (r >= 0)
r = 0;
else
r = -1;
-
- kmod_module_unref(mod);
}
- kmod_module_unref_list(list);
- kmod_unref(ctx);
-
return r;
}
#include <stdio.h>
#include <stdlib.h>
+#include "module-util.h"
#include "string-util.h"
#include "udev.h"
static struct kmod_ctx *ctx = NULL;
static int load_module(struct udev *udev, const char *alias) {
- struct kmod_list *list = NULL;
+ _cleanup_(kmod_module_unref_listp) struct kmod_list *list = NULL;
struct kmod_list *l;
int err;
log_debug("No module matches '%s'", alias);
kmod_list_foreach(l, list) {
- struct kmod_module *mod = kmod_module_get_module(l);
+ _cleanup_(kmod_module_unrefp) struct kmod_module *mod = NULL;
+
+ mod = kmod_module_get_module(l);
err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
if (err == KMOD_PROBE_APPLY_BLACKLIST)
log_debug("Inserted '%s'", kmod_module_get_name(mod));
else
log_debug("Failed to insert '%s'", kmod_module_get_name(mod));
-
- kmod_module_unref(mod);
}
- kmod_module_unref_list(list);
return err;
}