From 362780f7062a4c45f6f05737ddd74e27525ca1cb Mon Sep 17 00:00:00 2001 From: Kartik Nema Date: Fri, 10 Apr 2026 13:43:23 +0530 Subject: [PATCH 1/2] Fix libdir path and proc data fetch routine --- .../ContextualClassifierInit.cpp | 11 ++--- debian/userspace-resource-manager.install | 4 +- modula/CoreModules/AuxRoutines.cpp | 41 +++++++++++++++---- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/contextual-classifier/ContextualClassifierInit.cpp b/contextual-classifier/ContextualClassifierInit.cpp index fecceef29..484584975 100644 --- a/contextual-classifier/ContextualClassifierInit.cpp +++ b/contextual-classifier/ContextualClassifierInit.cpp @@ -6,6 +6,7 @@ #include #include "Logger.h" +#include "Config.h" #include "ComponentRegistry.h" // Helper function from ContextualClassifier to format strings @@ -36,11 +37,11 @@ static ErrCode init(void *arg = nullptr) { } // This should match the installed path of libContextualClassifier.so - const char *so_name = "/usr/lib/libContextualClassifier.so.1"; - g_cc_handle = dlopen(so_name, RTLD_NOW); + std::string so_name = std::string(LIBDIR_PATH) + "/libContextualClassifier.so.1"; + g_cc_handle = dlopen(so_name.c_str(), RTLD_NOW); if (!g_cc_handle) { LOGE(CLASSIFIER_TAG, - format_string("Failed to dlopen %s: %s", so_name, dlerror())); + format_string("Failed to dlopen %s: %s", so_name.c_str(), dlerror())); // Do not fail the entire URM; just disable classifier functionality. return RC_SUCCESS; } @@ -51,7 +52,7 @@ static ErrCode init(void *arg = nullptr) { const char *err = dlerror(); if (err != nullptr || !g_cc_init) { LOGE(CLASSIFIER_TAG, - format_string("Failed to resolve ccInit in %s: %s", so_name, + format_string("Failed to resolve ccInit in %s: %s", so_name.c_str(), err ? err : "unknown")); dlclose(g_cc_handle); g_cc_handle = nullptr; @@ -64,7 +65,7 @@ static ErrCode init(void *arg = nullptr) { err = dlerror(); if (err != nullptr || !g_cc_term) { LOGE(CLASSIFIER_TAG, - format_string("Failed to resolve ccTerminate in %s: %s", so_name, + format_string("Failed to resolve ccTerminate in %s: %s", so_name.c_str(), err ? err : "unknown")); dlclose(g_cc_handle); g_cc_handle = nullptr; diff --git a/debian/userspace-resource-manager.install b/debian/userspace-resource-manager.install index 8ab3c7b28..603093282 100644 --- a/debian/userspace-resource-manager.install +++ b/debian/userspace-resource-manager.install @@ -1,9 +1,7 @@ usr/bin/urm usr/bin/urmCli -usr/lib/${DEB_HOST_MULTIARCH}/*.so* etc/urm/common/* usr/include/Urm/* usr/lib/systemd/system/urm.service etc/urm/classifier/* -usr/lib/libContextualClassifier.so* -usr/lib/libml_inference_lib.so* +usr/lib/${DEB_HOST_MULTIARCH}/*.so* diff --git a/modula/CoreModules/AuxRoutines.cpp b/modula/CoreModules/AuxRoutines.cpp index c1a633446..43ada6c93 100644 --- a/modula/CoreModules/AuxRoutines.cpp +++ b/modula/CoreModules/AuxRoutines.cpp @@ -132,15 +132,42 @@ pid_t AuxRoutines::fetchPid(const std::string& process_name) { } int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) { - std::string comm = ""; - std::string commPath = COMM(pid); - std::ifstream commFile(commPath); + // Try cmdline first for full process name + std::string cmdlinePath = "/proc/" + std::to_string(pid) + "/cmdline"; + std::ifstream cmdlineFile(cmdlinePath); + + if(cmdlineFile.is_open()) { + std::string cmdline; + std::getline(cmdlineFile, cmdline, '\0'); // Arguments are null-separated + + if(!cmdline.empty()) { + // Extract just the executable name from the full path + size_t lastSlash = cmdline.find_last_of('/'); + if(lastSlash != std::string::npos) { + procName = cmdline.substr(lastSlash + 1); + } else { + procName = cmdline; + } + + // Trim whitespace + size_t first = procName.find_first_not_of(" \t\n\r"); + if(first != std::string::npos) { + size_t last = procName.find_last_not_of(" \t\n\r"); + procName = procName.substr(first, (last - first + 1)); + } + + return true; + } + } - std::string processName = ""; + // Fallback to comm if cmdline fails + std::string commPath = "/proc/" + std::to_string(pid) + "/comm"; + std::ifstream commFile(commPath); + if(commFile.is_open()) { + std::string processName; std::getline(commFile, processName); - - // Trim + size_t first = processName.find_first_not_of(" \t\n\r"); if(first != std::string::npos) { size_t last = processName.find_last_not_of(" \t\n\r"); @@ -148,7 +175,7 @@ int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) { return true; } } - + return false; } From e86f1e0a0c7c61fbf6850d3dd2689cfe63268ad3 Mon Sep 17 00:00:00 2001 From: Kartik Nema Date: Fri, 10 Apr 2026 13:46:25 +0530 Subject: [PATCH 2/2] Cleanup --- modula/CoreModules/AuxRoutines.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/modula/CoreModules/AuxRoutines.cpp b/modula/CoreModules/AuxRoutines.cpp index 43ada6c93..f28a1b4e6 100644 --- a/modula/CoreModules/AuxRoutines.cpp +++ b/modula/CoreModules/AuxRoutines.cpp @@ -128,20 +128,18 @@ pid_t AuxRoutines::fetchPid(const std::string& process_name) { } closedir(proc_dir); - return -1; // Not found + return -1; } int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) { - // Try cmdline first for full process name std::string cmdlinePath = "/proc/" + std::to_string(pid) + "/cmdline"; std::ifstream cmdlineFile(cmdlinePath); if(cmdlineFile.is_open()) { std::string cmdline; - std::getline(cmdlineFile, cmdline, '\0'); // Arguments are null-separated + std::getline(cmdlineFile, cmdline, '\0'); if(!cmdline.empty()) { - // Extract just the executable name from the full path size_t lastSlash = cmdline.find_last_of('/'); if(lastSlash != std::string::npos) { procName = cmdline.substr(lastSlash + 1); @@ -149,7 +147,6 @@ int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) { procName = cmdline; } - // Trim whitespace size_t first = procName.find_first_not_of(" \t\n\r"); if(first != std::string::npos) { size_t last = procName.find_last_not_of(" \t\n\r"); @@ -160,14 +157,13 @@ int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) { } } - // Fallback to comm if cmdline fails std::string commPath = "/proc/" + std::to_string(pid) + "/comm"; std::ifstream commFile(commPath); if(commFile.is_open()) { std::string processName; std::getline(commFile, processName); - + size_t first = processName.find_first_not_of(" \t\n\r"); if(first != std::string::npos) { size_t last = processName.find_last_not_of(" \t\n\r"); @@ -175,7 +171,7 @@ int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) { return true; } } - + return false; }