From: Sam Moore Date: Sat, 19 Oct 2013 15:40:22 +0000 (+0800) Subject: Merge branch 'master' of github:szmoore/MCTX3420 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=544b54c409f3731b8e1581af95072a64ff393a28;p=matches%2FMCTX3420.git Merge branch 'master' of github:szmoore/MCTX3420 Conflicts: server/control.c --- 544b54c409f3731b8e1581af95072a64ff393a28 diff --cc server/common.h index 637a813,fa997c5..0875b34 --- a/server/common.h +++ b/server/common.h @@@ -42,16 -40,13 +42,17 @@@ #include "control.h" /**Converts a timeval to a double**/ -#define TIMEVAL_TO_DOUBLE(tv) ((tv).tv_sec + 1e-6 * ((tv).tv_usec)) +#define TIMEVAL_TO_DOUBLE(tv) ((tv).tv_sec + 1e-9 * ((tv).tv_nsec)) /**Takes the tv1-tv2 between two timevals and returns the result as a double*/ -#define TIMEVAL_DIFF(tv1, tv2) ((tv1).tv_sec - (tv2).tv_sec + 1e-6 * ((tv1).tv_usec - (tv2).tv_usec)) - +#define TIMEVAL_DIFF(tv1, tv2) ((tv1).tv_sec - (tv2).tv_sec + 1e-9 * ((tv1).tv_nsec - (tv2).tv_nsec)) +/** Converts a double time value (in seconds) to a timespec **/ +#define DOUBLE_TO_TIMEVAL(value, tv) { \ + (tv)->tv_sec = (int)(value); \ + (tv)->tv_nsec = ((value) - (int)(value))*1e9; \ + } extern bool PathExists(const char * path); + extern bool DirExists(const char * path); diff --cc server/control.c index 776cdd1,4342c8c..6ebaba7 --- a/server/control.c +++ b/server/control.c @@@ -12,8 -14,10 +14,10 @@@ typedef struct ControlData { ControlModes current_mode; pthread_mutex_t mutex; - struct timeval start_time; + struct timespec start_time; char user_name[31]; // The user who owns the currently running experiment + char experiment_dir[BUFSIZ]; //Directory for experiment + char experiment_name[BUFSIZ]; } ControlData; ControlData g_controls = {CONTROL_STOP, PTHREAD_MUTEX_INITIALIZER, {0}}; @@@ -192,18 -219,13 +219,13 @@@ const char* Control_SetMode(ControlMode else switch (desired_mode) { case CONTROL_START: if (g_controls.current_mode == CONTROL_STOP) { - const char * name = arg; - if (!*name) - ret = "An experiment name must be specified"; - else if (strpbrk(name, INVALID_CHARACTERS)) - ret = "The experiment name must not contain: " INVALID_CHARACTERS_JSON; - else { - FILE *fp = fopen((const char*) arg, "a"); - if (fp) { - fclose(fp); - clock_gettime(CLOCK_MONOTONIC, &(g_controls.start_time)); - } else - ret = "Cannot open experiment name marker"; + const char * path = arg; + if (mkdir(path, 0777) != 0 && errno != EEXIST) { + Log(LOGERR, "Couldn't create experiment directory %s - %s", + path, strerror(errno)); + ret = "Couldn't create experiment directory."; + } else { - gettimeofday(&(g_controls.start_time), NULL); ++ clock_gettime(CLOCK_MONOTONIC, &(g_controls.start_time)); } } else ret = "Cannot start when not in a stopped state."; diff --cc server/fastcgi.c index a94a5ba,fd5839e..0a6783f --- a/server/fastcgi.c +++ b/server/fastcgi.c @@@ -540,10 -554,10 +559,10 @@@ void * FCGI_RequestLoop (void *data if (module_handler) { - if (module_handler != Login_Handler && module_handler != IdentifyHandler && module_handler) - //if (false) // Testing + //if (module_handler != Login_Handler && module_handler != IdentifyHandler && module_handler) + if (false) // Testing { - if (!FCGI_HasControl(&context, cookie)) + if (!FCGI_HasControl(&context, control_key)) { FCGI_RejectJSON(&context, "Please login. Invalid control key."); continue; diff --cc server/main.c index 5aef29f,e7edc7e..fadcd3a --- a/server/main.c +++ b/server/main.c @@@ -39,12 -32,10 +39,10 @@@ void ParseArguments(int argc, char ** a g_options.program = argv[0]; // program name g_options.verbosity = LOGDEBUG; // default log level // Set the main directory - if (getcwd(g_options.root_dir, sizeof(g_options.root_dir)) == NULL) - Fatal("Couldn't get current working directory - %s", strerror(errno)); + //if (getcwd(g_options.root_dir, sizeof(g_options.root_dir)) == NULL) + // Fatal("Couldn't get current working directory - %s", strerror(errno)); - gettimeofday(&(g_options.start_time), NULL); // Start time + clock_gettime(CLOCK_MONOTONIC, &(g_options.start_time)); // Start time g_options.auth_method = AUTH_NONE; // Don't use authentication diff --cc server/sensor.c index 816a895,c41d39e..ae5cdf4 --- a/server/sensor.c +++ b/server/sensor.c @@@ -303,10 -292,9 +307,9 @@@ void Sensor_EndResponse(FCGIContext * c */ void Sensor_Handler(FCGIContext *context, char * params) { - struct timeval now; - gettimeofday(&now, NULL); + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime()); - int id = 0; const char * name = ""; double start_time = 0;