static bool
sge_gdi_map_pack_errors(int pack_ret, lList **answer_list)
{
   bool ret = true;

   DENTER(GDI_LAYER, "sge_gdi_map_pack_errors");
   switch (pack_ret) {
   case PACK_SUCCESS:
      break;
   case PACK_ENOMEM:
      answer_list_add_sprintf(answer_list, STATUS_ERROR2,
                              ANSWER_QUALITY_ERROR,
                              MSG_GDI_MEMORY_NOTENOUGHMEMORYFORPACKINGGDIREQUEST);
      break;
   case PACK_FORMAT:
      answer_list_add_sprintf(answer_list, STATUS_ERROR3,
                              ANSWER_QUALITY_ERROR,
                              MSG_GDI_REQUESTFORMATERROR);
      break;
   default:
      answer_list_add_sprintf(answer_list, STATUS_ERROR1,
                              ANSWER_QUALITY_ERROR,
                              MSG_GDI_UNEXPECTEDERRORWHILEPACKINGGDIREQUEST);
      break;
   }
   ret = (pack_ret == PACK_SUCCESS) ? true : false;

   DRETURN(ret);
}
Beispiel #2
0
bool
spool_set_option(lList **answer_list, lListElem *context, const char *option)
{
   bool ret = true;

   DENTER(TOP_LAYER, "spool_set_option");
   PROF_START_MEASUREMENT(SGE_PROF_SPOOLING);
  
   if (context == NULL) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, MSG_SPOOL_NOVALIDCONTEXT_S, 
                              SGE_FUNC);
   } else {
      lListElem *rule;

      for_each (rule, lGetList(context, SPC_rules)) {
         spooling_option_func func = (spooling_option_func)
                                       lGetRef(rule, SPR_option_func);
         if (func != NULL) {
            if (!func(answer_list, rule, option)) {
               answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                       ANSWER_QUALITY_ERROR, 
                                       MSG_SPOOL_SETOPTIONOFRULEFAILED_SS,
                                       lGetString(rule, SPR_name), 
                                       lGetString(context, SPC_name));
               ret = false;
               break;
            }
         }
      }
   }
char *qmonReadText(const char *filename, lList **alpp)
{
   char *text = NULL;
   SGE_STRUCT_STAT statb;
   FILE *fp = NULL;

   DENTER(GUI_LAYER, "qmonReadText");

   if (filename == NULL) {
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                              "No filename specified");
      DRETURN(NULL);
   }

   /* 
   ** make sure the file is a regular text file and open it 
   */
   if (SGE_STAT(filename, &statb) == -1 
       || (statb.st_mode & S_IFMT) != S_IFREG 
       || !(fp = fopen(filename, "r"))) {
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                      MSG_FILE_OPENFAILED_S, filename);
      DRETURN(NULL);
   }

   /* 
   ** put the contents of the file in the Text widget by allocating
   ** enough space for the entire file, reading the file into the
   ** allocated space, and using XmTextFieldSetString() to show the file.
   */
   if ((text = XtMalloc((unsigned)(statb.st_size + 1))) == NULL) {
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                              "%s", MSG_MEMORY_MALLOCFAILED);
      FCLOSE(fp);
      DRETURN(NULL);
   }

   if (!fread(text, sizeof (char), statb.st_size + 1, fp)) {
      answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                              MSG_FILE_FREADFAILED_SS, filename, strerror(errno));
   }

   text[statb.st_size] = 0; /* be sure to NULL-terminate */

   FCLOSE(fp);
   DRETURN(text);

FCLOSE_ERROR:
   XtFree(text);
   answer_list_add_sprintf(alpp, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                           MSG_FILE_NOCLOSE_SS, filename, strerror(errno));
   DRETURN(NULL);
}
Beispiel #4
0
static bool
sge_parse_from_file_qrstat(const char *file, lList **ppcmdline, lList **alpp)
{
   bool ret = true;

   DENTER(TOP_LAYER, "sge_parse_from_file_qrstat");

   if (ppcmdline == NULL) {
      ret = false;
   } else {
      if (!sge_is_file(file)) {
         /*
          * This is no error
          */
         DPRINTF(("file "SFQ" does not exist\n", file));
      } else {
         char *file_as_string = NULL;
         int file_as_string_length;

         file_as_string = sge_file2string(file, &file_as_string_length);
         if (file_as_string == NULL) {
            answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, 
                                    ANSWER_QUALITY_ERROR,
                                    MSG_ANSWER_ERRORREADINGFROMFILEX_S, file);
            ret = false;
         } else {
            char **token = NULL;

            token = stra_from_str(file_as_string, " \n\t");
            *alpp = cull_parse_cmdline(QRSTAT, token, environ, ppcmdline, FLG_USE_PSEUDOS);
         }
      }
   }  
   DRETURN(ret); 
}
/****** sge_cqueue_verify/cqueue_verify_memory_value() ****************************
*  NAME
*     cqueue_verify_memory_value() -- verify a queue memory attribute like h_vmem
*
*  SYNOPSIS
*     bool 
*     cqueue_verify_memory_value(lListElem *cqueue, lList **answer_list, 
*                             lListElem *attr_elem)
*
*  FUNCTION
*     Verifies if a memory attribute of a queue is in the expected range
*     (0 .. INFINITY) NONE is no allowed value.
*
*  INPUTS
*     lListElem *cqueue    - The queue to verify.
*     lList **answer_list  - answer list to report errors
*     lListElem *attr_elem - the attribute to verify
*
*  RESULT
*     bool - true on success, false on error
*
*  NOTES
*     MT-NOTE: cqueue_verify_memory_value() is MT safe 
*******************************************************************************/
bool
cqueue_verify_memory_value(lListElem *cqueue, lList **answer_list,
                       lListElem *attr_elem)
{
   bool ret = true;

   DENTER(CQUEUE_VERIFY_LAYER, "cqueue_verify_memory_value");
   if (cqueue != NULL && attr_elem != NULL) {
      const char *memory_string = lGetString(attr_elem, AMEM_value);

#if 1
      lListElem *copy = lCopyElem(attr_elem);
      if (!object_parse_field_from_string(copy, answer_list, AMEM_value, memory_string)) {
         ret = false;
      }
      lFreeElem(&copy);
#else
      if (memory_string == NULL || !strcasecmp(memory_string, "none")) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
                         MSG_NONE_NOT_ALLOWED_S, "memory values");
         ret = false;
      }
#endif      
   }
   DEXIT;
   return ret;
}
static bool
sge_gdi_task_verify(sge_gdi_task_class_t * task, lList **answer_list)
{
   bool ret = true;
#if 0
   int operation = 0;
   lList *list = NULL;
   u_long32 target = 0;
#endif

   DENTER(TOP_LAYER, "sge_gdi_task_verify");
#if 0
   operation = SGE_GDI_GET_OPERATION(task->command);
   list = task->data_list;
   target = task->target;
   /* EB: TODO: this check does not work for AR objects why? */
   if (!list
       && !(operation == SGE_GDI_PERMCHECK || operation == SGE_GDI_GET
            || operation == SGE_GDI_TRIGGER || (operation == SGE_GDI_DEL
                                                && target ==
                                                SGE_STN_LIST))
      ) {
      answer_list_add_sprintf(answer_list, STATUS_ESEMANTIC,
                 ANSWER_QUALITY_ERROR, MSG_GDI_GDI_VERIFY_REQUEST_FAILED);
      ret = false;
   }
#endif
   DRETURN(ret);
}
Beispiel #7
0
/****** sge_utility/verify_host_name() *****************************************
*  NAME
*     verify_host_name() -- verify a hostname
*
*  SYNOPSIS
*     bool 
*     verify_host_name(lList **answer_list, const char *host_name) 
*
*  FUNCTION
*     Verifies if a hostname is correct (regarding maximum length etc.).
*
*  INPUTS
*     lList **answer_list   - answer list to pass back error messages
*     const char *host_name - the hostname to verify
*
*  RESULT
*     bool - true on success,
*            false on error with error message in answer_list
*
*  NOTES
*     MT-NOTE: verify_host_name() is MT safe 
*******************************************************************************/
bool verify_host_name(lList **answer_list, const char *host_name)
{
   bool ret = true;

   if (host_name == NULL || *host_name == '\0') {
      answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, 
                              MSG_HOSTNAME_NOT_EMPTY);
      ret = false;
   }

   if (ret) {
      if (strlen(host_name) > CL_MAXHOSTNAMELEN_LENGTH) {
         answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, 
                                 MSG_HOSTNAME_NOT_EMPTY);
      }
   }

   /* TODO: further verification (e.g. character set) */

   return ret;
}
Beispiel #8
0
/*-----------------------------------------------------------
 * Error
 *    print simple error message
 *-----------------------------------------------------------*/
