|
62 | 62 | #include <libcgroup.h>
|
63 | 63 | #include <sched.h>
|
64 | 64 | #include <sys/sysinfo.h>
|
| 65 | +#include <vector> |
| 66 | +#include <string> |
65 | 67 |
|
66 | 68 | #define PROGRAM "runguard"
|
67 | 69 | #define VERSION DOMJUDGE_VERSION "/" REVISION
|
@@ -106,7 +108,7 @@ char *rootchdir;
|
106 | 108 | char *stdoutfilename;
|
107 | 109 | char *stderrfilename;
|
108 | 110 | char *metafilename;
|
109 |
| -char *environment_variables; |
| 111 | +std::vector<std::string> environment_variables; |
110 | 112 | FILE *metafile;
|
111 | 113 |
|
112 | 114 | char cgroupname[255];
|
@@ -363,7 +365,8 @@ Run COMMAND with restrictions.\n\
|
363 | 365 | -s, --streamsize=SIZE truncate COMMAND stdout/stderr streams at SIZE kB\n\
|
364 | 366 | -E, --environment preserve environment variables (default only PATH)\n\
|
365 | 367 | -V, --variable add additional environment variables\n\
|
366 |
| - (in form KEY=VALUE;KEY2=VALUE2)\n\ |
| 368 | + (in form KEY=VALUE;KEY2=VALUE2); may be passed\n\ |
| 369 | + multiple times\n\ |
367 | 370 | -M, --outmeta=FILE write metadata (runtime, exitcode, etc.) to FILE\n\
|
368 | 371 | -U, --runpipepid=PID process ID of runpipe to send SIGUSR1 signal when\n\
|
369 | 372 | timelimit is reached\n");
|
@@ -802,8 +805,8 @@ void setrestrictions()
|
802 | 805 | }
|
803 | 806 |
|
804 | 807 | /* Set additional environment variables. */
|
805 |
| - if (environment_variables != nullptr) { |
806 |
| - char *token = strtok(environment_variables, ";"); |
| 808 | + for (const auto &tokens : environment_variables) { |
| 809 | + char *token = strtok(strdup(tokens.c_str()), ";"); |
807 | 810 | while (token != nullptr) {
|
808 | 811 | verbose("setting environment variable: %s", token);
|
809 | 812 | putenv(token);
|
@@ -1175,7 +1178,7 @@ int main(int argc, char **argv)
|
1175 | 1178 | preserve_environment = 1;
|
1176 | 1179 | break;
|
1177 | 1180 | case 'V': /* set environment variable */
|
1178 |
| - environment_variables = strdup(optarg); |
| 1181 | + environment_variables.push_back(std::string(optarg)); |
1179 | 1182 | break;
|
1180 | 1183 | case 'M': /* outputmeta option */
|
1181 | 1184 | outputmeta = 1;
|
|
0 commit comments