Change kmod loading method 24/225124/2 accepted/tizen/unified/20200220.122445 submit/submit/tizen/20200218.081748/20200218.081831 submit/tizen/20200218.081748
authorKonrad Kuchciak <k.kuchciak@samsung.com>
Mon, 17 Feb 2020 11:58:12 +0000 (12:58 +0100)
committerKonrad Kuchciak <k.kuchciak@samsung.com>
Tue, 18 Feb 2020 08:01:08 +0000 (09:01 +0100)
Load kernel module using libkmod to apply config provided in
/etc/modprobe.d

Change-Id: I8f799667897959a1d91b78fe86cdc06ed9da5856

Makefile
packaging/stability-monitor.spec
src/raw_data_providers/proc_tsm.c

index 924f369..a1c8b47 100644 (file)
--- 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 \
index c0aebfa..281d4c1 100644 (file)
@@ -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}
 
index 96ff3fe..8fe4746 100644 (file)
@@ -24,6 +24,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <libkmod.h>
 
 #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;
 }