From: Kienan Stewart Date: Wed, 22 Nov 2023 16:18:23 +0000 (-0500) Subject: sessiond: log error message when libkmod operations fail X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7d46777ba0eaba7916ae822a7133f39740cdf9e5;p=lttng-tools.git sessiond: log error message when libkmod operations fail Issue observed -------------- When loading or unloading modules and libkmod is being used, there are no details available in the `lttng-sessiond` error ouput. For example, ``` $ sudo -E lttng-sessiond Error: Unable to load required module lttng-ring-buffer-client-discard Warning: No kernel tracer available ``` When libkmod is not available or disabled in the configuration options, `lttng-sessiond` falls back to invoking `modprobe` via a `system` call. The command's error output will be visible and provide the necessary details, eg. ``` $ sudo -E lttng-sessiond modprobe: FATAL: Module lttng-ring-buffer-client-discard not found in directory /usr/lib/modules/6.2.0-36-generic Error: Unable to load required module lttng-ring-buffer-client-discard Warning: No kernel tracer available ``` Solution -------- Include the error message from `strerror` in the message that is logged via the `DBG` or `ERR` macros. The error is no clearer for users, eg. ``` $ sudo -E lttng-sessiond PERROR - 12:00:05.004593045 [Main]: Unable to load required module lttng-ring-buffer-client-discard: No such file or directory (in modprobe_lttng() at modprobe.cpp:396) Warning: No kernel tracer available ``` Known drawbacks --------------- The debug message emitted when a non-obligatory kernel module fails to load is now printed with `PERROR`. Change-Id: Ibd25614a6c5b5dd3b801063eafc272a4017058cd Signed-off-by: Kienan Stewart Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/modprobe.cpp b/src/bin/lttng-sessiond/modprobe.cpp index ac9f14257..547756de9 100644 --- a/src/bin/lttng-sessiond/modprobe.cpp +++ b/src/bin/lttng-sessiond/modprobe.cpp @@ -393,11 +393,11 @@ static int modprobe_lttng(struct kern_modules_param *modules, int entries) ret = 0; } else if (ret < 0) { if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED) { - ERR("Unable to load required module %s", modules[i].name); + PERROR("Unable to load required module `%s`", modules[i].name) goto error; } else { - DBG("Unable to load optional module %s; continuing", - modules[i].name); + PERROR("Unable to load optional module `%s`; continuing", + modules[i].name); ret = 0; } } else { @@ -491,7 +491,7 @@ static void modprobe_remove_lttng(const struct kern_modules_param *modules, int DBG("Module %s is not in kernel.", modules[i].name); } else if (modules[i].load_policy == KERNEL_MODULE_PROPERTY_LOAD_POLICY_REQUIRED && ret < 0) { - ERR("Unable to remove module %s", modules[i].name); + PERROR("Unable to remove module `%s`", modules[i].name); } else { DBG("Modprobe removal successful %s", modules[i].name); }