working out peer module loading
parent
49c73d1876
commit
448dc0cdfd
|
@ -151,6 +151,16 @@ extern "C" {
|
||||||
* @param level The log level (LOG_FATAL, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG)
|
* @param level The log level (LOG_FATAL, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG)
|
||||||
*/
|
*/
|
||||||
void dpm_set_logging_level(int level);
|
void dpm_set_logging_level(int level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the module path
|
||||||
|
*
|
||||||
|
* Returns the path where DPM modules are located, as determined by
|
||||||
|
* command-line arguments, configuration files, or defaults.
|
||||||
|
*
|
||||||
|
* @return The module path
|
||||||
|
*/
|
||||||
|
const char* dpm_get_module_path(void);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -210,6 +220,11 @@ return env_value; /* Will be null if env var doesn't exist */ \
|
||||||
extern "C" void dpm_set_logging_level(int level) { \
|
extern "C" void dpm_set_logging_level(int level) { \
|
||||||
std::cout << "[INFO] Verbosity level ignored, as all standalone executions have maximum verbosity" << std::endl; \
|
std::cout << "[INFO] Verbosity level ignored, as all standalone executions have maximum verbosity" << std::endl; \
|
||||||
} \
|
} \
|
||||||
|
extern "C" const char* dpm_get_module_path(void) { \
|
||||||
|
/* Get from environment variable or use default */ \
|
||||||
|
const char* env_path = getenv("DPM_MODULE_PATH"); \
|
||||||
|
return env_path ? env_path : "/usr/lib/dpm/modules/"; \
|
||||||
|
} \
|
||||||
int main(int argc, char** argv) { \
|
int main(int argc, char** argv) { \
|
||||||
/* Default to "help" if no command is provided */ \
|
/* Default to "help" if no command is provided */ \
|
||||||
const char* command = "help"; \
|
const char* command = "help"; \
|
||||||
|
|
|
@ -156,6 +156,12 @@ class ConfigManager {
|
||||||
*/
|
*/
|
||||||
bool hasConfigKey(const char* section, const char* key) const;
|
bool hasConfigKey(const char* section, const char* key) const;
|
||||||
|
|
||||||
|
// getter for _module_path
|
||||||
|
void setModulePath(const std::string& module_path);
|
||||||
|
|
||||||
|
// setter for _module_path
|
||||||
|
std::string getModulePath() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* @brief Default section name to use when none is specified
|
* @brief Default section name to use when none is specified
|
||||||
|
@ -199,6 +205,8 @@ class ConfigManager {
|
||||||
* @brief Configuration data structure: section -> key -> value
|
* @brief Configuration data structure: section -> key -> value
|
||||||
*/
|
*/
|
||||||
std::map<std::string, std::map<std::string, std::string>> _config_data;
|
std::map<std::string, std::map<std::string, std::string>> _config_data;
|
||||||
|
|
||||||
|
std::string _module_path;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -141,5 +141,16 @@ extern "C" {
|
||||||
* @param level The log level as an integer (0=FATAL, 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG)
|
* @param level The log level as an integer (0=FATAL, 1=ERROR, 2=WARN, 3=INFO, 4=DEBUG)
|
||||||
*/
|
*/
|
||||||
void dpm_set_logging_level(int level);
|
void dpm_set_logging_level(int level);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the derived module path from the global configuration
|
||||||
|
*
|
||||||
|
* Allows modules to retrieve the configured module path used by DPM.
|
||||||
|
* This path is determined at runtime based on CLI arguments, configuration files,
|
||||||
|
* and defaults, in order of precedence.
|
||||||
|
*
|
||||||
|
* @return The module path as a string
|
||||||
|
*/
|
||||||
|
const char* dpm_get_module_path(void);
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
|
@ -113,4 +113,5 @@ extern "C" int dpm_module_execute(const char* command, int argc, char** argv) {
|
||||||
// If we're building in standalone mode, include the main function
|
// If we're building in standalone mode, include the main function
|
||||||
#ifdef BUILD_STANDALONE
|
#ifdef BUILD_STANDALONE
|
||||||
DPM_MODULE_STANDALONE_MAIN()
|
DPM_MODULE_STANDALONE_MAIN()
|
||||||
#endif // BUILD_STANDALONE
|
#endif // BUILD_STANDALONE
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
* @param force Whether to force the operation even if warnings occur
|
* @param force Whether to force the operation even if warnings occur
|
||||||
* @return 0 on success, non-zero on failure
|
* @return 0 on success, non-zero on failure
|
||||||
*/
|
*/
|
||||||
int seal_stage_components( const std::string& stage_dir, bool force );
|
extern "C" int seal_stage_components( const std::string& stage_dir, bool force );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Second phase of sealing to finalize a package
|
* @brief Second phase of sealing to finalize a package
|
||||||
|
@ -50,7 +50,7 @@ int seal_stage_components( const std::string& stage_dir, bool force );
|
||||||
* @param force Whether to force the operation even if warnings occur
|
* @param force Whether to force the operation even if warnings occur
|
||||||
* @return 0 on success, non-zero on failure
|
* @return 0 on success, non-zero on failure
|
||||||
*/
|
*/
|
||||||
int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force);
|
extern "C" int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unseals a package file back to stage format
|
* @brief Unseals a package file back to stage format
|
||||||
|
@ -63,7 +63,7 @@ int seal_final_package(const std::string &stage_dir, const std::string &output_d
|
||||||
* @param force Whether to force the operation even if warnings occur
|
* @param force Whether to force the operation even if warnings occur
|
||||||
* @return 0 on success, non-zero on failure
|
* @return 0 on success, non-zero on failure
|
||||||
*/
|
*/
|
||||||
int unseal_package(const std::string& package_path, const std::string& output_dir, bool force);
|
extern "C" int unseal_package(const std::string& package_path, const std::string& output_dir, bool force);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unseals component files in a stage directory
|
* @brief Unseals component files in a stage directory
|
||||||
|
@ -74,4 +74,4 @@ int unseal_package(const std::string& package_path, const std::string& output_di
|
||||||
* @param stage_dir Path to the stage directory containing components
|
* @param stage_dir Path to the stage directory containing components
|
||||||
* @return 0 on success, non-zero on failure
|
* @return 0 on success, non-zero on failure
|
||||||
*/
|
*/
|
||||||
int unseal_stage_components(const std::filesystem::path& stage_dir);
|
extern "C" int unseal_stage_components(const std::filesystem::path& stage_dir);
|
|
@ -432,7 +432,7 @@ bool smart_compress_component( const std::filesystem::path& stage_dir, const std
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int seal_stage_components(const std::string& stage_dir, bool force)
|
extern "C" int seal_stage_components(const std::string& stage_dir, bool force)
|
||||||
{
|
{
|
||||||
dpm_con(LOG_INFO, ("Sealing package stage: " + stage_dir).c_str());
|
dpm_con(LOG_INFO, ("Sealing package stage: " + stage_dir).c_str());
|
||||||
|
|
||||||
|
@ -487,7 +487,7 @@ int seal_stage_components(const std::string& stage_dir, bool force)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force)
|
extern "C" int seal_final_package(const std::string &stage_dir, const std::string &output_dir, bool force)
|
||||||
{
|
{
|
||||||
int stage_seal_result = seal_stage_components( stage_dir, force );
|
int stage_seal_result = seal_stage_components( stage_dir, force );
|
||||||
if ( stage_seal_result != 0 ) {
|
if ( stage_seal_result != 0 ) {
|
||||||
|
@ -525,7 +525,7 @@ int seal_final_package(const std::string &stage_dir, const std::string &output_d
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int unseal_package(const std::string& package_filepath, const std::string& output_dir, bool force)
|
extern "C" int unseal_package(const std::string& package_filepath, const std::string& output_dir, bool force)
|
||||||
{
|
{
|
||||||
dpm_log(LOG_INFO, ("Unsealing package: " + package_filepath).c_str());
|
dpm_log(LOG_INFO, ("Unsealing package: " + package_filepath).c_str());
|
||||||
|
|
||||||
|
@ -657,7 +657,7 @@ bool smart_uncompress_component(const std::filesystem::path& stage_dir, const st
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int unseal_stage_components(const std::filesystem::path& stage_dir)
|
extern "C" int unseal_stage_components(const std::filesystem::path& stage_dir)
|
||||||
{
|
{
|
||||||
dpm_log(LOG_INFO, ("Unsealing package components in: " + stage_dir.string()).c_str());
|
dpm_log(LOG_INFO, ("Unsealing package components in: " + stage_dir.string()).c_str());
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <dpmdk/include/CommonModuleAPI.hpp>
|
#include <dpmdk/include/CommonModuleAPI.hpp>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum Command
|
* @enum Command
|
||||||
|
|
|
@ -12,6 +12,39 @@
|
||||||
|
|
||||||
#include "verify_commands.hpp"
|
#include "verify_commands.hpp"
|
||||||
|
|
||||||
|
int check_and_load_build_module(void*& module_handle) {
|
||||||
|
// Get the module path using the new direct accessor
|
||||||
|
const char* module_path = dpm_get_module_path();
|
||||||
|
if (!module_path || strlen(module_path) == 0) {
|
||||||
|
dpm_log(LOG_ERROR, "Module path not available");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a proper path object
|
||||||
|
std::filesystem::path modules_dir(module_path);
|
||||||
|
|
||||||
|
// Build path to the build module
|
||||||
|
std::filesystem::path build_module_path = modules_dir / "build.so";
|
||||||
|
|
||||||
|
// Check if the file exists
|
||||||
|
if (!std::filesystem::exists(build_module_path)) {
|
||||||
|
dpm_log(LOG_ERROR, ("Build module not found at: " + build_module_path.string()).c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load the module
|
||||||
|
module_handle = dlopen(build_module_path.c_str(), RTLD_LAZY);
|
||||||
|
if (!module_handle) {
|
||||||
|
dpm_log(LOG_ERROR, ("Failed to load build module: " + std::string(dlerror())).c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear any error
|
||||||
|
dlerror();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_checksum(int argc, char** argv) {
|
int cmd_checksum(int argc, char** argv) {
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
bool all_packages = false;
|
bool all_packages = false;
|
||||||
|
|
|
@ -320,3 +320,11 @@ bool ConfigManager::getConfigBool(const char* section, const char* key, bool def
|
||||||
// If not recognized, return default
|
// If not recognized, return default
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigManager::setModulePath(const std::string& module_path) {
|
||||||
|
_module_path = module_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ConfigManager::getModulePath() const {
|
||||||
|
return _module_path;
|
||||||
|
}
|
|
@ -129,6 +129,8 @@ int main( int argc, char* argv[] )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_config_manager.setModulePath(module_path);
|
||||||
|
|
||||||
// create a module loader object with the determined path
|
// create a module loader object with the determined path
|
||||||
ModuleLoader loader(module_path);
|
ModuleLoader loader(module_path);
|
||||||
|
|
||||||
|
|
|
@ -120,4 +120,10 @@ extern "C" void dpm_set_logging_level(int level) {
|
||||||
}
|
}
|
||||||
|
|
||||||
g_logger.setLogLevel(log_level);
|
g_logger.setLogLevel(log_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" const char* dpm_get_module_path(void) {
|
||||||
|
static std::string module_path;
|
||||||
|
module_path = g_config_manager.getModulePath();
|
||||||
|
return module_path.c_str();
|
||||||
}
|
}
|
Loading…
Reference in New Issue