mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Specify environment variables to contract binary (#355)
This commit is contained in:
@@ -948,6 +948,7 @@ namespace conf
|
||||
jdoc.insert_or_assign("unl", unl);
|
||||
jdoc.insert_or_assign("bin_path", contract.bin_path);
|
||||
jdoc.insert_or_assign("bin_args", contract.bin_args);
|
||||
jdoc.insert_or_assign("environment", contract.environment);
|
||||
jdoc.insert_or_assign("roundtime", contract.roundtime.load());
|
||||
jdoc.insert_or_assign("stage_slice", contract.stage_slice.load());
|
||||
jdoc.insert_or_assign("consensus", contract.is_consensus_public ? PUBLIC : PRIVATE);
|
||||
@@ -1045,6 +1046,7 @@ namespace conf
|
||||
|
||||
contract.bin_path = jdoc["bin_path"].as<std::string>();
|
||||
contract.bin_args = jdoc["bin_args"].as<std::string>();
|
||||
contract.environment = jdoc["environment"].as<std::string>();
|
||||
|
||||
contract.roundtime = jdoc["roundtime"].as<uint32_t>();
|
||||
if (contract.roundtime < 1 || contract.roundtime > MAX_ROUND_TIME)
|
||||
@@ -1093,6 +1095,11 @@ namespace conf
|
||||
return -1;
|
||||
}
|
||||
|
||||
contract.runtime_env_args.clear();
|
||||
// Populate runtime environment args.
|
||||
if (!contract.environment.empty())
|
||||
util::split_string(contract.runtime_env_args, contract.environment, " ");
|
||||
|
||||
contract.runtime_binexec_args.clear();
|
||||
// Populate runtime contract execution args.
|
||||
if (!contract.bin_args.empty())
|
||||
|
||||
@@ -182,6 +182,7 @@ namespace conf
|
||||
std::set<std::string> unl; // Unique node list (list of binary public keys).
|
||||
std::string bin_path; // Full path to the contract binary.
|
||||
std::string bin_args; // CLI arguments to pass to the contract binary.
|
||||
std::string environment; // Environment variables to be passed into contract.
|
||||
std::atomic<uint32_t> roundtime = 0; // Consensus round time in ms (max: 3,600,000).
|
||||
std::atomic<uint32_t> stage_slice = 0; // Percentage slice of round time that stages 0,1,2 get (max: 33).
|
||||
bool is_consensus_public = false; // If true, consensus are broadcasted to non-unl nodes as well.
|
||||
@@ -192,6 +193,7 @@ namespace conf
|
||||
|
||||
// Config element which are initialized in memory (This is not directly loaded from the config file)
|
||||
std::vector<std::string> runtime_binexec_args; // Contract binary execution args used during runtime.
|
||||
std::vector<std::string> runtime_env_args; // Contract environment variables.
|
||||
};
|
||||
|
||||
struct user_config
|
||||
|
||||
@@ -210,6 +210,12 @@ namespace sc
|
||||
execv_args[j] = conf::cfg.contract.runtime_binexec_args[i].data();
|
||||
execv_args[len - 1] = NULL;
|
||||
|
||||
len = conf::cfg.contract.runtime_env_args.size() + 1;
|
||||
char *env_args[len];
|
||||
for (int i = 0; i < conf::cfg.contract.runtime_env_args.size(); i++)
|
||||
env_args[i] = conf::cfg.contract.runtime_env_args[i].data();
|
||||
env_args[len - 1] = NULL;
|
||||
|
||||
if (chdir(ctx.working_dir.c_str()) == -1)
|
||||
{
|
||||
std::cerr << errno << ": Contract process chdir failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n";
|
||||
@@ -224,8 +230,8 @@ namespace sc
|
||||
exit(1);
|
||||
}
|
||||
|
||||
execv(execv_args[0], execv_args);
|
||||
std::cerr << errno << ": Contract process execv failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n";
|
||||
execve(execv_args[0], execv_args, env_args);
|
||||
std::cerr << errno << ": Contract process execve failed." << (ctx.args.readonly ? " (rdonly)" : "") << "\n";
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user