[PATCH] Attempted fix for occasional execv error
authorSam Moore <[email protected]>
Sat, 17 Mar 2012 07:46:59 +0000 (15:46 +0800)
committerSam Moore <[email protected]>
Sat, 17 Mar 2012 07:46:59 +0000 (15:46 +0800)
If there are no arguments passed to an AI, pass execv NULL for the arguments.
Passing it a pointer to an array of size zero... is not good.

judge/manager/network_controller.cpp
judge/manager/program.cpp

index fcca84e..5a689a0 100644 (file)
@@ -19,7 +19,7 @@ MovementResult NetworkReceiver::QuerySetup(const char * opponentName, string set
        //fprintf(stderr,"      NetworkReceiver::QuerySetup... ");
        for (int ii=0; ii < 4; ++ii)
        {
-               assert(network->GetMessage(setup[ii], 20));
+               assert(network->GetMessage(setup[ii], 20000));
        }
        //fprintf(stderr,"Done!\n");
        return MovementResult::OK;
@@ -34,6 +34,6 @@ MovementResult NetworkSender::QueryMove(string & buffer)
 
 MovementResult NetworkReceiver::QueryMove(string & buffer)
 {
-       assert(network->GetMessage(buffer, 20));
+       assert(network->GetMessage(buffer, 20000));
        return MovementResult::OK;
 }
index 2d09a51..02c9cb8 100644 (file)
@@ -8,6 +8,7 @@
 #include "program.h"
 #include <vector>
 #include <string.h>
+#include <stdio.h>
 
 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
        }

UCC git Repository :: git.ucc.asn.au