const char * util_interp_setenv( const char * variable , const char * value) {
  char * interp_value = util_alloc_envvar( value );
  if (interp_value != NULL) {
    util_setenv( variable , interp_value);
    free( interp_value );
  } else
    util_unsetenv( variable );
  
  return getenv( variable );
}
const char * util_update_path_var(const char * variable, const char * value, bool append) {
  const char * current_value = getenv( variable );
  if (current_value == NULL)
    /* The (path) variable is not currently set. */
    util_setenv( variable , value );
  else {
    bool    update = true; 

    {
      char ** path_list;
      int     num_path;
      util_split_string( current_value , ":" , &num_path , &path_list);
      if (append) {
        int i;
        for (i = 0; i < num_path; i++) {
          if (util_string_equal( path_list[i] , value)) 
            update = false;                            /* The environment variable already contains @value - no point in appending it at the end. */
        } 
      } else {
        if (util_string_equal( path_list[0] , value)) 
          update = false;                              /* The environment variable already starts with @value. */
      }
      util_free_stringlist( path_list , num_path );
    }
    
    if (update) {
      char  * new_value;
      if (append)
        new_value = util_alloc_sprintf("%s:%s" , current_value , value);
      else
        new_value = util_alloc_sprintf("%s:%s" , value , current_value);
      util_setenv( variable , new_value );
      free( new_value );
    }
    
  }
  return getenv( variable );
}
Example #3
0
void site_config_clear_pathvar( site_config_type * site_config ) {
  stringlist_clear( site_config->path_variables_user );
  stringlist_clear( site_config->path_values_user );
  {
    /* Recover the original values. */
    hash_iter_type * hash_iter = hash_iter_alloc( site_config->path_variables_site );
    while (!hash_iter_is_complete( hash_iter )) {
      const char * var       = hash_iter_get_next_key( hash_iter );
      const char * site_value = hash_get( site_config->path_variables_site , var );
      
      if (site_value == NULL)
        util_unsetenv( var );
      else
        util_setenv( var , site_value );
    }
  }
}
void util_unsetenv( const char * variable ) {
  util_setenv( variable , NULL );
}
Example #5
0
int main( int argc, char ** argv) {
  if (argc == 1)
    util_exit("block_node  node1  node2  node3:2  \n");
  
  /* Initialize lsf environment */
  util_setenv( "LSF_BINDIR"    , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/bin" );
  util_setenv( "LSF_LINDIR"    , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib" );
  util_setenv( "XLSF_UIDDIR"   , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib/uid" );
  util_setenv( "LSF_SERVERDIR" , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/etc");
  util_setenv( "LSF_ENVDIR"    , "/prog/LSF/conf");
  
  util_update_path_var( "PATH"               , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/bin" , false);
  util_update_path_var( "LD_LIBRARY_PATH"    , "/prog/LSF/9.1/linux2.6-glibc2.3-x86_64/lib" , false);

  
  lsf_driver = lsf_driver_alloc();
  if (lsf_driver_get_submit_method( lsf_driver ) != LSF_SUBMIT_INTERNAL)
    util_exit("Sorry - the block_node program must be invoked on a proper LSF node \n");

  {
    
    int iarg;
    int total_blocked_target = 0;
    nodes       = hash_alloc();
    for (iarg = 1; iarg < argc; iarg++) {
      char   *node_name;
      int    num_slots;
      
      {
        char * num_slots_string;
        util_binary_split_string( argv[iarg] , ":" , true , &node_name , &num_slots_string);
        if (num_slots_string)
          util_sscanf_int( num_slots_string , &num_slots);
        else
          num_slots = 1;
      }
      
      if (!hash_has_key( nodes , node_name))
        hash_insert_hash_owned_ref( nodes , node_name , count_pair_alloc() , free);

      {
        count_pair_type * pair = hash_get( nodes , node_name);
        pair->target += num_slots;
      }
      total_blocked_target += num_slots;
    }

    signal(SIGINT , block_node_exit );
    {
      const int sleep_time    = 5;
      const int chunk_size    = 10;    /* We submit this many at a time. */
      const int max_pool_size = 1000;  /* The absolute total maximum of jobs we will submit. */  

      bool           cont        = true;
      int            pending     = 0;   
      bool           all_blocked;
      job_pool                   = vector_alloc_new();

      while (cont) {
        printf("[Ctrl-C to give up] "); fflush( stdout );
        if (cont) sleep( sleep_time );
        if (pending == 0) {
          if (vector_get_size( job_pool ) < max_pool_size)
            add_jobs( chunk_size );
        }
        
        update_pool_status( &all_blocked , &pending);
        print_status();

        if (all_blocked)
          cont = false;
      }
      if (!all_blocked)
        printf("Sorry - failed to block all the nodes \n");
      
      block_node_exit( 0 );
      hash_free( nodes );
    }
  }
}