cmdline: allow to override config cmdline with cmdline cmdline

This commit is contained in:
Robert Swiecki 2019-03-30 16:10:14 +01:00
parent e3db427f0b
commit 2b1bad6b5b
3 changed files with 20 additions and 10 deletions

View File

@ -298,17 +298,25 @@ static std::string argFromVec(const std::vector<std::string>& vec, size_t pos) {
}
static bool setupArgv(nsjconf_t* nsjconf, int argc, char** argv, int optind) {
for (int i = optind; i < argc; i++) {
nsjconf->argv.push_back(argv[i]);
}
if (nsjconf->argv.empty()) {
cmdlineUsage(argv[0]);
LOG_E("No command provided");
return false;
/*
* If user provided cmdline via nsjail [opts] -- [cmdline], then override the one from the
* config file
*/
if (optind < argc) {
nsjconf->argv.clear();
nsjconf->exec_file.clear();
for (int i = optind; i < argc; i++) {
nsjconf->argv.push_back(argv[i]);
}
}
if (nsjconf->exec_file.empty()) {
nsjconf->exec_file = nsjconf->argv[0];
}
if (nsjconf->exec_file.empty()) {
cmdlineUsage(argv[0]);
LOG_E("No command-line provided");
return false;
}
if (nsjconf->use_execveat) {
#if !defined(__NR_execveat)

View File

@ -265,8 +265,10 @@ static bool configParseInternal(nsjconf_t* nsjconf, const nsjail::NsJailConfig&
nsjconf->iface_vs_ma = njc.macvlan_vs_ma();
if (njc.has_exec_bin()) {
nsjconf->exec_file = njc.exec_bin().path();
nsjconf->argv.push_back(njc.exec_bin().path());
if (njc.exec_bin().has_path()) {
nsjconf->exec_file = njc.exec_bin().path();
nsjconf->argv.push_back(njc.exec_bin().path());
}
for (ssize_t i = 0; i < njc.exec_bin().arg().size(); i++) {
nsjconf->argv.push_back(njc.exec_bin().arg(i));
}

View File

@ -66,7 +66,7 @@ enum RLimit {
}
message Exe {
/* Will be used both as execv's path and as argv[0] */
required string path = 1;
optional string path = 1;
/* This will be argv[1] and so on.. */
repeated string arg = 2;
/* Override argv[0] */