OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogserver commits / dc87350

Fix bogus module path loading
dc87350ecdee12e68fa79beec846184d6b2b3c2f
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-14T07:50:57.000Z

Changed files (1) +15 -19

opencog/cogserver/server/ModuleManager.cc +15 -19
……@@ -11,8 +11,8 @@
1111 * explore writing guile (scheme) or python modules instead.
1212 */
1313
14#include <cstdlib>
1415#include <dlfcn.h>
15#include <unistd.h>
1616
1717#include <filesystem>
1818
……@@ -24,28 +24,24 @@
2424
2525using namespace opencog;
2626
27static std::string get_exe_dir()
28{
29 static const int EXE_PATH_MAX = 1024;
30 static char buf[EXE_PATH_MAX];
31 int rslt = readlink("/proc/self/exe", buf, EXE_PATH_MAX);
32 if (rslt < 0) return "";
33
34 buf[rslt] = '\0';
35 std::string exeName(buf);
36 return exeName.substr(0, exeName.rfind("/")+1);
37}
38
3927ModuleManager::ModuleManager(void)
4028{
41 // Give priority search order to the build directories.
42 // Do NOT search these, if working from installed path!
43 std::string exe = get_exe_dir();
44 if (0 == exe.compare(0, sizeof(PROJECT_BINARY_DIR)-1, PROJECT_BINARY_DIR))
29 // Check for COGSERVER_MODULE_PATH environment variable.
30 // This is a colon-separated list of directories to search for modules.
31 // These paths are searched first, before the install prefix.
32 const char* env_path = std::getenv("COGSERVER_MODULE_PATH");
33 if (env_path)
4534 {
46 module_paths.push_back(PROJECT_BINARY_DIR "/opencog/cogserver/modules/");
47 module_paths.push_back(PROJECT_BINARY_DIR "/opencog/cogserver/shell/");
35 std::vector<std::string> paths;
36 tokenize(env_path, std::back_inserter(paths), ":");
37 for (const std::string& p : paths)
38 {
39 if (not p.empty())
40 module_paths.push_back(p);
41 }
4842 }
43
44 // Finally, search the install prefix.
4945 module_paths.push_back(PROJECT_INSTALL_PREFIX "/lib/opencog/modules/");
5046}
5147