示例#1
0
static char * util_bt_alloc_current_executable(const char * bt_symbol) {
  if (__current_executable != NULL) 
    return util_alloc_string_copy(__current_executable );
  else {
    if (bt_symbol != NULL) {
      int paren_pos = 0;
      char * path;
      while (bt_symbol[paren_pos] != '(' && bt_symbol[paren_pos] != ' ')
        paren_pos++;
      
      path = util_alloc_substring_copy(bt_symbol , 0 , paren_pos);
      if (util_is_abs_path(path))
        return path;
      else {
        char * full_path = util_alloc_PATH_executable( path );
        free(path);
        return full_path;
      }
    } else 
      return NULL;
  }
}
示例#2
0
bool config_schema_item_validate_set(const config_schema_item_type * item , stringlist_type * token_list , const char * config_file, const config_path_elm_type * path_elm , config_error_type * error_list) {
  bool OK = true;
  int argc = stringlist_get_size( token_list ) - 1;
  if (item->validate->argc_min >= 0) {
    if (argc < item->validate->argc_min) {
      OK = false;
      {
        char * error_message;
        if (config_file != NULL)
          error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have at least %d arguments.",config_file , item->kw , item->validate->argc_min);
        else
          error_message = util_alloc_sprintf("Error:: Keyword:%s must have at least %d arguments.",item->kw , item->validate->argc_min);

        config_error_add( error_list , error_message );
      }
    }
  }

  if (item->validate->argc_max >= 0) {
    if (argc > item->validate->argc_max) {
      OK = false;
      {
        char * error_message;

        if (config_file != NULL)
          error_message = util_alloc_sprintf("Error when parsing config_file:\"%s\" Keyword:%s must have maximum %d arguments.",config_file , item->kw , item->validate->argc_max);
        else
          error_message = util_alloc_sprintf("Error:: Keyword:%s must have maximum %d arguments.",item->kw , item->validate->argc_max);

        config_error_add( error_list , error_message );
      }
    }
  }

  /*
     OK - now we have verified that the number of arguments is correct. Then
     we start actually looking at the values.
  */
  if (OK) {
    /* Validating selection set - first common, then indexed */
    if (item->validate->common_selection_set) {
      for (int iarg = 0; iarg < argc; iarg++) {
        if (!set_has_key(item->validate->common_selection_set , stringlist_iget( token_list , iarg + 1))) {
          config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for: %s.",stringlist_iget( token_list , iarg + 1) , item->kw));
          OK = false;
        }
      }
    } else if (item->validate->indexed_selection_set != NULL) {
      for (int iarg = 0; iarg < argc; iarg++) {
        if ((item->validate->argc_max > 0) || (iarg < item->validate->argc_min)) {  /* Without this test we might go out of range on the indexed selection set. */
          const set_type * selection_set = validate_iget_selection_set( item->validate , iarg);
          if (selection_set) {
            if (!set_has_key( selection_set, stringlist_iget( token_list , iarg + 1))) {
              config_error_add( error_list , util_alloc_sprintf("%s: is not a valid value for item %d of \'%s\'.",stringlist_iget( token_list , iarg + 1) , iarg + 1 , item->kw));
              OK = false;
            }
          }
        }
      }
    }

    /*
      Observe that the following code might rewrite the content of
      argv for arguments referring to path locations.
    */


    /* Validate the TYPE of the various argumnents */
    {
      for (int iarg = 0; iarg < argc; iarg++) {
        const char * value = stringlist_iget(token_list , iarg + 1);
        switch (validate_iget_type( item->validate , iarg)) {
        case(CONFIG_STRING): /* This never fails ... */
          break;
        case(CONFIG_ISODATE):
          if (!util_sscanf_isodate( value , NULL ))
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an ISO date: YYYY-MM-DD.",value));
          break;
        case(CONFIG_INT):
          if (!util_sscanf_int( value , NULL ))
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as an integer.",value));
          break;
        case(CONFIG_FLOAT):
          if (!util_sscanf_double( value , NULL )) {
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a floating point number.", value));
            OK = false;
          }
          break;
        case(CONFIG_PATH):
          // As long as we do not reuqire the path to exist it is just a string.
          break;
        case(CONFIG_EXISTING_PATH):
          {
            char * path = config_path_elm_alloc_abspath( path_elm , value );
            if (!util_entry_exists(path)) {
              config_error_add( error_list , util_alloc_sprintf("Can not find entry %s in %s ",value , config_path_elm_get_relpath( path_elm) ));
              OK = false;
            }
            free( path );
          }
          break;
        case(CONFIG_EXECUTABLE):
          {
            /*
              1. If the supplied value is an abolute path - do nothing.
              2. If the supplied is _not_ an absolute path:

                 a. Try if the relocated exists - then use that.
                 b. Else - try if the util_alloc_PATH_executable() exists.
            */
            if (!util_is_abs_path( value )) {
              char * relocated  = __alloc_relocated__(path_elm , value);
              char * path_exe   = util_alloc_PATH_executable( value );

              if (util_file_exists(relocated)) {
                if (util_is_executable(relocated))
                  stringlist_iset_copy( token_list , iarg , relocated);
              } else if (path_exe != NULL)
                stringlist_iset_copy( token_list , iarg , path_exe);
              else
                config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value));

              free(relocated);
              util_safe_free(path_exe);
            } else {
              if (!util_is_executable( value ))
                config_error_add( error_list , util_alloc_sprintf("Could not locate executable:%s ", value));
            }
          }
          break;
        case(CONFIG_BOOL):
          if (!util_sscanf_bool( value , NULL )) {
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:%s as a boolean.", value));
            OK = false;
          }
          break;
        case(CONFIG_BYTESIZE):
          if (!util_sscanf_bytesize( value , NULL)) {
            config_error_add( error_list , util_alloc_sprintf("Failed to parse:\"%s\" as number of bytes." , value));
            OK = false;
          }
          break;
        default:
          util_abort("%s: config_item_type:%d not recognized \n",__func__ , validate_iget_type(item->validate , iarg));
        }
      }
    }
  }
  return OK;
}
示例#3
0
job_queue_node_type * job_queue_node_alloc( const char * job_name ,
                                            const char * run_path ,
                                            const char * run_cmd ,
                                            int argc ,
                                            const char ** argv,
                                            int num_cpu,
                                            const char * ok_file,
                                            const char * exit_file,
                                            job_callback_ftype * done_callback,
                                            job_callback_ftype * retry_callback,
                                            job_callback_ftype * exit_callback,
                                            void * callback_arg) {

  if (util_is_directory( run_path )) {
    job_queue_node_type * node = util_malloc(sizeof * node );

    UTIL_TYPE_ID_INIT( node , JOB_QUEUE_NODE_TYPE_ID );
    {
      /* The data initialized in this block should *NEVER* change. */
      node->job_name       = util_alloc_string_copy( job_name );

      if (util_is_abs_path(run_path))
        node->run_path = util_alloc_string_copy( run_path );
      else
        node->run_path = util_alloc_realpath( run_path );

      node->run_cmd        = util_alloc_string_copy( run_cmd );
      node->argc           = argc;
      node->argv           = util_alloc_stringlist_copy( argv , argc );
      node->num_cpu        = num_cpu;

      if (ok_file)
        node->ok_file = util_alloc_filename(node->run_path , ok_file , NULL);
      else
        node->ok_file = NULL;

      if (exit_file)
        node->exit_file = util_alloc_filename(node->run_path , exit_file , NULL);
      else
        node->exit_file = NULL;

      node->exit_callback  = exit_callback;
      node->retry_callback = retry_callback;
      node->done_callback  = done_callback;
      node->callback_arg   = callback_arg;
    }
    {
      node->error_reason   = NULL;
      node->stderr_capture = NULL;
      node->stderr_file    = NULL;
      node->failed_job     = NULL;
    }
    {
      node->job_status     = JOB_QUEUE_NOT_ACTIVE;
      node->queue_index    = INVALID_QUEUE_INDEX;
      node->submit_attempt = 0;
      node->job_data       = NULL;                                    /* The allocation is run in single thread mode - we assume. */
      node->sim_start      = 0;
      node->sim_end        = 0;
      node->submit_time    = time( NULL );
    }

    pthread_mutex_init( &node->data_mutex , NULL );
    return node;
  } else
    return NULL;
}