Skip to content

Commit e7d5905

Browse files
authored
Fix libdir path and proc data fetch routine (#231)
--- Signed-off-by: Kartik Nema <kartnema@qti.qualcomm.com>
1 parent 363e4cd commit e7d5905

3 files changed

Lines changed: 36 additions & 14 deletions

File tree

contextual-classifier/ContextualClassifierInit.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <cstdarg>
77

88
#include "Logger.h"
9+
#include "Config.h"
910
#include "ComponentRegistry.h"
1011

1112
// Helper function from ContextualClassifier to format strings
@@ -36,11 +37,11 @@ static ErrCode init(void *arg = nullptr) {
3637
}
3738

3839
// This should match the installed path of libContextualClassifier.so
39-
const char *so_name = "/usr/lib/libContextualClassifier.so.1";
40-
g_cc_handle = dlopen(so_name, RTLD_NOW);
40+
std::string so_name = std::string(LIBDIR_PATH) + "/libContextualClassifier.so.1";
41+
g_cc_handle = dlopen(so_name.c_str(), RTLD_NOW);
4142
if (!g_cc_handle) {
4243
LOGE(CLASSIFIER_TAG,
43-
format_string("Failed to dlopen %s: %s", so_name, dlerror()));
44+
format_string("Failed to dlopen %s: %s", so_name.c_str(), dlerror()));
4445
// Do not fail the entire URM; just disable classifier functionality.
4546
return RC_SUCCESS;
4647
}
@@ -51,7 +52,7 @@ static ErrCode init(void *arg = nullptr) {
5152
const char *err = dlerror();
5253
if (err != nullptr || !g_cc_init) {
5354
LOGE(CLASSIFIER_TAG,
54-
format_string("Failed to resolve ccInit in %s: %s", so_name,
55+
format_string("Failed to resolve ccInit in %s: %s", so_name.c_str(),
5556
err ? err : "unknown"));
5657
dlclose(g_cc_handle);
5758
g_cc_handle = nullptr;
@@ -64,7 +65,7 @@ static ErrCode init(void *arg = nullptr) {
6465
err = dlerror();
6566
if (err != nullptr || !g_cc_term) {
6667
LOGE(CLASSIFIER_TAG,
67-
format_string("Failed to resolve ccTerminate in %s: %s", so_name,
68+
format_string("Failed to resolve ccTerminate in %s: %s", so_name.c_str(),
6869
err ? err : "unknown"));
6970
dlclose(g_cc_handle);
7071
g_cc_handle = nullptr;
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
usr/bin/urm
22
usr/bin/urmCli
3-
usr/lib/${DEB_HOST_MULTIARCH}/*.so*
43
etc/urm/common/*
54
usr/include/Urm/*
65
usr/lib/systemd/system/urm.service
76
etc/urm/classifier/*
8-
usr/lib/libContextualClassifier.so*
9-
usr/lib/libml_inference_lib.so*
7+
usr/lib/${DEB_HOST_MULTIARCH}/*.so*

modula/CoreModules/AuxRoutines.cpp

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,42 @@ pid_t AuxRoutines::fetchPid(const std::string& process_name) {
128128
}
129129

130130
closedir(proc_dir);
131-
return -1; // Not found
131+
return -1;
132132
}
133133

134134
int8_t AuxRoutines::getProcName(pid_t pid, std::string& procName) {
135-
std::string comm = "";
136-
std::string commPath = COMM(pid);
137-
std::ifstream commFile(commPath);
135+
std::string cmdlinePath = "/proc/" + std::to_string(pid) + "/cmdline";
136+
std::ifstream cmdlineFile(cmdlinePath);
137+
138+
if(cmdlineFile.is_open()) {
139+
std::string cmdline;
140+
std::getline(cmdlineFile, cmdline, '\0');
141+
142+
if(!cmdline.empty()) {
143+
size_t lastSlash = cmdline.find_last_of('/');
144+
if(lastSlash != std::string::npos) {
145+
procName = cmdline.substr(lastSlash + 1);
146+
} else {
147+
procName = cmdline;
148+
}
149+
150+
size_t first = procName.find_first_not_of(" \t\n\r");
151+
if(first != std::string::npos) {
152+
size_t last = procName.find_last_not_of(" \t\n\r");
153+
procName = procName.substr(first, (last - first + 1));
154+
}
155+
156+
return true;
157+
}
158+
}
138159

139-
std::string processName = "";
160+
std::string commPath = "/proc/" + std::to_string(pid) + "/comm";
161+
std::ifstream commFile(commPath);
162+
140163
if(commFile.is_open()) {
164+
std::string processName;
141165
std::getline(commFile, processName);
142166

143-
// Trim
144167
size_t first = processName.find_first_not_of(" \t\n\r");
145168
if(first != std::string::npos) {
146169
size_t last = processName.find_last_not_of(" \t\n\r");

0 commit comments

Comments
 (0)