X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=judge%2Fmanager%2Fprogram.cpp;h=02c9cb86ea3f0eb86781dd4ef923467f3a936002;hp=2d09a510aa6e9c70ba0c0f0bf4922812de7cae63;hb=58a1ee0aeace5a6a9aea4cbdbfe8870d106409f6;hpb=6a473ff260f5cf194533cdc4bd80d1ea086cd597 diff --git a/judge/manager/program.cpp b/judge/manager/program.cpp index 2d09a51..02c9cb8 100644 --- a/judge/manager/program.cpp +++ b/judge/manager/program.cpp @@ -8,6 +8,7 @@ #include "program.h" #include #include +#include using namespace std; @@ -56,10 +57,13 @@ Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0 } while (token != NULL); - char ** arguments = new char*[args.size()+2]; - for (unsigned int i=0; i < args.size(); ++i) - arguments[i] = args[i]; - + 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) { @@ -89,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 + { 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 }