From c185b79194ca22d4ed4c0aaa4a1368af0ecb7766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Desch=C3=AAnes?= Date: Tue, 4 Aug 2020 15:06:10 -0400 Subject: [PATCH] fix(userspace/libscap): use proper module name in sysfs paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current solution appending _probe to `PROBE_DEVICE_NAME` won't work if `PROBE_NAME` doesn't end in '-probe'. Define SYSFS_NAME matching kbuild's KBUILD_MODNAME: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/Makefile.lib#n111 sysdig-CLA-1.0-signed-off-by: Antoine DeschĂȘnes --- CMakeLists.txt | 2 ++ driver/driver_config.h.in | 2 ++ userspace/libscap/scap.c | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46ab92bd43..1ee12eb844 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,8 @@ if(NOT WIN32) set(PROBE_NAME "sysdig-probe") endif() + string(REGEX REPLACE "[,-]" "_" SYSFS_NAME ${PROBE_NAME}) + if(NOT DEFINED PROBE_DEVICE_NAME) set(PROBE_DEVICE_NAME "sysdig") endif() diff --git a/driver/driver_config.h.in b/driver/driver_config.h.in index 5afb3acd8e..2d9416733a 100644 --- a/driver/driver_config.h.in +++ b/driver/driver_config.h.in @@ -13,3 +13,5 @@ or GPL2.txt for full copies of the license. #define PROBE_NAME "${PROBE_NAME}" #define PROBE_DEVICE_NAME "${PROBE_DEVICE_NAME}" + +#define SYSFS_NAME "${SYSFS_NAME}" diff --git a/userspace/libscap/scap.c b/userspace/libscap/scap.c index e9faea5184..824aaa0010 100644 --- a/userspace/libscap/scap.c +++ b/userspace/libscap/scap.c @@ -100,7 +100,7 @@ scap_t* scap_open_live_int(char *error, int32_t *rc, static uint32_t get_max_consumers() { uint32_t max; - FILE *pfile = fopen("/sys/module/" PROBE_DEVICE_NAME "_probe/parameters/max_consumers", "r"); + FILE *pfile = fopen("/sys/module/" SYSFS_NAME "/parameters/max_consumers", "r"); if(pfile != NULL) { int w = fscanf(pfile, "%"PRIu32, &max); @@ -328,7 +328,7 @@ scap_t* scap_open_live_int(char *error, int32_t *rc, else if(errno == EBUSY) { uint32_t curr_max_consumers = get_max_consumers(); - snprintf(error, SCAP_LASTERR_SIZE, "Too many sysdig instances attached to device %s. Current value for /sys/module/" PROBE_DEVICE_NAME "_probe/parameters/max_consumers is '%"PRIu32"'.", filename, curr_max_consumers); + snprintf(error, SCAP_LASTERR_SIZE, "Too many sysdig instances attached to device %s. Current value for /sys/module/" SYSFS_NAME "/parameters/max_consumers is '%"PRIu32"'.", filename, curr_max_consumers); } else {