Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions contextual-classifier/ContextualClassifierInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdarg>

#include "Logger.h"
#include "Config.h"
#include "ComponentRegistry.h"

// Helper function from ContextualClassifier to format strings
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions debian/userspace-resource-manager.install
Original file line number Diff line number Diff line change
@@ -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*
35 changes: 29 additions & 6 deletions modula/CoreModules/AuxRoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading