}
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)
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));
}
}
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] */