static int Error(s_token *token_p, int expected)
{
   DENTER(GUI_LAYER, "sge_eval_expression:Error");
   if (token_p->tt!=T_ERROR){
      answer_list_add_sprintf(token_p->answer_list, STATUS_ESYNTAX,
                              ANSWER_QUALITY_ERROR, MSG_EVAL_EXPRESSION_PARSE_ERROR,
                              token_p->s - token_p->expr , token_p->expr);
      ERROR((SGE_EVENT, MSG_EVAL_EXPRESSION_PARSE_ERROR, (int)(token_p->s - token_p->expr) , token_p->expr));
      token_p->et=expected;
      token_p->tt=T_ERROR;
   }
   DRETURN((-1)); /*negative return value is error index */
}
/****** gdi/request_internal/sge_gdi_packet_create_base() ********************
*  NAME
*     sge_gdi_packet_create_base() -- ???
*
*  SYNOPSIS
*     sge_gdi_packet_class_t *
*     sge_gdi_packet_create_base(lList **answer_list)
*
*  FUNCTION
*     Creates a new GDI packet and initializes all base structure memebers
*     where necessary information is available.
*
*     "uid", "gid", "user" and "group" memebers part of sge_gdi_packet_class_t
*     will not be initialized with this function. Instead
*     sge_gdi_packet_create() can be used or the function
*     sge_gdi_packet_initialize_auth_info() can be called afterwards.
*
*  INPUTS
*     lList **answer_list - answer list in case of error
*
*  RESULT
*     sge_gdi_packet_class_t * - new GDI packet
*
*  NOTES
*     MT-NOTE: sge_gdi_packet_create_base() is MT safe
*
*  SEE ALSO
*     gdi/request_internal/sge_gdi_packet_create()
*     gdi/request_internal/sge_gdi_packet_initialize_auth_info()
******************************************************************************/
sge_gdi_packet_class_t *
sge_gdi_packet_create_base(lList **answer_list)
{
   sge_gdi_packet_class_t *ret = NULL;

   DENTER(TOP_LAYER, "sge_gdi_packet_create_base");
   ret = (sge_gdi_packet_class_t *) sge_malloc(sizeof(sge_gdi_packet_class_t));
   if (ret != NULL) {
      int local_ret1;
      int local_ret2;

      local_ret1 = pthread_mutex_init(&(ret->mutex), NULL);
      local_ret2 = pthread_cond_init(&(ret->cond), NULL);
      if (local_ret1 == 0 && local_ret2 == 0) {
         ret->is_intern_request = false;
         ret->is_gdi_request = true;
         ret->is_handled = false;
         ret->id = 0;
         ret->host = NULL;
         ret->commproc = NULL;
         ret->commproc_id = 0;

         ret->version = GRM_GDI_VERSION;
         ret->first_task = NULL;
         ret->last_task = NULL;
         ret->auth_info = NULL;
         ret->next = NULL;
         memset(&(ret->pb), 0, sizeof(sge_pack_buffer));
      } else {
         answer_list_add_sprintf(answer_list, STATUS_EMALLOC,
                                 ANSWER_QUALITY_ERROR,
                                 MSG_MEMORY_MALLOCFAILED);
      }
   } else {
      answer_list_add_sprintf(answer_list, STATUS_EMALLOC,
                              ANSWER_QUALITY_ERROR, MSG_SGETEXT_NOMEM);
   }
   DRETURN(ret);
}
bool
binding_parse_from_string(lListElem *this_elem, lList **answer_list, dstring *string) 
{
   bool ret = true;

   DENTER(BINDING_LAYER, "binding_parse_from_string");

   if (this_elem != NULL && string != NULL) {
      int amount = 0;
      int stepsize = 0;
      int firstsocket = 0;
      int firstcore = 0;
      binding_type_t type = BINDING_TYPE_NONE; 
      dstring strategy = DSTRING_INIT;
      dstring socketcorelist = DSTRING_INIT;
      dstring error = DSTRING_INIT;

      if (parse_binding_parameter_string(sge_dstring_get_string(string), 
               &type, &strategy, &amount, &stepsize, &firstsocket, &firstcore, 
               &socketcorelist, &error) != true) {
         dstring parse_binding_error = DSTRING_INIT;

         sge_dstring_append_dstring(&parse_binding_error, &error);

         answer_list_add_sprintf(answer_list, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR,
                                 MSG_PARSE_XOPTIONWRONGARGUMENT_SS, "-binding",  
                                 sge_dstring_get_string(&parse_binding_error));

         sge_dstring_free(&parse_binding_error);
         ret = false;
      } else {
         lSetString(this_elem, BN_strategy, sge_dstring_get_string(&strategy));
         
         lSetUlong(this_elem, BN_type, type);
         lSetUlong(this_elem, BN_parameter_socket_offset, (firstsocket >= 0) ? firstsocket : 0);
         lSetUlong(this_elem, BN_parameter_core_offset, (firstcore >= 0) ? firstcore : 0);
         lSetUlong(this_elem, BN_parameter_n, (amount >= 0) ? amount : 0);
         lSetUlong(this_elem, BN_parameter_striding_step_size, (stepsize >= 0) ? stepsize : 0);
         
         if (strstr(sge_dstring_get_string(&strategy), "explicit") != NULL) {
            lSetString(this_elem, BN_parameter_explicit, sge_dstring_get_string(&socketcorelist));
         }
      }

      sge_dstring_free(&strategy);
      sge_dstring_free(&socketcorelist);
      sge_dstring_free(&error);
   }

   DRETURN(ret);
}
Beispiel #11
0
/**
* @brief remove potentially dangerous environment variables
*
* The function removes potentially dangerous environment variables from
* an environment list (e.g. from job or pe task submission).
* The following variables are removed:
*  - LD_PRELOAD
*  - all flavours of LD_LIBRARY_PATH, SHLIB_PATH etc.
*    unless qmaster param ENABLE_SUBMIT_LIB_PATH is set to TRUE
* We generate an INFO message to be output by the submit client.
*
* @param env_list       the environment list
* @param answer_list    answer_list to report removal of variables
*/
void var_list_filter_env_list(lList *env_list, lList **answer_list)
{
   lListElem *ep;

   /* LD_PRELOAD */
   ep = lGetElemStr(env_list, VA_variable, "LD_PRELOAD");
   if (ep != NULL) {
      lRemoveElem(env_list, &ep);
      answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_INFO,
                              MSG_REMOVED_ENV_VAR_S, "LD_PRELOAD");
   }

   /* other potentially dangerous variables */
   if (!mconf_get_enable_submit_lib_path()) {
      static const char *lib_path_names[] = {
         "LD_LIBRARY_PATH",
         "LD_LIBRARY_PATH_32",
         "LD_LIBRARY_PATH_64",
         "LIBPATH",
         "SHLIB_PATH",
         "DYLD_LIBRARY_PATH",
         "LD_ORIGIN_PATH",
         "LD_CONFIG",
         NULL
      };
      const char *var_name;
      int i;
      for (i = 0; (var_name = lib_path_names[i]) != NULL; i++) {
         ep = lGetElemStr(env_list, VA_variable, var_name);
         if (ep != NULL) {
            lRemoveElem(env_list, &ep);
            answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_INFO,
                                    MSG_REMOVED_ENV_VAR_S, var_name);
         }
      }
   }
}
Beispiel #12
0
/****** spool/spool_free_context() **************************************
*  NAME
*     spool_free_context() -- free resources of a spooling context
*
*  SYNOPSIS
*     lListElem* 
*     spool_free_context(lList **answer_list, lListElem *context) 
*
*  FUNCTION
*     Performs a shutdown of the spooling context and releases
*     all allocated resources.
*
*  INPUTS
*     lList **answer_list  - to return error messages
*     lListElem *context   - the context to free
*
*  RESULT
*     lListElem* - NULL
*
*  EXAMPLE
*     lListElem *context;
*     ...
*     context = spool_free_context(answer_list, context);
*
*  SEE ALSO
*     spool/--Spooling
*     spool/spool_create_context()
*     spool/spool_shutdown_context()
*******************************************************************************/
lListElem *
spool_free_context(lList **answer_list, lListElem *context)
{
   DENTER(TOP_LAYER, "spool_free_context");
   PROF_START_MEASUREMENT(SGE_PROF_SPOOLING);
  
   if (context == NULL) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, MSG_SPOOL_NOVALIDCONTEXT_S, 
                              SGE_FUNC);
   } else {
      spool_shutdown_context(answer_list, context);
      lFreeElem(&context);
   }

   PROF_STOP_MEASUREMENT(SGE_PROF_SPOOLING);
   DRETURN(context);
}
Beispiel #13
0
/****** spool/spool_create_context() ************************************
*  NAME
*     spool_create_context() -- create a new spooing context
*
*  SYNOPSIS
*     lListElem *
*     spool_create_context(lList **answer_list, const char *name);
*
*  FUNCTION
*     Create a new spooling context.
*
*  INPUTS
*     lList **answer_list  - to return error messages
*     const char *name     - name of the context
*
*  RESULT
*     lListElem* - the new spooling context
*
*  EXAMPLE
*     lListElem *context;
*     
*     context = spool_create_context(answer_list, "my spooling context");
*     ...
*
*
*  NOTES
*     Usually, a service function creating a spooling context
*     for a certain storage system will be called, e.g. 
*     spool_classic_create_context().
*
*  SEE ALSO
*     spool/--Spooling
*     spool/spool_free_context()
*     spool/classic/spool_classic_create_context()
*******************************************************************************/
lListElem *
spool_create_context(lList **answer_list, const char *name)
{
   lListElem *ep = NULL;

   DENTER(TOP_LAYER, "spool_create_context");
   PROF_START_MEASUREMENT(SGE_PROF_SPOOLING);

   if (name == NULL) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, MSG_SPOOL_CONTEXTNEEDSNAME);
   } else {
      ep = lCreateElem(SPC_Type);
      lSetString(ep, SPC_name, name);
   }

   PROF_STOP_MEASUREMENT(SGE_PROF_SPOOLING);
   DRETURN(ep);
}
/****** sge_cqueue_verify/cqueue_verify_time_value() ****************************
*  NAME
*     cqueue_verify_time_value() -- verify a queue time attribute like h_cpu
*
*  SYNOPSIS
*     bool 
*     cqueue_verify_time_value(lListElem *cqueue, lList **answer_list, 
*                             lListElem *attr_elem)
*
*  FUNCTION
*     Verifies if a time attribute of a queue is in the expected range
*     (0:0:0 .. INFINITY) NONE is no allowed value.
*
*  INPUTS
*     lListElem *cqueue    - The queue to verify.
*     lList **answer_list  - answer list to report errors
*     lListElem *attr_elem - the attribute to verify
*
*  RESULT
*     bool - true on success, false on error
*
*  NOTES
*     MT-NOTE: cqueue_verify_time_value() is MT safe 
*******************************************************************************/
bool
cqueue_verify_time_value(lListElem *cqueue, lList **answer_list,
                       lListElem *attr_elem)
{
   bool ret = true;

   DENTER(CQUEUE_VERIFY_LAYER, "cqueue_verify_time_value");
   if (cqueue != NULL && attr_elem != NULL) {
      const char *time_string = lGetString(attr_elem, ATIME_value);

      if (time_string == NULL || !strcasecmp(time_string, "none")) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
                         MSG_NONE_NOT_ALLOWED_S, "time values");
         ret = false;
      }
   }
   DEXIT;
   return ret;
}
/****** sge_cqueue_verify/cqueue_verify_job_slots() ****************************
*  NAME
*     cqueue_verify_job_slots() -- verify the queue slots attribute
*
*  SYNOPSIS
*     bool 
*     cqueue_verify_job_slots(lListElem *cqueue, lList **answer_list, 
*                             lListElem *attr_elem)
*
*  FUNCTION
*     Verifies if the slots attribute of a queue is in the expected range
*     (0 .. MAX_SEQNUM). MAX_SEQNUM is 9999999.
*
*  INPUTS
*     lListElem *cqueue    - The queue to verify.
*     lList **answer_list  - answer list to report errors
*     lListElem *attr_elem - the attribute to verify
*
*  RESULT
*     bool - true on success, false on error
*
*  NOTES
*     MT-NOTE: cqueue_verify_job_slots() is MT safe 
*******************************************************************************/
bool 
cqueue_verify_job_slots(lListElem *cqueue, lList **answer_list, lListElem *attr_elem)
{
   bool ret = true;

   DENTER(CQUEUE_VERIFY_LAYER, "cqueue_verify_job_slots");
   if (cqueue != NULL && attr_elem != NULL) {
      u_long32 slots = lGetUlong(attr_elem, AULNG_value);

      if (slots > MAX_SEQNUM) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR,
                                 MSG_ATTR_INVALID_ULONGVALUE_USUU, sge_u32c(slots), "slots",
                                 sge_u32c(0), sge_u32c(MAX_SEQNUM));
         ret = false;
      }
   }

   DEXIT;
   return ret;
}
Beispiel #16
0
/****** sge_var/var_list_verify() **********************************************
*  NAME
*     var_list_verify() -- verify contents of a variable list
*
*  SYNOPSIS
*     bool 
*     var_list_verify(const lList *lp, lList **answer_list) 
*
*  FUNCTION
*     Verifies the contents of a variable list.
*     Variable names may not be NULL or empty strings.
*
*  INPUTS
*     const lList *lp     - the list to verify
*     lList **answer_list - answer list to pass back error messages
*
*  RESULT
*     bool - true on success, 
*            false in case of errors, error message in answer_list
*
*  NOTES
*     MT-NOTE: var_list_verify() is MT safe 
*******************************************************************************/
bool 
var_list_verify(const lList *lp, lList **answer_list)
{
   bool ret = true;
   lListElem *ep;

   for_each (ep, lp) {
      const char *variable = lGetString(ep, VA_variable);
      if (variable == NULL || variable[0] == '\0') {
         answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR, 
                                 MSG_OBJECT_VARIABLENAME_NOT_EMPTY);
         ret = false;
         break;
      }
   }

   /* TODO: further checks, e.g. length, format strings */

   return ret;
}
Beispiel #17
0
bool
switch_list_qstat_parse_from_file(lList **switch_list, lList **answer_list,
                                  int mode, const char *file)
{
   bool ret = true;

   DENTER(TOP_LAYER, "switch_list_qstat_parse_from_file");
   if (switch_list == NULL) {
      ret = false;
   } else {
      if (!sge_is_file(file)) {
         /*
          * This is no error
          */
         DPRINTF(("file "SFQ" does not exist\n", file));
         ret = true;
      } else {
         char *file_as_string = NULL;
         int file_as_string_length;

         file_as_string = sge_file2string(file, &file_as_string_length);
         if (file_as_string == NULL) {
            answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                    ANSWER_QUALITY_ERROR,
                                    MSG_ANSWER_ERRORREADINGFROMFILEX_S, file);
            ret = false;
         } else {
            char **token = NULL;

            token = stra_from_str(file_as_string, " \n\t");
            ret = switch_list_qstat_parse_from_cmdline(switch_list, answer_list,
                                                       mode, token);
            sge_strafree(&token);
         }
         sge_free(&file_as_string);
      }
   }  
   DRETURN(ret); 
}
/****** qmaster/ckpt/ckpt_spool() *********************************************
*
*  NAME
*     ckpt_spool -- spool a ckpt object  
*
*  SYNOPSIS
*     int ckpt_spool(lList **alpp, lListElem *ep, gdi_object_t *object);
*
*  FUNCTION
*     This function will be called from the framework which will
*     add/modify/delete generic gdi objects.
*     After an object was modified/added successfully it
*     is necessary to spool the current state to the filesystem.
*
*
*  INPUTS
*     alpp        - reference to an answer list.
*     ep          - ckpt object which should be spooled
*     object      - structure of the gdi framework which contains 
*                   additional information to perform the request
*                   (function pointers, names, CULL-types) 
*
*  RESULT
*     [alpp] - error messages will be added to this list
*     0 - success
*     STATUS_EEXIST - an error occured
******************************************************************************/
int ckpt_spool(sge_gdi_ctx_class_t *ctx, lList **alpp, lListElem *ep, gdi_object_t *object) 
{  
   lList *answer_list = NULL;
   bool dbret;
   bool job_spooling = ctx->get_job_spooling(ctx);

   DENTER(TOP_LAYER, "ckpt_spool");

   dbret = spool_write_object(&answer_list, spool_get_default_context(), ep, 
                              lGetString(ep, CK_name), SGE_TYPE_CKPT,
                              job_spooling);
   answer_list_output(&answer_list);

   if (!dbret) {
      answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_PERSISTENCE_WRITE_FAILED_S,
                              lGetString(ep, CK_name));
   }

   DEXIT;
   return dbret ? 0 : 1;
}
Beispiel #19
0
static bool 
sge_parse_qrstat(sge_gdi_ctx_class_t *ctx, lList **answer_list,
                 qrstat_env_t *qrstat_env, lList **cmdline)
{
   bool ret = true;
   
   DENTER(TOP_LAYER, "sge_parse_qrstat");

   qrstat_env->is_summary = true;
   while (lGetNumberOfElem(*cmdline)) {
      u_long32 value;
   
      /* -help */
      if (opt_list_has_X(*cmdline, "-help")) {
         sge_usage(QRSTAT, stdout);
         DEXIT;
         SGE_EXIT((void**)&ctx, 0);
      }

      /* -u */
      while (parse_multi_stringlist(cmdline, "-u", answer_list, 
                                    &(qrstat_env->user_list), ST_Type, ST_name)) {
         continue;
      }

      /* -explain */
      while (parse_flag(cmdline, "-explain", answer_list, &value)) {
         qrstat_filter_add_core_attributes(qrstat_env);
         qrstat_filter_add_explain_attributes(qrstat_env);
         qrstat_env->is_explain = (value > 0) ? true : false;
         continue;
      }

      /* -xml */
      while (parse_flag(cmdline, "-xml", answer_list, &value)) {
         qrstat_filter_add_core_attributes(qrstat_env);
         qrstat_filter_add_xml_attributes(qrstat_env);
         qrstat_env->is_xml = (value > 0) ? true : false;
         continue;
      }

      /* -ar */
      while (parse_u_longlist(cmdline, "-ar", answer_list, &(qrstat_env->ar_id_list))) {         
         qrstat_filter_add_core_attributes(qrstat_env);
         qrstat_filter_add_ar_attributes(qrstat_env);
         qrstat_filter_add_ar_where(qrstat_env);
         qrstat_env->is_summary = false;
         continue;      
      }

      if (lGetNumberOfElem(*cmdline)) {
         sge_usage(QRSTAT, stdout);
         answer_list_add(answer_list, MSG_PARSE_TOOMANYOPTIONS, 
                         STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR);
         ret = false;
         break;
      }
   } 

   if (qrstat_env->is_summary) {
      char user[128] = "";
      if (sge_uid2user(geteuid(), user, sizeof(user), MAX_NIS_RETRIES)) {
         answer_list_add_sprintf(answer_list, STATUS_ESEMANTIC,
                                 ANSWER_QUALITY_CRITICAL,
                                 MSG_SYSTEM_RESOLVEUSER_U, (u_long32)geteuid());
         ret = false;
      } else {
         str_list_transform_user_list(&(qrstat_env->user_list), answer_list, user);
         qrstat_filter_add_core_attributes(qrstat_env);
         qrstat_filter_add_u_where(qrstat_env);
      }
   }

   DRETURN(ret);
}
static sge_gdi_task_class_t *
sge_gdi_task_create(sge_gdi_packet_class_t * packet, lList **answer_list,
                    u_long32 target, u_long32 command, lList **lp,
                    lList **a_list, lCondition **condition,
                    lEnumeration **enumeration, bool do_copy, bool do_verify)
{
   sge_gdi_task_class_t *task = NULL;

   DENTER(TOP_LAYER, "sge_gdi_task_create");

   task = (sge_gdi_task_class_t *) sge_malloc(sizeof(sge_gdi_task_class_t));
   if (task != NULL) {
      task->id =
         ((packet->last_task != NULL) ? (packet->last_task->id + 1) : 1);
      task->command = command;
      task->target = target;
      task->next = NULL;
      task->do_select_pack_simultaneous = false;
      if (do_copy) {
         if (enumeration != NULL && *enumeration != NULL) {
            task->data_list = (((lp != NULL) && (*lp != NULL)) ?
                               lSelect("", *lp, NULL, *enumeration) : NULL);
         } else {
            task->data_list = (((lp != NULL) && (*lp != NULL)) ?
                               lCopyList("", *lp) : NULL);
         }
         task->answer_list = (((a_list != NULL) && (*a_list != NULL)) ?
                              lCopyList("", *a_list) : NULL);
         task->condition = (((condition != NULL) && (*condition != NULL)) ?
                            lCopyWhere(*condition) : NULL);
         task->enumeration = (((enumeration != NULL) && (*enumeration != NULL)) ?
                              lCopyWhat(*enumeration) : NULL);
      } else {
         if ((lp != NULL) && (*lp != NULL)) {
            task->data_list = *lp;
            *lp = NULL;
         } else {
            task->data_list = NULL;
         }
         if ((a_list != NULL) && (*a_list != NULL)) {
            task->answer_list = *a_list;
            *a_list = NULL;
         } else {
            task->answer_list = NULL;
         }
         if ((condition != NULL) && (*condition != NULL)) {
            task->condition = *condition;
            *condition = NULL;
         } else {
            task->condition = NULL;
         }
         if ((enumeration != NULL) && (*enumeration != NULL)) {
            task->enumeration = *enumeration;
            *enumeration = NULL;
         } else {
            task->enumeration = NULL;
         }
      }
      if (do_verify && !sge_gdi_task_verify(task, answer_list)) {
         if (do_copy == true) {
            lFreeList(&(task->data_list));
            lFreeList(&(task->answer_list));
            lFreeWhere(&(task->condition));
            lFreeWhat(&(task->enumeration));
         } else {
            task->data_list = NULL;
            task->answer_list = NULL;
            task->condition = NULL;
            task->enumeration = NULL;
         }
         sge_gdi_task_free(&task);
      }
   } else {
      answer_list_add_sprintf(answer_list, STATUS_EMALLOC,
                              ANSWER_QUALITY_ERROR, MSG_MEMORY_MALLOCFAILED);
   }
   DRETURN(task);
}
/****** spool/spool_create_dynamic_context() *********************
*  NAME
*     spool_create_dynamic_context() -- create a spooling context
*
*  SYNOPSIS
*     lListElem * 
*     spool_create_dynamic_context(lList **answer_list, 
*                                  const char *shlib_name, const char *args) 
*
*  FUNCTION
*     Create a spooling context.
*     Which spooling context to use can either be defined at compile time, e.g. 
*     by calling "aimk -spool-classic" or "aimk -spool-flatfile".
*
*     Or dynamic loading of a spooling framework is activated (by building
*     with "aimk -spool-dynamic".
*     In this case a shared library is dynamically loaded and the spooling
*     framework implementation of that shared library is used.
*
*  INPUTS
*     lList **answer_list    - to return error messages
*     const char *shlib_name - name of a shared lib
*     const char *args       - arguments to be passed to the initialization
*                              function in the specified shared lib.
*
*  RESULT
*     lListElem * - on success a spooling context, else NULL.
*
*  SEE ALSO
*     spool/--Spooling
*******************************************************************************/
lListElem *
spool_create_dynamic_context(lList **answer_list, const char *method,
                             const char *shlib_name, const char *args)
{
   const char *compiled_method;
   lListElem *context = NULL;

   DENTER(TOP_LAYER, "spool_create_dynamic_context");

#ifdef SPOOLING_berkeleydb
   compiled_method = "berkeleydb";
   if (strcmp(method, compiled_method) != 0) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_SPOOL_COMPILEDMETHODNECONFIGURED_SS,
                              compiled_method, method);
   } else {
      context = spool_berkeleydb_create_context(answer_list, args);
   }
