{ { "quiet", no_argument, NULL, 'q' }, "Log warning and more important messages only" },
{ { "really_quiet", no_argument, NULL, 'Q' }, "Log fatal messages only" },
{ { "keep_env", no_argument, NULL, 'e' }, "Pass all environment variables to the child process (default: all envvars are cleared)" },
- { { "env", required_argument, NULL, 'E' }, "Additional environment variable (can be used multiple times)" },
+ { { "env", required_argument, NULL, 'E' }, "Additional environment variable (can be used multiple times). If the envvar doesn't contain '=' (e.g. just the 'DISPLAY' string), the current envvar value will be used" },
{ { "keep_caps", no_argument, NULL, 0x0501 }, "Don't drop any capabilities" },
{ { "cap", required_argument, NULL, 0x0509 }, "Retain this capability, e.g. CAP_PTRACE (can be specified multiple times)" },
{ { "silent", no_argument, NULL, 0x0502 }, "Redirect child process' fd:0/1/2 to /dev/null" },
LOG_HELP_BOLD(" nsjail -Me --chroot / --disable_proc -- /bin/echo \"ABC\"");
}
+void addEnv(nsjconf_t* nsjconf, const std::string& env) {
+ if (env.find('=') != std::string::npos) {
+ nsjconf->envs.push_back(env);
+ return;
+ }
+ char* e = getenv(env.c_str());
+ if (!e) {
+ nsjconf->envs.push_back(env);
+ return;
+ }
+ nsjconf->envs.push_back(std::string(env).append("=").append(e));
+}
+
void logParams(nsjconf_t* nsjconf) {
switch (nsjconf->mode) {
case MODE_LISTEN_TCP:
nsjconf->use_execveat = true;
break;
case 'E':
- nsjconf->envs.push_back(optarg);
+ addEnv(nsjconf.get(), optarg);
break;
case 'u': {
std::vector<std::string> subopts = util::strSplit(optarg, ':');
/* Should the current environment variables be kept
when executing the binary */
optional bool keep_env = 19 [default = false];
- /* EnvVars to be set before executing binaries */
+ /* EnvVars to be set before executing binaries. If the envvar doesn't contain '='
+ (e.g. just the 'DISPLAY' string), the current envvar value will be used */
repeated string envar = 20;
/* Should capabilities be preserved or dropped */