| … | … | @@ -11,8 +11,8 @@ |
| 11 | 11 | * explore writing guile (scheme) or python modules instead. |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | #include <cstdlib> |
| 14 | 15 | #include <dlfcn.h> |
| 15 | | #include <unistd.h> |
| 16 | 16 | |
| 17 | 17 | #include <filesystem> |
| 18 | 18 | |
| … | … | @@ -24,28 +24,24 @@ |
| 24 | 24 | |
| 25 | 25 | using namespace opencog; |
| 26 | 26 | |
| 27 | | static 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 | | |
| 39 | 27 | ModuleManager::ModuleManager(void) |
| 40 | 28 | { |
| 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) |
| 45 | 34 | { |
| 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 | } |
| 48 | 42 | } |
| 43 | |
| 44 | // Finally, search the install prefix. |
| 49 | 45 | module_paths.push_back(PROJECT_INSTALL_PREFIX "/lib/opencog/modules/"); |
| 50 | 46 | } |
| 51 | 47 | |