#endif
#ifdef SPOOLING_classic
   compiled_method = "classic";
   if (strcmp(method, compiled_method) != 0) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_SPOOL_COMPILEDMETHODNECONFIGURED_SS,
                              compiled_method, method);
   } else {
      context = spool_classic_create_context(answer_list, args);
   }
#endif
#ifdef SPOOLING_flatfile
   compiled_method = "flatfile";
   if (strcmp(method, compiled_method) != 0) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_SPOOL_COMPILEDMETHODNECONFIGURED_SS,
                              compiled_method, method);
   } else {
      context = spool_flatfile_create_context(answer_list, args);
   }
#endif
#ifdef SPOOLING_postgres
   compiled_method = "postgres";
   if (strcmp(method, compiled_method) != 0) { 
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_SPOOL_COMPILEDMETHODNECONFIGURED_SS,
                              compiled_method, method);
   } else {
      context = spool_postgres_create_context(answer_list, args);
   }
#endif
#ifdef SPOOLING_dynamic
   /* 
    * don't need compiled_method here, but otherwise we get an
    * unused variable compiler warning. And we need the DPRINTF
    * on irix6, otherwise we get a set but not used warning.
    */
   compiled_method = "dynamic";
   DPRINTF(("creating "SFQ" spooling context\n", compiled_method));
   context = spool_dynamic_create_context(answer_list, method, shlib_name, 
                                          args);
