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..f28a1b4e6 100644 --- a/modula/CoreModules/AuxRoutines.cpp +++ b/modula/CoreModules/AuxRoutines.cpp @@ -128,19 +128,42 @@ 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) { - std::string comm = ""; - std::string commPath = COMM(pid); - std::ifstream commFile(commPath); + 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'); + + if(!cmdline.empty()) { + size_t lastSlash = cmdline.find_last_of('/'); + if(lastSlash != std::string::npos) { + procName = cmdline.substr(lastSlash + 1); + } else { + procName = cmdline; + } + + 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 = ""; + 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");