From 4e94f7fadde9088d85d827a2bb089de94147ecce Mon Sep 17 00:00:00 2001 From: Konrad Kuchciak Date: Mon, 17 Feb 2020 12:58:12 +0100 Subject: [PATCH] Change kmod loading method Load kernel module using libkmod to apply config provided in /etc/modprobe.d Change-Id: I8f799667897959a1d91b78fe86cdc06ed9da5856 --- Makefile | 2 +- packaging/stability-monitor.spec | 3 ++- src/raw_data_providers/proc_tsm.c | 33 ++++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 924f369..a1c8b47 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ src = \ obj = $(src:.c=.o) -libs = json-c aul gio-2.0 glib-2.0 pkgmgr-info crash-service +libs = json-c aul gio-2.0 glib-2.0 pkgmgr-info crash-service libkmod CFLAGS = \ -Wall \ diff --git a/packaging/stability-monitor.spec b/packaging/stability-monitor.spec index c0aebfa..281d4c1 100644 --- a/packaging/stability-monitor.spec +++ b/packaging/stability-monitor.spec @@ -1,7 +1,7 @@ %define KMOD_PATH %{_libdir}/stability-monitor/proc-tsm.ko Name: stability-monitor -Version: 6.1.1 +Version: 6.2.1 Release: 0 License: Apache-2.0 Source0: %{name}-%{version}.tar.xz @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(crash-service) BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(libkmod) ExclusiveArch: armv7l Requires: %{KMOD_PATH} diff --git a/src/raw_data_providers/proc_tsm.c b/src/raw_data_providers/proc_tsm.c index 96ff3fe..8fe4746 100644 --- a/src/raw_data_providers/proc_tsm.c +++ b/src/raw_data_providers/proc_tsm.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "log.h" #include "raw_data.h" @@ -31,7 +32,6 @@ #define PROC_TSM_MODULE_NAME "proc_tsm" #define PROC_TSM_PATH "/proc/tsm" #define MAX_LINE 100 -#define finit_module(fd, params, flags) syscall(__NR_finit_module, fd, params, flags) static int str_to_ullarray(char *str, unsigned long long *array) @@ -91,23 +91,38 @@ error: /* Load kernel module if not loaded */ static int init(void) { - int fd, ret = 0; + struct kmod_ctx *ctx; + struct kmod_module *mod; + int ret = 0; if (access(PROC_TSM_PATH, O_RDONLY) == 0) { _I("Kernel module already loaded"); return 0; } - fd = open(KMOD_PATH, O_RDONLY); - if (fd == -1) { - _E("Unable to open file descriptor"); + ctx = kmod_new(NULL, NULL); + if (!ctx) { + _E("kmod_new() failed"); return -1; } - ret = finit_module(fd, "", 0); - if (ret) - _E("Unable to load kernel module: %m"); - close(fd); + ret = kmod_module_new_from_name(ctx, PROC_TSM_MODULE_NAME, &mod); + if (ret) { + _E("Unable to find module " PROC_TSM_MODULE_NAME); + goto kmod_unref; + } + + ret = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL); + if (ret) { + errno = -ret; + _E("Unable to insert %s: %m", kmod_module_get_name(mod)); + goto module_unref; + } + +module_unref: + kmod_module_unref(mod); +kmod_unref: + kmod_unref(ctx); return ret; } -- 2.34.1