#endif

   if (context == NULL) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_SPOOL_ERRORCREATINGCONTEXT_S, 
                              method);
   }

   DEXIT;
   return context;
}
/****** spool/utilities/spool_default_validate_func() ****************
*  NAME
*     spool_default_validate_func() -- validate objects
*
*  SYNOPSIS
*     bool
*     spool_default_validate_func(lList **answer_list, 
*                               const lListElem *type, 
*                               const lListElem *rule, 
*                               const lListElem *object, 
*                               const char *key, 
*                               const sge_object_type object_type) 
*
*  FUNCTION
*     Verifies an object.
*
*  INPUTS
*     lList **answer_list - to return error messages
*     const lListElem *type           - object type description
*     const lListElem *rule           - rule to use
*     const lListElem *object         - object to validate
*     const sge_object_type object_type - object type
*
*  RESULT
*     bool - true on success, else false
*
*  NOTES
*     This function should not be called directly, it is called by the
*     spooling framework.
*
*  SEE ALSO
*******************************************************************************/
bool spool_default_validate_func(lList **answer_list, 
                          const lListElem *type, 
                          const lListElem *rule,
                          lListElem *object,
                          const sge_object_type object_type)
{
   bool ret = true;

   DENTER(TOP_LAYER, "spool_default_validate_func");

   switch(object_type) {
      case SGE_TYPE_ADMINHOST:
      case SGE_TYPE_EXECHOST:
      case SGE_TYPE_SUBMITHOST:
         {
            int cl_ret;
            int key_nm = object_type_get_key_nm(object_type);
            char *old_name = strdup(lGetHost(object, key_nm));

            /* try hostname resolving */
            if (strcmp(old_name, SGE_GLOBAL_NAME) != 0) {
               cl_ret = sge_resolve_host(object, key_nm);

               /* if hostname resolving failed: create error */
               if (cl_ret != CL_RETVAL_OK) {
                  if (cl_ret != CL_RETVAL_GETHOSTNAME_ERROR) {
                     answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                             ANSWER_QUALITY_ERROR, 
                                             MSG_SPOOL_CANTRESOLVEHOSTNAME_SS, 
                                             old_name, cl_get_error_text(ret)); 
                     ret = false;
                  } else {
                     answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                             ANSWER_QUALITY_WARNING, 
                                             MSG_SPOOL_CANTRESOLVEHOSTNAME_SS, 
                                             old_name, cl_get_error_text(ret));
                  }
               } else {
                  /* if hostname resolving changed hostname: spool */
                  const char *new_name;
                  new_name = lGetHost(object, key_nm);
                  if (strcmp(old_name, new_name) != 0) {
                     spooling_write_func write_func = 
                             (spooling_write_func)lGetRef(rule, SPR_write_func);
                     spooling_delete_func delete_func = 
                             (spooling_delete_func)lGetRef(rule, SPR_delete_func);
                     write_func(answer_list, type, rule, object, new_name, 
                                object_type);
                     delete_func(answer_list, type, rule, old_name, object_type);
                  }
               }
            }

            sge_free(&old_name);

            if (object_type == SGE_TYPE_EXECHOST && ret) {
               lListElem *load_value;
               lList *master_centry_list = *object_type_get_master_list(SGE_TYPE_CENTRY);

               /* all spooled load values are static, therefore we tag them here */
               for_each(load_value, lGetList(object, EH_load_list)) {
                  lSetBool(load_value, HL_static, true);
               }

               /* necessary to init double values of consumable configuration */
               centry_list_fill_request(lGetList(object, EH_consumable_config_list), 
                     NULL, master_centry_list, true, false, true);
               /* necessary to setup actual list of exechost */
               debit_host_consumable(NULL, object, master_centry_list, 0, true, NULL);

               if (ensure_attrib_available(NULL, object, 
                                           EH_consumable_config_list)) {
                  ret = false;
               }
            }
         }
