Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runguard: Allow passing -V multiple times. #2804

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions judge/runguard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#include <libcgroup.h>
#include <sched.h>
#include <sys/sysinfo.h>
#include <vector>
#include <string>

#define PROGRAM "runguard"
#define VERSION DOMJUDGE_VERSION "/" REVISION
Expand Down Expand Up @@ -106,7 +108,7 @@ char *rootchdir;
char *stdoutfilename;
char *stderrfilename;
char *metafilename;
char *environment_variables;
std::vector<std::string> environment_variables;
FILE *metafile;

char cgroupname[255];
Expand Down Expand Up @@ -363,7 +365,8 @@ Run COMMAND with restrictions.\n\
-s, --streamsize=SIZE truncate COMMAND stdout/stderr streams at SIZE kB\n\
-E, --environment preserve environment variables (default only PATH)\n\
-V, --variable add additional environment variables\n\
(in form KEY=VALUE;KEY2=VALUE2)\n\
(in form KEY=VALUE;KEY2=VALUE2); may be passed\n\
multiple times\n\
-M, --outmeta=FILE write metadata (runtime, exitcode, etc.) to FILE\n\
-U, --runpipepid=PID process ID of runpipe to send SIGUSR1 signal when\n\
timelimit is reached\n");
Expand Down Expand Up @@ -802,8 +805,8 @@ void setrestrictions()
}

/* Set additional environment variables. */
if (environment_variables != nullptr) {
char *token = strtok(environment_variables, ";");
for (const auto &tokens : environment_variables) {
char *token = strtok(strdup(tokens.c_str()), ";");
while (token != nullptr) {
verbose("setting environment variable: %s", token);
putenv(token);
Expand Down Expand Up @@ -1175,7 +1178,7 @@ int main(int argc, char **argv)
preserve_environment = 1;
break;
case 'V': /* set environment variable */
environment_variables = strdup(optarg);
environment_variables.push_back(std::string(optarg));
break;
case 'M': /* outputmeta option */
outputmeta = 1;
Expand Down
5 changes: 3 additions & 2 deletions judge/runguard_test/runguard_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,11 @@ test_envvars() {
expect_stdout "USER="
expect_stdout "SHELL="

exec_check_success sudo $RUNGUARD -u domjudge-run-0 -V"DOMjudgeA=A;DOMjudgeB=BB" ./print_envvars.py
expect_stdout "COUNT: 4."
exec_check_success sudo $RUNGUARD -u domjudge-run-0 -V"DOMjudgeA=A;DOMjudgeB=BB" -V"DOMjudgeC=CCC" ./print_envvars.py
expect_stdout "COUNT: 5."
expect_stdout "DOMjudgeA=A"
expect_stdout "DOMjudgeB=BB"
expect_stdout "DOMjudgeC=CCC"
not_expect_stdout "HOME="
not_expect_stdout "USER="
not_expect_stdout "SHELL="
Expand Down
Loading