X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=progcomp%2Fjudge%2Fmanager%2Fprogram.cpp;h=588f7146c323f19f47369a5ab52845c40ebbc12f;hp=660362ac06cc7535c1f2814c9e1bd6579b17c0d4;hb=baf69b8ddea3e2749f114a1e82bc1253ef062bc0;hpb=88fc5a96c424e9a451b98f3b680bc1980345320d diff --git a/progcomp/judge/manager/program.cpp b/progcomp/judge/manager/program.cpp index 660362a..588f714 100644 --- a/progcomp/judge/manager/program.cpp +++ b/progcomp/judge/manager/program.cpp @@ -22,13 +22,8 @@ using namespace std; */ Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0) { - //See if file exists... - FILE * file = fopen(executablePath, "r"); - if (file != NULL) - { - fclose(file); - } - else + //See if file exists and is executable... + if (access(executablePath, X_OK) != 0) { pid = -1; return; @@ -55,10 +50,11 @@ Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0 //If your wrapped program is not written in C/C++, you will probably have a problem - - execl(executablePath, executablePath, (char*)(NULL)); ///Replace process with desired executable - //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 + 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 + + 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 } else {