X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=judge%2Fmanager%2Fprogram.cpp;h=02c9cb86ea3f0eb86781dd4ef923467f3a936002;hb=451c60e0e37013ecf85360bad290d454b94c5477;hp=031d4113febc78d7f41cc9e10f0e7481ceb013f3;hpb=38c6e9b9fc245ca5e6e6cee2806cb64dcbd34e35;p=progcomp2012.git diff --git a/judge/manager/program.cpp b/judge/manager/program.cpp index 031d411..02c9cb8 100644 --- a/judge/manager/program.cpp +++ b/judge/manager/program.cpp @@ -6,7 +6,9 @@ #include "thread_util.h" #include "program.h" - +#include +#include +#include using namespace std; @@ -22,6 +24,46 @@ using namespace std; */ Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0), paused(false) { + + + + vector args; + if (executablePath[0] != '"') + args.push_back((char*)executablePath); + else + args.push_back((char*)(executablePath)+1); + char * token = NULL; + do + { + token = strstr(args[args.size()-1], " "); + if (token == NULL) + break; + + *token = '\0'; + do + { + ++token; + if (*token == '"') + *token = '\0'; + } + while (*token != '\0' && iswspace(*token)); + + if (*token != '\0' && !iswspace(*token)) + { + args.push_back(token); + } + else + break; + } + while (token != NULL); + + char ** arguments = NULL; + if (args.size() > 0) + { + arguments = new char*[args.size()+2]; + for (unsigned int i=0; i < args.size(); ++i) + arguments[i] = args[i]; + } //See if file exists and is executable... if (access(executablePath, X_OK) != 0) { @@ -51,8 +93,10 @@ Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0 if (access(executablePath, X_OK) == 0) //Check we STILL have permissions to start the file - execl(executablePath, executablePath, (char*)(NULL)); ///Replace process with desired executable - + { + execv(executablePath,arguments); ///Replace process with desired executable + } + perror("execv error:\n"); fprintf(stderr, "Program::Program - Could not run program \"%s\"!\n", executablePath); exit(EXIT_FAILURE); //We will probably have to terminate the whole program if this happens }