static spooling_field *
_spool_get_fields_to_spool(lList **answer_list, const lDescr *descr, 
                           const spool_instr *instr)
{
   spooling_field *fields;
   int i, j, size;
   int strip = 0;

   DENTER(TOP_LAYER, "_spool_get_fields_to_spool");

   /* we don't check descr and instr, as we know they are ok
    * (it's a static function)
    */

   /* count fields to spool */
   for (i = 0, size = 0; mt_get_type(descr[i].mt) != lEndT; i++) {
      if ((descr[i].mt & instr->selection) != 0) {
         size++;
      }
   }

   /* allocate memory */
   fields = (spooling_field *)malloc((size + 1) * sizeof(spooling_field));
   if (fields == NULL) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_UNABLETOALLOCATEBYTES_DS, 
                              (size * 1) * sizeof(spooling_field), SGE_FUNC);
      DRETURN(NULL);
   }

   /* initialize fields */
   for (i = 0; i < size; i++) {
      fields[i].nm         = NoName;
      fields[i].width      = 0;
      fields[i].name       = NULL;
      fields[i].sub_fields = NULL;
      fields[i].clientdata = NULL;
      fields[i].read_func  = NULL;
      fields[i].write_func = NULL;
   }

   /* do we have to strip field prefixes, e.g. "QU_" from field names? */
   if (instr->copy_field_names && instr->strip_field_prefix) {
      dstring buffer = DSTRING_INIT;
      const char *prefix = object_get_name_prefix(descr, &buffer);
      strip = sge_strlen(prefix);
      sge_dstring_free(&buffer);
   }

   /* copy field info */
   for (i = 0, j = 0; mt_get_type(descr[i].mt) != lEndT; i++) {
      if ((descr[i].mt & instr->selection) != 0) {
         spooling_field *sub_fields = NULL;

         DPRINTF(("field "SFQ" will be spooled\n", lNm2Str(descr[i].nm)));

         fields[j].nm         = descr[i].nm;

         if (instr->copy_field_names) {
            const char *name;
            name = lNm2Str(descr[i].nm);
            if(name == NULL || strlen(name) <= strip) {
               answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                       ANSWER_QUALITY_ERROR, 
                                       MSG_NONAMEFORATTRIBUTE_D, 
                                       descr[i].nm);
               fields = spool_free_spooling_fields(fields);
               DEXIT;
               return NULL;
            }
            fields[j].name = strdup(name + strip);
         }
         
         if (mt_get_type(descr[i].mt) == lListT) {
            const lDescr *sub_descr;

            if (instr->sub_instr == NULL) {
               answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                       ANSWER_QUALITY_ERROR,
                                       MSG_DONTKNOWHOWTOSPOOLSUBLIST_SS,
                                       lNm2Str(descr[i].nm), SGE_FUNC);
               fields = spool_free_spooling_fields(fields);
               DEXIT;
               return NULL;
            }

            sub_descr = object_get_subtype(descr[i].nm);
            if (sub_descr == NULL) {
               answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                       ANSWER_QUALITY_ERROR,
                                       MSG_UNKNOWNOBJECTTYPEFOR_SS,
                                       lNm2Str(descr[i].nm), SGE_FUNC);
               fields = spool_free_spooling_fields(fields);
               DEXIT;
               return NULL;
            }

            /* recursive spooling, e.g. sharetree */
            if (instr->sub_instr == instr && descr == sub_descr) {
               sub_fields = fields;
               DPRINTF(("recursive structure detected for field %s\n",
                        lNm2Str(descr[i].nm)));
            } else {
               sub_fields = _spool_get_fields_to_spool(answer_list, sub_descr, 
                                                       instr->sub_instr);
            }
         }

         fields[j++].sub_fields = sub_fields;
      }
   }

   /* end of field array */
   fields[j].nm = NoName;

   DEXIT;
   return fields;
}
Beispiel #24
0
bool sge_parse_qrsub(sge_gdi_ctx_class_t *ctx, lList *pcmdline, lList **alpp, lListElem **ar)
{
   lListElem *ep = NULL, *next_ep = NULL;
   lList *lp = NULL;
   DENTER(TOP_LAYER, "sge_parse_qrsub");

   /*  -help 	 print this help */
   if ((ep = lGetElemStr(pcmdline, SPA_switch, "-help"))) {
      lRemoveElem(pcmdline, &ep);
      sge_usage(QRSUB, stdout);
      DEXIT;
      SGE_EXIT((void **)&ctx, 0);
   }

   /*  -a date_time 	 start time in [[CC]YY]MMDDhhmm[.SS] SGE_ULONG */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-a"))) {
      lSetUlong(*ar, AR_start_time, lGetUlong(ep, SPA_argval_lUlongT));
      lRemoveElem(pcmdline, &ep);
   }

   /*  -e date_time 	 end time in [[CC]YY]MMDDhhmm[.SS] SGE_ULONG*/
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-e"))) {
      lSetUlong(*ar, AR_end_time, lGetUlong(ep, SPA_argval_lUlongT));
      lRemoveElem(pcmdline, &ep);
   }

   /*  -d time 	 duration in TIME format SGE_ULONG */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-d"))) {
      lSetUlong(*ar, AR_duration, lGetUlong(ep, SPA_argval_lUlongT));
      lRemoveElem(pcmdline, &ep);
   }
   
   /*  -w e/v 	 validate availability of AR request, default e SGE_ULONG */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-w"))) {
      lSetUlong(*ar, AR_verify, lGetInt(ep, SPA_argval_lIntT));
      lRemoveElem(pcmdline, &ep);
   }
  
   /*  -N name 	 AR name SGE_STRING */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-N"))) {
      lSetString(*ar, AR_name, lGetString(ep, SPA_argval_lStringT));
      lRemoveElem(pcmdline, &ep);
   }
      
   /*  -A account_string 	 AR name in accounting record SGE_STRING */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-A"))) {
      lSetString(*ar, AR_account, lGetString(ep, SPA_argval_lStringT));
      lRemoveElem(pcmdline, &ep);
   }
     
   /*  -l resource_list 	 request the given resources  SGE_LIST */
   parse_list_simple(pcmdline, "-l", *ar, AR_resource_list, 0, 0, FLG_LIST_APPEND);
   centry_list_remove_duplicates(lGetList(*ar, AR_resource_list));

   /*  -u wc_user 	       access list SGE_LIST */
   /*  -u ! wc_user TBD: Think about eval_expression support in compare allowed and excluded lists */
   parse_list_simple(pcmdline, "-u", *ar, AR_acl_list, ARA_name, 0, FLG_LIST_MERGE);
   /*  -u ! list separation */
   lp = lGetList(*ar,  AR_acl_list);
   next_ep = lFirst(lp);
   while ((ep = next_ep)) {
      bool is_xacl = false;
      const char *name = lGetString(ep, ARA_name);

      next_ep = lNext(ep);
      if (name[0] == '!') { /* move this element to xacl_list */
         is_xacl = true;
         name++;
      }

      if (!is_hgroup_name(name)) {
         struct passwd *pw;
         struct passwd pw_struct;
         char *buffer;
         int size;
         stringT group;

         size = get_pw_buffer_size();
         buffer = sge_malloc(size);
         pw = sge_getpwnam_r(name, &pw_struct, buffer, size);
         
         if (pw == NULL) {
           answer_list_add_sprintf(alpp, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR, MSG_USER_XISNOKNOWNUSER_S, name);
           FREE(buffer);
           DRETURN(false);
         }
         sge_gid2group(pw->pw_gid, group, MAX_STRING_SIZE, MAX_NIS_RETRIES);
         lSetString(ep, ARA_group, group);
         FREE(buffer);
      }

      if (is_xacl) {
         lListElem *new_ep = lAddSubStr(*ar, ARA_name, name, AR_xacl_list, ARA_Type);
         lSetString(new_ep, ARA_group, lGetString(ep, ARA_group));
         lRemoveElem(lp, &ep);
      }

   }

   /*  -q wc_queue_list 	 reserve in queue(s) SGE_LIST */
   parse_list_simple(pcmdline, "-q", *ar, AR_queue_list, 0, 0, FLG_LIST_APPEND);

  /*    -pe pe_name slot_range reserve slot range for parallel jobs */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-pe"))) {
      lSetString(*ar, AR_pe, lGetString(ep, SPA_argval_lStringT)); /* SGE_STRING, */
      lSwapList(*ar, AR_pe_range, ep, SPA_argval_lListT);       /* SGE_LIST */
      lRemoveElem(pcmdline, &ep);
   }
   /*   AR_master_queue_list  -masterq wc_queue_list, SGE_LIST bind master task to queue(s) */
   parse_list_simple(pcmdline, "-masterq", *ar, AR_master_queue_list, 0, 0, FLG_LIST_APPEND);

   /*  -ckpt ckpt-name 	 reserve in queue with ckpt method SGE_STRING */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-ckpt"))) {
      lSetString(*ar, AR_checkpoint_name, lGetString(ep, SPA_argval_lStringT));
      lRemoveElem(pcmdline, &ep);
   }
   
   /*  -m b/e/a/n 	 define mail notification events SGE_ULONG */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-m"))) {
      u_long32 ul;
      u_long32 old_mail_opts;

      ul = lGetInt(ep, SPA_argval_lIntT);
      if  ((ul & NO_MAIL)) {
         lSetUlong(*ar, AR_mail_options, 0);
      } else {
         old_mail_opts = lGetUlong(*ar, AR_mail_options);
         lSetUlong(*ar, AR_mail_options, ul | old_mail_opts);
      }
      lRemoveElem(pcmdline, &ep);
   }

   /*   -M user[@host],... 	 notify these e-mail addresses SGE_LIST*/
   parse_list_simple(pcmdline, "-M", *ar, AR_mail_list, MR_host, MR_user, FLG_LIST_MERGE);

   /*  -he yes/no 	 hard error handling SGE_ULONG */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-he"))) {
      lSetUlong(*ar, AR_error_handling, lGetUlong(ep, SPA_argval_lUlongT));
      lRemoveElem(pcmdline, &ep);
   }

   /*   -now 	 reserve in queues with qtype interactive  SGE_ULONG */
   while ((ep = lGetElemStr(pcmdline, SPA_switch, "-now"))) {
      u_long32 ar_now = lGetUlong(*ar, AR_type);
      if(lGetInt(ep, SPA_argval_lIntT)) {
         JOB_TYPE_SET_IMMEDIATE(ar_now);
      } else {
         JOB_TYPE_CLEAR_IMMEDIATE(ar_now);
      }

      lSetUlong(*ar, AR_type, ar_now);

      lRemoveElem(pcmdline, &ep);
   }

  /* Remove the script elements. They are not stored in the ar structure */
  if ((ep = lGetElemStr(pcmdline, SPA_switch, STR_PSEUDO_SCRIPT))) {
      lRemoveElem(pcmdline, &ep);
   }

   if ((ep = lGetElemStr(pcmdline, SPA_switch, STR_PSEUDO_SCRIPTLEN))) {
      lRemoveElem(pcmdline, &ep);
   }

   if ((ep = lGetElemStr(pcmdline, SPA_switch, STR_PSEUDO_SCRIPTPTR))) {
      lRemoveElem(pcmdline, &ep);
   }

   ep = lFirst(pcmdline);   
   if(ep) {
      const char *option = lGetString(ep,SPA_switch);
      /* as jobarg are stored no switch values, need to be filtered */ 
      if(sge_strnullcmp(option, "jobarg") != 0) {
         answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR,
                              MSG_PARSE_INVALIDOPTIONARGUMENTX_S,
                              lGetString(ep,SPA_switch)); 
      } else {
         answer_list_add_sprintf(alpp, STATUS_ESEMANTIC, ANSWER_QUALITY_ERROR,
                              MSG_PARSE_INVALIDOPTIONARGUMENT);
       }
      DRETURN(false);
   }

   if (lGetUlong(*ar, AR_start_time) == 0 && lGetUlong(*ar, AR_end_time) != 0 && lGetUlong(*ar, AR_duration) != 0) {
      lSetUlong(*ar, AR_start_time, lGetUlong(*ar, AR_end_time) - lGetUlong(*ar, AR_duration));
   } else if (lGetUlong(*ar, AR_start_time) != 0 && lGetUlong(*ar, AR_end_time) == 0 && lGetUlong(*ar, AR_duration) != 0) {
      lSetUlong(*ar, AR_end_time, duration_add_offset(lGetUlong(*ar, AR_start_time), lGetUlong(*ar, AR_duration)));
      lSetUlong(*ar, AR_duration, lGetUlong(*ar, AR_end_time) - lGetUlong(*ar, AR_start_time));
   } else if (lGetUlong(*ar, AR_start_time) != 0 && lGetUlong(*ar, AR_end_time) != 0 && lGetUlong(*ar, AR_duration) == 0) {
      lSetUlong(*ar, AR_duration, lGetUlong(*ar, AR_end_time) - lGetUlong(*ar, AR_start_time));
   }

   DRETURN(true);
}
Beispiel #25
0
lList *cull_unparse_job_parameter(sge_gdi_ctx_class_t *ctx, lList **pcmdline, lListElem *job, int flags)
{
    const char *cp;
    u_long32 ul;
    lList *answer = NULL;
    char str[MAX_STRING_SIZE];
    lList *lp;
    int ret;
    lListElem *ep_opt;
    const char *username = ctx->get_username(ctx);
    const char *qualified_hostname = ctx->get_qualified_hostname(ctx);

    DENTER(TOP_LAYER, "cull_unparse_job_parameter");

    /*
    ** -a
    ** problem with submission time, but that is not a good
    ** default option anyway, is not unparsed
    */

    /*
    ** -A
    */
    if (sge_unparse_account_string(job, pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }

    /*
    ** -c
    */
    if (sge_unparse_checkpoint_option(job, pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }

    /*
     * -ckpt
     */
    if (sge_unparse_string_option(job, JB_checkpoint_name, "-ckpt",
                                  pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }


    /*
    ** -cwd
    */
    if (lGetString(job, JB_cwd)) {
        ep_opt = sge_add_noarg(pcmdline, cwd_OPT, "-cwd", NULL);
    }

    /*
     * -P
     */
    if (sge_unparse_string_option(job, JB_project, "-P",
                                  pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }

#if 0
    /*
    ** -C
    */
    if (sge_unparse_string_option(job, JB_directive_prefix, "-C",
                                  pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }
#endif

    /*
    ** -e
    */
    if (sge_unparse_path_list(job, JB_stderr_path_list, "-e", pcmdline,
                              &answer) != 0) {
        DEXIT;
        return answer;
    }

    /*
    ** -h, here only user hold supported at the moment
    */
    if  ((ul = lGetUlong(lFirst(lGetList(job, JB_ja_tasks)), JAT_hold))) {
        ep_opt = sge_add_noarg(pcmdline, h_OPT, "-h", NULL);
    }

    /*
    ** -hold_jid
    */
    if ((lp = lGetList(job, JB_jid_request_list))) {
        int fields[] = { JRE_job_name, 0 };
        const char *delis[] = {NULL, ",", NULL};

        ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 0);
        if (ret) {
            DPRINTF(("Error %d formatting jid_request_list as -hold_jid\n", ret));
            answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                    MSG_LIST_ERRORFORMATINGJIDPREDECESSORLISTASHOLDJID);
            return answer;
        }
        ep_opt = sge_add_arg(pcmdline, hold_jid_OPT, lListT, "-hold_jid", str);
        lSetList(ep_opt, SPA_argval_lListT, lCopyList("hold_jid list", lp));
    }

    /*
    ** -hold_jid_ad
    */
    if ((lp = lGetList(job, JB_ja_ad_request_list))) {
        int fields[] = { JRE_job_name, 0 };
        const char *delis[] = {NULL, ",", NULL};

        ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis, 0);
        if (ret) {
            DPRINTF(("Error %d formatting ja_ad_request_list as -hold_jid_ad\n", ret));
            answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                    MSG_LIST_ERRORFORMATINGJIDPREDECESSORLISTASHOLDJIDAD);
            return answer;
        }
        ep_opt = sge_add_arg(pcmdline, hold_jid_ad_OPT, lListT, "-hold_jid_ad", str);
        lSetList(ep_opt, SPA_argval_lListT, lCopyList("hold_jid_ad list", lp));
    }

    /*
    ** -i
    */
    if (sge_unparse_path_list(job, JB_stdin_path_list, "-i", pcmdline,
                              &answer) != 0) {
        DEXIT;
        return answer;
    }

    /*
    ** -j
    */
    if ((ul = lGetBool(job, JB_merge_stderr))) {
        ep_opt = sge_add_arg(pcmdline, j_OPT, lIntT, "-j", "y");
        lSetInt(ep_opt, SPA_argval_lIntT, true);
    }

    /*
    ** -jid
    */
    if ((lp = lGetList(job, JB_job_identifier_list))) {
        int fields[] = { JRE_job_number, 0};
        const char *delis[] = {"", ",", NULL};

        ret = uni_print_list(NULL, str, sizeof(str) - 1, lp, fields, delis,
                             0);
        if (ret) {
            DPRINTF(("Error %d formatting job_identifier_list as -jid\n", ret));
            answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                    MSG_LIST_ERRORFORMATINGJOBIDENTIFIERLISTASJID);
            DRETURN(answer);
        }
        ep_opt = sge_add_arg(pcmdline, jid_OPT, lListT, "-jid", str);
        lSetList(ep_opt, SPA_argval_lListT, lCopyList("jid list", lp));
    }

    /*
    ** -js
    */
    if ((ul = lGetUlong(job, JB_jobshare)) != 0)  {
        sprintf(str, sge_u32, ul);
        ep_opt = sge_add_arg(pcmdline, js_OPT, lUlongT, "-js", str);
        lSetUlong(ep_opt, SPA_argval_lUlongT, ul);
    }

    /*
    ** -lj is in parsing but can't be unparsed here
    */

    /*
    ** -l
    */
    if (sge_unparse_resource_list(job, JB_hard_resource_list,
                                  pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }
    if (sge_unparse_resource_list(job, JB_soft_resource_list,
                                  pcmdline, &answer) != 0) {
        DEXIT;
        return answer;
    }






    /*
    ** -m
    */
    if ((ul = lGetUlong(job, JB_mail_options))) {
        cp = sge_unparse_mail_options(ul);
        if (!cp) {
            DPRINTF(("Error unparsing mail options\n"));
            answer_list_add_sprintf(&answer, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                                    MSG_PARSE_ERRORUNPARSINGMAILOPTIONS);
            return answer;
        }
        ep_opt = sge_add_arg(pcmdline, m_OPT, lIntT, "-m", cp);
        lSetInt(ep_opt, SPA_argval_lIntT, ul);
    }

    /*
    ** -M obviously a problem!!!
    ** not unparsed at the moment
    ** does it make sense as a default, after all?
    */
    if ((lp = lGetList(job, JB_mail_list))) {
        lList *lp_new = NULL;
        lListElem *ep_new = NULL;
        lListElem *ep = NULL;
        const char *host;
        const char *user;

        /*
        ** or rather take all if there are more than one elements?
        */
        for_each(ep, lp) {
            user = lGetString(ep, MR_user);
            host = lGetHost(ep, MR_host);
            if (sge_strnullcmp(user, username) ||
                    sge_hostcmp(host, qualified_hostname)) {
                lp_new = lCreateList("mail list", MR_Type);
                ep_new = lAddElemStr(&lp_new, MR_user, user, MR_Type);
                lSetHost(ep_new, MR_host, host);
            }
        }
/****** sge_advance_reservation/ar_validate() **********************************
*  NAME
*     ar_validate() -- validate a advance reservation
*
*  SYNOPSIS
*     bool ar_validate(lListElem *ar, lList **alpp, bool in_master)
*
*  FUNCTION
*     Ensures a new ar has valid start and end times
*
*  INPUTS
*     lListElem *ar   - the ar to check
*     lList **alpp    - answer list pointer
*     bool in_master  - are we in qmaster?
*     bool is_spool   - do we validate for spooling? 
*
*  RESULT
*     bool - true if OK, else false
*
*  NOTES
*     MT-NOTE: ar_validate() is MT safe
*******************************************************************************/
bool ar_validate(lListElem *ar, lList **alpp, bool in_master, bool is_spool)
{
   u_long32 start_time;
   u_long32 end_time;
   u_long32 duration;
   u_long32 now = sge_get_gmt();
   object_description *object_base = object_type_get_object_description();
   
   DENTER(TOP_LAYER, "ar_validate");

   /*   AR_start_time, SGE_ULONG        */
   if ((start_time = lGetUlong(ar, AR_start_time)) == 0) {
      start_time = now;
      lSetUlong(ar, AR_start_time, start_time);
   }

   /*   AR_end_time, SGE_ULONG        */
   end_time = lGetUlong(ar, AR_end_time);
   duration = lGetUlong(ar, AR_duration);
   
   if (end_time == 0 && duration == 0) {
      answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR,
                              MSG_AR_MISSING_VALUE_S, "end time or duration");
      goto ERROR;
   } else if (end_time == 0) {
      end_time = duration_add_offset(start_time, duration);
      duration = end_time  - start_time;
      lSetUlong(ar, AR_end_time, end_time);
      lSetUlong(ar, AR_duration, duration);
   } else if (duration == 0) {
      duration = end_time - start_time;
      lSetUlong(ar, AR_duration, duration);
   }

   if ((end_time - start_time) != duration) {
      answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR,
                              MSG_AR_START_END_DURATION_INVALID);
      goto ERROR;
   }

   if (start_time > end_time) {
      answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR,
                              MSG_AR_START_LATER_THAN_END);
      goto ERROR;
   }
   
   if (!is_spool) {
      if (start_time < now) {
         answer_list_add_sprintf(alpp, STATUS_EEXIST, ANSWER_QUALITY_ERROR,
                                 MSG_AR_START_IN_PAST);
         goto ERROR;
      }
   }
   /*   AR_owner, SGE_STRING */
   
   if (in_master) {
      /*    AR_name, SGE_STRING */
      NULL_OUT_NONE(ar, AR_name);
      if (object_verify_name(ar, alpp, AR_name, SGE_OBJ_AR)) {
         goto ERROR;
      }
      /*   AR_account, SGE_STRING */
      NULL_OUT_NONE(ar, AR_account);
      if (!lGetString(ar, AR_account)) {
         lSetString(ar, AR_account, DEFAULT_ACCOUNT);
      } else {
         if (verify_str_key(alpp, lGetString(ar, AR_account), MAX_VERIFY_STRING,
         "account string", QSUB_TABLE) != STATUS_OK) {
            goto ERROR;
         }
      }
      /*   AR_verify, SGE_ULONG              just verify the reservation or final case */
      /*   AR_error_handling, SGE_ULONG      how to deal with soft and hard exceptions */
      /*   AR_checkpoint_name, SGE_STRING    Named checkpoint */
      NULL_OUT_NONE(ar, AR_checkpoint_name);
      {
         /* request for non existing ckpt object will be refused */
         const char *ckpt_name = NULL;

         ckpt_name = lGetString(ar, AR_checkpoint_name);
         if (ckpt_name != NULL) {
            lList *master_ckpt_list = *object_base[SGE_TYPE_CKPT].list;
            lListElem *ckpt_ep = ckpt_list_locate(master_ckpt_list, ckpt_name);
            if (!ckpt_ep) {
               ERROR((SGE_EVENT, MSG_JOB_CKPTUNKNOWN_S, ckpt_name));
               answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
               goto ERROR;
            }
          }
      }
      /*   AR_resource_list, SGE_LIST */
      {
         lList *master_centry_list = *object_base[SGE_TYPE_CENTRY].list;

         if (centry_list_fill_request(lGetList(ar, AR_resource_list),
                                      alpp, master_centry_list, false, true,
                                      false)) {
            goto ERROR;
         }
         if (compress_ressources(alpp, lGetList(ar, AR_resource_list), SGE_OBJ_AR)) {
            goto ERROR;
         }
         
         if (!centry_list_is_correct(lGetList(ar, AR_resource_list), alpp)) {
            goto ERROR;
         }
      }
      /*   AR_queue_list, SGE_LIST */
      if (!qref_list_is_valid(lGetList(ar, AR_queue_list), alpp)) {
         goto ERROR;
      }
      /*   AR_mail_options, SGE_ULONG   */
      /*   AR_mail_list, SGE_LIST */
      
      /*   AR_master_queue_list  -masterq wc_queue_list, SGE_LIST bind master task to queue(s) */
      if (!qref_list_is_valid(lGetList(ar, AR_master_queue_list), alpp)) {
         goto ERROR;
      }
       
      
      /*   AR_pe, SGE_STRING,  AR_pe_range, SGE_LIST */
      NULL_OUT_NONE(ar, AR_pe);
      {
         const char *pe_name = NULL;
         lList *pe_range = NULL;
         
         pe_name = lGetString(ar, AR_pe);
         if (pe_name) {
            const lListElem *pep;
            pep = pe_list_find_matching(*object_base[SGE_TYPE_PE].list, pe_name);
            if (!pep) {
               ERROR((SGE_EVENT, MSG_JOB_PEUNKNOWN_S, pe_name));
               answer_list_add(alpp, SGE_EVENT, STATUS_EUNKNOWN, ANSWER_QUALITY_ERROR);
               goto ERROR;
            }
            /* check pe_range */
            pe_range = lGetList(ar, AR_pe_range);
            if (object_verify_pe_range(alpp, pe_name, pe_range, SGE_OBJ_AR)!=STATUS_OK) {
               goto ERROR;
            }
         }
      }

      /*   AR_acl_list, SGE_LIST */
      if (userset_list_validate_access(lGetList(ar, AR_acl_list), ARA_name, alpp) != STATUS_OK) {
         goto ERROR;
      }
      
      /*   AR_xacl_list, SGE_LIST */
      if (userset_list_validate_access(lGetList(ar, AR_xacl_list), ARA_name, alpp) != STATUS_OK) {
         goto ERROR;
      }

      if (is_spool) {
         lListElem *jg;
         dstring cqueue_buffer = DSTRING_INIT;
         dstring hostname_buffer = DSTRING_INIT;
         for_each(jg, lGetList(ar, AR_granted_slots)){
            const char *hostname = NULL;
            const char *qname = lGetString(jg, JG_qname);
            bool has_hostname = false;
            bool has_domain = false;

            cqueue_name_split(qname, &cqueue_buffer, &hostname_buffer,
                              &has_hostname, &has_domain);
            hostname = sge_dstring_get_string(&hostname_buffer);
            lSetHost(jg, JG_qhostname, hostname);
         }
         sge_dstring_free(&cqueue_buffer);
         sge_dstring_free(&hostname_buffer);
      }
      /*   AR_type,  SGE_ULONG     */
      /*   AR_state, SGE_ULONG               state of the AR */
      if(lGetUlong(ar, AR_state) == ARL_UNKNOWN){
         lSetUlong(ar, AR_state, ARL_CREATION);  
      }
   }
   DRETURN(true);

ERROR:
   DRETURN(false);
}
Beispiel #27
0
/****** sgeobj/sge_eval_expression/sge_eval_expression() **********************
*  NAME
*     sge_eval_expression() -- boolean expression extension 
*
*  SYNOPSIS
*     int sge_eval_expression(u_long32 type, 
*                             const char *expr, 
*                             const char *value)
*
*  FUNCTION
*     boolean expression extension of regular expression evaluation function 
*     fnmatch()
*
*  INPUTS
*     u_long32 type - type of resource
*     const char *expr - expression string to be evaluated
*     const char *value - value string to be compared for
*     lList **answer_list - answer list to pass back error messages
*
*  RESULT
*     int - result if expression is true or
*         0 - strings are the same or both NULL
*         1 - if is false
*        -1 - for empty expression, null, or other error
*
*  SEE ALSO
*     uti/hostname/sge_hostcmp()
*     fnmatch()
*
*  NOTES:
*     MT-NOTE: sge_eval_expression() is MT safe
*****************************************************************************/
int 
sge_eval_expression(u_long32 type, const char *expr, const char *value, lList **answer_list) 
{
   int match;
   char pattern_buf[MAX_STRING_SIZE], value_buf[MAX_STRING_SIZE];
   
   DENTER(BASIS_LAYER, "sge_eval_expression");
   
   /* Null values are supported in str_cmp_null way */
   if (expr==NULL && value!=NULL) {
      DRETURN(-1);
   }              
   if (expr!=NULL && value==NULL) {
      DRETURN(1);
   }
   if (expr == NULL && value == NULL) {
      DRETURN(0);
   }

   /* To long arguments */
   if (strlen(value) >= MAX_STRING_SIZE) {
      answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                              MSG_EVAL_EXPRESSION_LONG_VALUE, MAX_STRING_SIZE);
      ERROR((SGE_EVENT, MSG_EVAL_EXPRESSION_LONG_VALUE, MAX_STRING_SIZE));
      DRETURN(-1);
   }
   if (strlen(expr) >= MAX_STRING_SIZE) {
      answer_list_add_sprintf(answer_list, STATUS_ESYNTAX, ANSWER_QUALITY_ERROR,
                              MSG_EVAL_EXPRESSION_LONG_EXPRESSION, MAX_STRING_SIZE);
      ERROR((SGE_EVENT, MSG_EVAL_EXPRESSION_LONG_EXPRESSION, MAX_STRING_SIZE));
      DRETURN(-1);
   }   
  
   { 
	   s_token token;             /* The main token structure */
	   token.value=value;         /* the copybuffer will be on demand */
	   token.expr=expr;           /* copy per partes to pattern_buf */
	   token.pattern=pattern_buf;
	   token.s=token.expr;        /* Set the index. */
	   token.tt=T_END;            /* Type of token */
	   token.et=T_EXP;            /* Type of expected token */
	   token.type=type;
	   token.answer_list=answer_list;
	   token.has_patterns = sge_is_expression(token.expr); /*  pattern is detected latter */

	   if(token.has_patterns){
	      uncaseValue(&token,value_buf);   /* Check the value needs to be lowered */
	      match = OrExpression(&token, false);
	      /*
	       * after the expression has been evaluated
	       * the input stream must be empty
	       * and the token must be T_END
	       */
	      if (token.tt != T_END) {
            match=Error(&token, T_END);
	      } else if (token.s[0] != '\0') { /*Something is missing? */
            match=Error(&token, token.et);
	      }
	   } else {
         token.pattern=(char *) token.expr;
         match = MatchPattern(&token, false);
	   }
   }

   DRETURN(match);
}
lListElem *
spool_dynamic_create_context(lList **answer_list, const char *method,
                             const char *shlib_name, const char *args)
{
   bool ok = true;
   lListElem *context = NULL;

   /* shared lib name buffer and handle */
   dstring shlib_dstring = DSTRING_INIT;
   const char *shlib_fullname;
   void *shlib_handle;

   /* get_method function pointer and result */
   spooling_get_method_func get_spooling_method = NULL;
   const char *spooling_name = NULL;

   DENTER(TOP_LAYER, "spool_dynamic_create_context");

   /* build the full name of the shared lib - append architecture dependent
    * shlib postfix 
    */
   shlib_fullname = sge_dstring_sprintf(&shlib_dstring, "%s.%s", shlib_name, 
#if defined(HP11) || defined(HP1164)
                                        "sl"
#elif defined(DARWIN)
                                        "dylib"
#else
                                        "so"
#endif
                                       );

#if defined(HP1164)   
   /*
   ** need to switch to start user for HP
   */
   sge_switch2start_user();
#endif   

   /* open the shared lib */
   # if defined(DARWIN)
   # ifdef RTLD_NODELETE
   shlib_handle = dlopen(shlib_fullname, RTLD_NOW | RTLD_GLOBAL | RTLD_NODELETE);
   # else
   shlib_handle = dlopen(shlib_fullname, RTLD_NOW | RTLD_GLOBAL );
   # endif /* RTLD_NODELETE */
   # else
   # ifdef RTLD_NODELETE
   shlib_handle = dlopen(shlib_fullname, RTLD_NOW | RTLD_NODELETE);
   # else
   shlib_handle = dlopen(shlib_fullname, RTLD_NOW);
   # endif /* RTLD_NODELETE */
   #endif
                        
#if defined(HP1164)   
   /*
   ** switch back to admin user for HP
   */
   sge_switch2admin_user();
#endif

   if (shlib_handle == NULL) {
      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_ERROR, 
                              MSG_SPOOL_ERROROPENINGSHAREDLIB_SS, 
                              shlib_fullname, dlerror());
      ok = false;
   } 

   /* retrieve function pointer of get_method function in shared lib */
   if (ok) {
      dstring get_spooling_method_func_name = DSTRING_INIT;

      sge_dstring_sprintf(&get_spooling_method_func_name,
                          "get_%s_spooling_method", method);

      get_spooling_method = (spooling_get_method_func)
                            dlsym(shlib_handle, 
                            sge_dstring_get_string(&get_spooling_method_func_name));
      if (get_spooling_method == NULL) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                 ANSWER_QUALITY_ERROR, 
                                 MSG_SPOOL_SHLIBDOESNOTCONTAINSPOOLING_SS, 
                                 shlib_fullname, dlerror());
         ok = false;
      }
      sge_dstring_free(&get_spooling_method_func_name);
   }

   /* retrieve name of spooling method in shared lib */
   if (ok) {
      spooling_name = get_spooling_method();

      if (spooling_name == NULL) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                 ANSWER_QUALITY_INFO, 
                                 MSG_SPOOL_SHLIBGETMETHODRETURNSNULL_S, 
                                 shlib_fullname);
         ok = false;
      } else {
         if (strcmp(spooling_name, method) != 0) {
            answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                    ANSWER_QUALITY_INFO, 
                                    MSG_SPOOL_SHLIBCONTAINSXWENEEDY_SSS, 
                                    shlib_fullname, spooling_name, method);
            ok = false;
         }
      }
   }

   /* create spooling context from shared lib */
   if (ok) {
      dstring create_context_func_name = DSTRING_INIT;
      spooling_create_context_func create_context;

      answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                              ANSWER_QUALITY_INFO, 
                              MSG_SPOOL_LOADINGSPOOLINGMETHOD_SS, 
                              spooling_name, shlib_fullname);

      sge_dstring_sprintf(&create_context_func_name, 
                          "spool_%s_create_context", spooling_name);

      create_context = 
            (spooling_create_context_func) 
            dlsym(shlib_handle, 
                  sge_dstring_get_string(&create_context_func_name));
      if (create_context == NULL) {
         answer_list_add_sprintf(answer_list, STATUS_EUNKNOWN, 
                                 ANSWER_QUALITY_ERROR, 
                                 MSG_SPOOL_SHLIBDOESNOTCONTAINSPOOLING_SS,
                                 shlib_fullname, dlerror());
         ok = false;
      } else {
         context = create_context(answer_list, args);
      }
      sge_dstring_free(&create_context_func_name);
   }

   /* cleanup in case of initialization error */
   if (context == NULL) {
      if (shlib_handle != NULL) {
         dlclose(shlib_handle);
      }
   }

   sge_dstring_free(&shlib_dstring);

   DRETURN(context);
}