示例#1
0
lList *buildRequestList(int n)
{
   lList *requestlist = NULL;
   lListElem *request;

   requestlist = lCreateList("requestlist", JobRequestT);

   request = lCreateElem(JobRequestT);
   lSetString(request, R_name, "ARCH");
   lSetString(request, R_operator, "==");
   lSetString(request, R_value, "irix");
   lAppendElem(requestlist, request);

   if (n) {
      request = lCreateElem(JobRequestT);
      lSetString(request, R_name, "editor");
      lSetString(request, R_operator, "==");
      lSetString(request, R_value, "vi");
      lAppendElem(requestlist, request);
   }

   request = lCreateElem(JobRequestT);
   lSetString(request, R_name, "GROUP");
   lSetString(request, R_operator, "==");
   lSetString(request, R_value, "graphic");
   lAppendElem(requestlist, request);

   return requestlist;
}
示例#2
0
static lList *test_create_rqs(void)
{
   lList* rqs_list = lCreateList("my_rqs", RQS_Type);
   lListElem* rqs;
   lList* rule_list;
   lListElem* rule;
   lListElem* filter;
   lListElem* limit;
   lList * limit_list;
   
   rqs = lCreateElem(RQS_Type);
   lSetString(rqs, RQS_name, "Test_Name1");
   lSetBool(rqs, RQS_enabled, true);
   rule_list = lCreateList("Rule_List", RQR_Type);

   rule = lCreateElem(RQR_Type);
      filter = lCreateElem(RQRF_Type);
      lSetBool(filter, RQRF_expand, true);
      lAddSubStr(filter, ST_name, "rqs_user", RQRF_scope, ST_Type);

      lSetObject(rule, RQR_filter_users, filter);

      limit_list = lCreateList("limit_list", RQRL_Type);
      limit = lCreateElem(RQRL_Type);
      lSetString(limit, RQRL_name, "slots");
      lSetString(limit, RQRL_value, "2*$num_proc");
      lAppendElem(limit_list, limit);
      lSetList(rule, RQR_limit, limit_list);
   lAppendElem(rule_list, rule);
   lSetList(rqs, RQS_rule, rule_list);
   lAppendElem(rqs_list, rqs);


   return rqs_list;
}
示例#3
0
void xml_addAttribute(lListElem *xml_elem, const char *name, const char *value) {
    lListElem *attr_elem = lCreateElem(XMLA_Type);
    lList *attr_list = NULL;
    dstring mod_value = DSTRING_INIT;
    bool is_mod_value;
    DENTER(CULL_LAYER, "xml_addAttribute");

    is_mod_value = escape_string(value, &mod_value);

    if (attr_elem) {
        lSetString(attr_elem, XMLA_Name, name);
        lSetString(attr_elem, XMLA_Value, (is_mod_value?sge_dstring_get_string(&mod_value):""));
        if (lGetPosViaElem(xml_elem, XMLH_Attribute, SGE_NO_ABORT) != -1) {
            attr_list = lGetList(xml_elem, XMLH_Attribute);
            if (!attr_list)
                lSetList(xml_elem, XMLH_Attribute, (attr_list = lCreateList("Attributes", XMLA_Type)));
        }
        else if (lGetPosViaElem(xml_elem, XMLE_Attribute, SGE_NO_ABORT) != -1) {
            attr_list = lGetList(xml_elem, XMLE_Attribute);
            if (!attr_list)
                lSetList(xml_elem, XMLE_Attribute, (attr_list = lCreateList("Attributes", XMLA_Type)));
        }
        else {
            sge_dstring_free(&mod_value);
            CRITICAL((SGE_EVENT, "xml_addAttribute() called on wrong cull structure"));

            DEXIT;
            abort();
        }
        lAppendElem(attr_list, attr_elem);
    }
    sge_dstring_free(&mod_value);
    DEXIT;
    return;
}
示例#4
0
/****** sge_orders/sge_add_schedd_info() ***************************************
*  NAME
*     sge_add_schedd_info() -- retrieves the messages and generates an order out 
*                              of it.
*
*  SYNOPSIS
*     lList* sge_add_schedd_info(lList *or_list, int *global_mes_count, int 
*     *job_mes_count) 
*
*  FUNCTION
*     retrieves all messages, puts them into an order package, and frees the
*     orginal messages. It also returns the number of global and job messages.
*
*  INPUTS
*     lList *or_list        - int: the order list to which the message order is added
*     int *global_mes_count - out: global message count
*     int *job_mes_count    - out: job message count
*
*  RESULT
*     lList* - the order list
*
*  NOTES
*     MT-NOTE: sge_add_schedd_info() is not MT safe 
*
*******************************************************************************/
lList *sge_add_schedd_info(lList *or_list, int *global_mes_count, int *job_mes_count) 
{
   lList *jlist;
   lListElem *sme, *ep;

   DENTER(TOP_LAYER, "sge_add_schedd_info");

   sme = schedd_mes_obtain_package(global_mes_count, job_mes_count);

   if (!sme || (lGetNumberOfElem(lGetList(sme, SME_message_list)) < 1 
         && lGetNumberOfElem(lGetList(sme, SME_global_message_list)) < 1)) {
      DEXIT;
      return or_list;
   }
   
   /* create orders list if not existent */
   if (!or_list) {
      or_list = lCreateList("orderlist", OR_Type);
   }   

   /* build order */
   ep=lCreateElem(OR_Type);   
   
   jlist = lCreateList("", SME_Type);
   lAppendElem(jlist, sme);
   lSetList(ep, OR_joker, jlist);
   
   lSetUlong(ep, OR_type, ORT_job_schedd_info);
   lAppendElem(or_list, ep);

   DEXIT;
   return or_list;
}
示例#5
0
/*-------------------------------------------------------------------------*/
lList* qmonGetCE_Type(
Widget w 
) {
   lList *lp = NULL;
   lListElem *ep;
   int row;
   int max_rows;
   char *ce_entry[CE_MAX]; 
   int k;

   DENTER(GUI_LAYER, "qmonGetCE_Type");
   
   XtVaGetValues(w, XmNrows, &max_rows, NULL);
   lp = lCreateList(XtName(w), CE_Type);
   for (row=0; row<max_rows && lp; row++) {
      for (k=0; k<CE_MAX; k++) 
         ce_entry[k] = XbaeMatrixGetCell(w, row, k);
      if (ce_entry[CE_NAME] && ce_entry[CE_NAME][0] != '\0') {
         ep = lCreateElem(CE_Type);
         setCE_TypeValues(ep, ce_entry);
         lAppendElem(lp, ep);
      }
      else
         break;
   }

   DEXIT;
   return lp;
}
示例#6
0
lList *buildComplexNameListB(void)
{
   lList *complexnamelist = NULL;
   lListElem *complexname;

   complexnamelist = lCreateList("complexnamelistB", ComplexNameT);

   complexname = lCreateElem(ComplexNameT);
   lSetString(complexname, N_complexname, "default");
   lAppendElem(complexnamelist, complexname);

   complexname = lCreateElem(ComplexNameT);
   lSetString(complexname, N_complexname, "hardware");
   lAppendElem(complexnamelist, complexname);

   return complexnamelist;
}
示例#7
0
/****** test_category/test_create_access() *************************************
*  NAME
*     test_create_access() -- creates an access list from AccessList
*
*  SYNOPSIS
*     lList* test_create_access() 
*
*  RESULT
*     lList* - NULL or valid acces list
*
*  NOTES
*     MT-NOTE: test_create_access() is not MT safe 
*
*******************************************************************************/
static lList *test_create_access(void)
{
   lList *access_list = NULL;

   access_list = lCreateList("access", US_Type);
   
   if (access_list != NULL) {
      int i;

      for (i = 0; AccessList[i] != NULL; i++) {
         char *access_cp = NULL;
         char *access_str = NULL;
         char *iter_dash = NULL;

         access_cp = strdup(AccessList[i]);
        
         for (access_str = strtok_r(access_cp, " ", &iter_dash); access_str; access_str = strtok_r(NULL, " ", &iter_dash)) {
            lListElem *acc_elem = NULL;

            acc_elem = lCreateElem(US_Type);
            if (acc_elem != NULL) {
               lList *users = lCreateList("user", UE_Type);
               lSetString(acc_elem, US_name, access_str);
               lSetList(acc_elem, US_entries, users);
               lSetBool(acc_elem, US_consider_with_categories, true);
              
               lAppendElem(access_list, acc_elem);
              
               for (access_str = strtok_r(NULL, " ", &iter_dash); access_str; access_str = strtok_r(NULL, " ", &iter_dash)) {
                  lListElem *user = lCreateElem(UE_Type);

                  lSetString(user, UE_name, access_str);
                  lAppendElem(users, user);
               }

            }
         }
         if (access_cp != NULL) {
            sge_free(&access_cp);
         }
      }
   }
   return access_list;
}
示例#8
0
lList *buildComplexList(void)
{
   lList *complexlist = NULL;
   lListElem *complex;

   /* It is better to test every list for its existence (list != NULL) */
   complexlist = lCreateList("complexlist", ComplexT);

   complex = lCreateElem(ComplexT);
   lSetString(complex, C_name, "default");
   lSetList(complex, C_attribute, readComplexFile("default"));
   lAppendElem(complexlist, complex);

   complex = lCreateElem(ComplexT);
   lSetString(complex, C_name, "software");
   lSetList(complex, C_attribute, readComplexFile("software"));
   lAppendElem(complexlist, complex);
   return complexlist;
}
示例#9
0
bool check_range_get_all_ids(void)
{
   bool failed = false;
   lListElem *range;

   /* Create preinitialized range element */
   if (!failed) {
      range = lCreateElem(RN_Type);
      if (range == NULL) {
         failed = true;
      }
   }

   /* Check NULL pointer */
   if (!failed) {
      u_long32 min = 1, max = 6, step = 2;

      range_get_all_ids(NULL, &min, &max, &step);
      if (max != 0 || min != 0 || step != 0) {
         fprintf(stderr, "NULL range is not correct in range_get_all_ids()\n");
         failed = true;
      }
   }

   /* Check preinitialized range */
   if (!failed) {
      u_long32 min = 1, max = 6, step = 2;

      range_get_all_ids(range, &min, &max, &step);
      if (max != 0 || min != 0 || step != 0) {
         fprintf(stderr, "Init range is not correct in range_get_all_ids()\n");
         failed = true;
      }
   }

   /* Check range */
   if (!failed) {
      u_long32 min = 1, max = 6, step = 2;
   
      range_set_all_ids(range, min, max, step);
      range_get_all_ids(range, &min, &max, &step);
      if (min != 1 || max != 6 || step != 2) {
         fprintf(stderr, "Range is not correct in range_get_all_ids()\n");
         failed = true;
      }
   }

   lFreeElem(&range);
   return failed;
}
示例#10
0
void xml_addStylesheet(lListElem *xml_head, const char* name, const char *url, const char *version) {
    lListElem *stylesheet_elem = lCreateElem(XMLS_Type);
    lList *stylesheet_list = NULL;

    if (stylesheet_elem) {
        lSetString(stylesheet_elem, XMLS_Name, name);
        lSetString(stylesheet_elem, XMLS_Value, url);
        lSetString(stylesheet_elem, XMLS_Version, version);
        stylesheet_list = lGetList(xml_head, XMLH_Stylesheet);
        if (!stylesheet_list)
            lSetList(xml_head, XMLH_Stylesheet, (stylesheet_list = lCreateList("Stylesheet", XMLS_Type)));

        lAppendElem(stylesheet_list, stylesheet_elem);
    }
}
示例#11
0
lList *buildQueueList(void)
{
   lList *queuelist = NULL;
   lListElem *element;

   queuelist = lCreateList("queuelist", QueueT);

   element = lCreateElem(QueueT);
   lSetString(element, Q_name, "balin.q");
   lSetList(element, Q_complexname, buildComplexNameListA());
   lAppendElem(queuelist, element);

   element = lCreateElem(QueueT);
   lSetString(element, Q_name, "durin.q");
   lSetList(element, Q_complexname, buildComplexNameListB());
   lAppendElem(queuelist, element);

   element = lCreateElem(QueueT);
   lSetString(element, Q_name, "gloin.q");
   lSetList(element, Q_complexname, buildComplexNameListC());
   lAppendElem(queuelist, element);

   return queuelist;
}
static int test_normal_utilization(void)
{
   /*
    *  8-|          --------    ----
    *    |
    *  4-|                  ---- 
    *    |
    *  0----------------------------------->
    *               |       |   |   |
    *              800     1000
    */
   int ret = 0;

   static u_long32 qeti_expected_result[] = {
      1200,
      1100,
      1000,
      800
   };

   test_array_t test_array[] = {
   {1000, 100, 4},
   {1200, 150, 0},
   {700, 150, 8},
   {0, 0, 0}
   };

   lListElem *cr = lCreateElem(RUE_Type);
   lSetString(cr, RUE_name, "slots");

   printf("\n - test simple reservation - \n\n");


   printf("adding a 200s now assignment of 8 starting at 800\n");
   utilization_add(cr, 800, 200, 8, 100, 1, PE_TAG, "pe_slots", "STARTING", false, false);

   printf("adding a 100s now assignment of 4 starting at 1000\n");
   utilization_add(cr, 1000, 100, 4, 101, 1, PE_TAG, "pe_slots", "STARTING", false, false);

   printf("adding a 100s reservation of 8 starting at 1100\n");
   utilization_add(cr, 1100, 100, 8, 102, 1, PE_TAG, "pe_slots", "RESERVING", false, false);

   ret += do_utilization_test(cr, test_array);
   ret += do_qeti_test(cr, qeti_expected_result);

   lFreeElem(&cr);
   return ret;
}
示例#13
0
int pack_ack(sge_pack_buffer *pb, u_long32 type, u_long32 id, u_long32 id2, const char *str)
{
   int ret;
   lListElem *ack = lCreateElem(ACK_Type);

   DENTER(TOP_LAYER, "pack_ack");

   lSetUlong(ack, ACK_type, type);
   lSetUlong(ack, ACK_id, id);
   lSetUlong(ack, ACK_id2, id2);
   lSetString(ack, ACK_str, str);

   ret = cull_pack_elem(pb, ack);
   lFreeElem(&ack);

   DRETURN(ret);
}
示例#14
0
lList *readComplexFile(
char *complexname 
) {
   FILE *calf;                  /* complex attribute list file */
   char name[MAX_STRINGLENGTH];
   char value[MAX_STRINGLENGTH];
   char listname[MAX_STRINGLENGTH];
   char filename[MAX_STRINGLENGTH];
   char *s;
   int result;
   lList *calp = NULL;          /* complex attribute list ptr */
   lListElem *calep;            /* complex attribute list element pointer */

   strcpy(filename, DATA_DIR);
   strcat(filename, complexname);
   strcat(filename, ".cplx");

   if (!(calf = fopen(filename, "r"))) {
      printf("readComplexFile(): unable to read from file: %s\n", filename);
      exit(-1);
   }

   while ((result = fscanf(calf, "%s %s", name, value)) != EOF) {
      if (result != 2) {
         printf("readComplexFile: wrong format in complexfile %s\n",
                filename);
         exit(-1);
      }
      if (!calp) {
         s = strrchr(filename, '/');
         sprintf(listname, "ComplexAttributes_from_%s",
                 s ? s + 1 : filename);
         calp = lCreateList(filename, ComplexAttributeT);
      }
      calep = lCreateElem(ComplexAttributeT);
      lSetString(calep, A_name, name);
      lSetString(calep, A_value, value);
      lAppendElem(calp, calep);
   }

/*      lWriteList(calp); */

   return calp;
}
示例#15
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);
}
示例#16
0
lListElem* xml_getHead(const char *name, lList *list, lList *attributes) {
    lListElem *xml_head = NULL;

    xml_head = lCreateElem(XMLH_Type);

    if (xml_head) {

        lSetString(xml_head, XMLH_Version, "<?xml version='1.0'?>");
        lSetString(xml_head, XMLH_Name, name);
        lSetList(xml_head, XMLH_Attribute, attributes);
        lSetList(xml_head, XMLH_Element, list);
        xml_addAttribute(xml_head, "xmlns:xsd", "http://gridengine.sunsource.net/source/browse/*checkout*/gridengine/source/dist/util/resources/schemas/qstat/qstat.xsd?revision=1.11");

        /* we do not support stylesheets yet */
        /*    xml_addStylesheet(xml_head, "xmlns:xsl", "http://www.w3.org/1999/XSL/Transform", "1.0");*/
    }

    return xml_head;
}
示例#17
0
lList *buildJobList(int num)
{
   lList *joblist = NULL;
   lListElem *job;
   int n;
   char name[20];

   joblist = lCreateList("joblist", JobT);

   for (n = 0; n < num; n++) {
      sprintf(name, "Job%d", n);
      job = lCreateElem(JobT);
      lSetUlong(job, J_id, n);
      lSetString(job, J_name, name);
      lSetList(job, J_hardrequest, buildRequestList(n));
      lAppendElem(joblist, job);
   }

   return joblist;
}
示例#18
0
/****** sge_orders/sge_create_orders() *****************************************
*  NAME
*     sge_create_orders() -- Create a new order-list or add orders to an existing one
*
*  SYNOPSIS
*     lList* sge_create_orders(lList *or_list, u_long32 type, lListElem *job, 
*     lListElem *ja_task, lList *granted, bool update_execd) 
*
*  FUNCTION
*     - If the or_list is NULL, a new one will be generated
*
*     - in case of a clear_pri order, teh ja_task is improtant. If NULL is put
*       in for ja_task, only the pendin tasks of the spedified job are set to NULL.
*       If a ja_task is put in, all tasks of the job are set to NULL
*
*  INPUTS
*     lList *or_list     - the order list
*     u_long32 type      - order type
*     lListElem *job     - job
*     lListElem *ja_task - ja_task ref or NULL(there is only one case, where it can be NULL)
*     lList *granted     - granted queue list
*     bool update_execd  - should the execd get new ticket values?
*
*  RESULT
*     lList* - returns the orderlist
*
*  NOTES
*     MT-NOTE: sge_create_orders() is MT safe 
*
*  SEE ALSO
*     ???/???
*******************************************************************************/
lList 
*sge_create_orders(lList *or_list, u_long32 type, lListElem *job, lListElem *ja_task,
                   lList *granted , bool update_execd) 
{
   lList *ql = NULL;
   lListElem *gel, *ep, *ep2;
   u_long32 qslots;
  
   DENTER(TOP_LAYER, "sge_create_orders");
   
   if (!job) {
      lFreeList(&or_list);
      DEXIT;
      return or_list;
   }

   /* create orders list if not existent */
   if (!or_list) {
      or_list = lCreateList("orderlist", OR_Type);
   }   

   /* build sublist of granted */
   if (update_execd) {
      for_each(gel, granted) {
         qslots = lGetUlong(gel, JG_slots);
         if (qslots) { /* ignore Qs with slots==0 */
            ep2=lCreateElem(OQ_Type);

            lSetUlong(ep2, OQ_slots, qslots);
            lSetString(ep2, OQ_dest_queue, lGetString(gel, JG_qname));
            lSetUlong(ep2, OQ_dest_version, lGetUlong(gel, JG_qversion));
            lSetDouble(ep2, OQ_ticket, lGetDouble(gel, JG_ticket));
            lSetDouble(ep2, OQ_oticket, lGetDouble(gel, JG_oticket));
            lSetDouble(ep2, OQ_fticket, lGetDouble(gel, JG_fticket));
            lSetDouble(ep2, OQ_sticket, lGetDouble(gel, JG_sticket));
            if (!ql)
               ql=lCreateList("orderlist",OQ_Type);
            lAppendElem(ql, ep2);
         }
      }
   }
示例#19
0
/****** test_category/test_create_request() ************************************
*  NAME
*     test_create_request() -- creats a request list from the request string
*
*  SYNOPSIS
*     lList* test_create_request(const char *requestStr, int count) 
*
*  INPUTS
*     const char *requestStr - request string
*     int count              - how many times the request string should be used
*                              (multiplyer, needs to between 1 and ...)
*
*  RESULT
*     lList* - NULL or request list
*
*  NOTES
*     MT-NOTE: test_create_request() is MT safe 
*
*******************************************************************************/
static lList *test_create_request(const char *requestStr, int count) 
{
   lList *requests = NULL;
   char *request_cp = NULL;
   char *iter_dash = NULL;

   requests = lCreateList("requests", CE_Type);

   if (requests != NULL) {
       int i;
       for (i = 0; i < count; i++) {
          char *request_str;

          request_cp = strdup(requestStr);
          
          for (request_str = strtok_r(request_cp, " ", &iter_dash); request_str; request_str = strtok_r(NULL, " ", &iter_dash)) {
            lListElem *request = NULL;
            
            request = lCreateElem(CE_Type);
            
            if (request != NULL) {
               lSetString(request, CE_name, request_str);
               lSetString(request, CE_stringval, strtok_r(NULL, " ", &iter_dash));
            }
            else {
               lFreeList(&requests);
               goto end;
            }
            lAppendElem(requests, request); 
          }
         if (request_cp != NULL) { 
            sge_free(&request_cp);
         }
       }
   }
end:
   if (request_cp != NULL) {
      sge_free(&request_cp);
   }
   return requests;
}
/******* execd/loadsensor/sge_ls_create_ls() **********************************
*  NAME
*     sge_ls_create_ls -- creates a new CULL loadsensor element 
*
*  SYNOPSIS
*     static lListElem* sge_ls_create_ls(const char *qualified_hostname,
*                                        char *name, const char *scriptfile)
*
*  FUNCTION
*     The function creates a new CULL element of type LS_Type and
*     returns a pointer to this object. The loadsensor will be
*     started immediately.
*     If it cannot be started then, LS_has_to_restart is set to 
*     true so that it will be attempted to be restarted in the next load interval
*
*  INPUTS
*     qualified_hostname - qualified host name
*     name - pseudo name of the ls
*              "extern" for user defined loadsensors
*              "intern" for qidle and qloadsensor
*     scriptfile - absolute path to the ls scriptfile
*
*  RESULT
*     new CULL element of type LS_Type will be returned
*     and a new loadsensor process will be created by this function
******************************************************************************/
static lListElem *sge_ls_create_ls(const char *qualified_hostname, char *name, const char *scriptfile)
{
   lListElem *new_ls = NULL;    /* LS_Type */
   SGE_STRUCT_STAT st;

   DENTER(TOP_LAYER, "sge_ls_create_ls");

   if (scriptfile != NULL) {
      if (SGE_STAT(scriptfile, &st) != 0) {
         if (strcmp(name, "extern") == 0) {
            WARNING((SGE_EVENT, MSG_LS_NOMODTIME_SS, scriptfile,
                   strerror(errno)));
         }
         DRETURN(NULL);
      }

      new_ls = lCreateElem(LS_Type);
      if (new_ls) {
         /* initialize all attributes */
         lSetString(new_ls, LS_name, name);
         lSetString(new_ls, LS_command, scriptfile);
         sge_ls_set_pid(new_ls, -1);
         lSetRef(new_ls, LS_in, NULL);
         lSetRef(new_ls, LS_out, NULL);
         lSetRef(new_ls, LS_err, NULL);
         lSetBool(new_ls, LS_has_to_restart, false);
         lSetUlong(new_ls, LS_tag, 0);
         lSetList(new_ls, LS_incomplete, lCreateList("", LR_Type));
         lSetList(new_ls, LS_complete, lCreateList("", LR_Type));
         lSetUlong(new_ls, LS_last_mod, st.st_mtime);

         /* start loadsensor, if couldn't set the restart flag so that we
          * restart it in the next load interval
          */
         if (sge_ls_start_ls(qualified_hostname, new_ls) != LS_OK) {
            lSetBool(new_ls, LS_has_to_restart, true);
         }
      }
   }
   DRETURN(new_ls);
}
示例#21
0
/****** cull/db/lJoinCopyElem() ***********************************************
*  NAME
*     lJoinCopyElem() -- Combine two elements 
*
*  SYNOPSIS
*     static lListElem* lJoinCopyElem(const lDescr *dp, 
*                                     const lListElem *src0, 
*                                     const lEnumeration *enp0, 
*                                     const lListElem *src1, 
*                                     const lEnumeration *enp1) 
*
*  FUNCTION
*     Returns a combined element with descriptor 'dp'. Uses 'src0'
*     with mask 'enp0' and 'src1' with mask 'enp1' as source. 
*
*  INPUTS
*     const lDescr *dp         - descriptor 
*     const lListElem *src0    - element1 
*     const lEnumeration *enp0 - mask1 
*     const lListElem *src1    - element2 
*     const lEnumeration *enp1 - mask2 
*
*  RESULT
*     static lListElem* - combined element 
******************************************************************************/
static lListElem *lJoinCopyElem(const lDescr *dp, 
                                const lListElem *src0,
                                const lEnumeration *enp0,
                                const lListElem *src1,
                                const lEnumeration *enp1) 
{
   lListElem *dst;
   int i;

   DENTER(CULL_LAYER, "lJoinCopyElem");

   if (!src0 || !src1) {
      LERROR(LEELEMNULL);
      DEXIT;
      return NULL;
   }

   if (!(dst = lCreateElem(dp))) {
      LERROR(LECREATEELEM);
      DEXIT;
      return NULL;
   }

   i = 0;
   if (lCopyElemPartialPack(dst, &i, src0, enp0, true, NULL) == -1) {
      sge_free(&dst);
      LERROR(LECOPYELEMPART);
      DEXIT;
      return NULL;
   }
   if (lCopyElemPartialPack(dst, &i, src1, enp1, true, NULL) == -1) {
      sge_free(&dst);
      LERROR(LECOPYELEMPART);
      DEXIT;
      return NULL;
   }

   DEXIT;
   return dst;
}
示例#22
0
/****** test_category/test_create_queue() **************************************
*  NAME
*     test_create_queue() -- creates a request queue list from the queue string
*
*  SYNOPSIS
*     lList* test_create_queue(const char *queueStr, int count) 
*
*  INPUTS
*     const char *queueStr - the queue string used as a bases
*     int count            -  how many times the request string should be used
*                             (multiplyer, needs to between 1 and ...)
*
*  RESULT
*     lList* - NULL or valid queue request list
*
*  NOTES
*     MT-NOTE: test_create_queue() is MT safe 
*
*******************************************************************************/
static lList *test_create_queue(const char *queueStr, int count) 
{
   lList *queues = NULL;
   char *queue_cp = NULL;
   char *iter_dash = NULL;

   queues = lCreateList("queues", QR_Type);

   if (queues != NULL) {
       int i;
       for (i = 0; i < count; i++) {
          char *queues_str;
          queue_cp = strdup(queueStr);
          for (queues_str = strtok_r(queue_cp, " ", &iter_dash); queues_str; queues_str = strtok_r(NULL, " ", &iter_dash)) {
            lListElem *queue = NULL;
            
            queue = lCreateElem(QR_Type);
            
            if (queue != NULL) {
               lSetString(queue, QR_name, queues_str);
            }
            else {
               lFreeList(&queues);
               goto end;
            }
            lAppendElem(queues, queue); 
          }
          if (queue_cp != NULL) {
            sge_free(&queue_cp);
          }
       }
   }
end:
   if (queue_cp != NULL) {
      sge_free(&queue_cp); 
   }
   return queues;
}
示例#23
0
文件: qrsub.c 项目: HPCKP/gridengine
int main(int argc, char **argv) {
   lList *pcmdline = NULL;
   lList *alp = NULL;
   sge_gdi_ctx_class_t *ctx = NULL;
   lList *ar_lp = NULL;

   lListElem *ar = NULL;

   DENTER_MAIN(TOP_LAYER, "qrsub");

   /* Set up the program information name */
   sge_setup_sig_handlers(QRSUB);

   log_state_set_log_gui(1);

   if (sge_gdi2_setup(&ctx, QRSUB, MAIN_THREAD, &alp) != AE_OK) {
      answer_list_output(&alp);
      goto error_exit;
   }

   /*
   ** stage 1 of commandline parsing
   */
   {
      dstring file = DSTRING_INIT;
      const char *user = ctx->get_username(ctx);
      const char *cell_root = ctx->get_cell_root(ctx);

      /* arguments from SGE_ROOT/common/sge_ar_request file */
      get_root_file_path(&file, cell_root, SGE_COMMON_DEF_AR_REQ_FILE);
      if ((alp = parse_script_file(QRSUB, sge_dstring_get_string(&file), "", &pcmdline, environ, 
         FLG_HIGHER_PRIOR | FLG_IGN_NO_FILE)) == NULL) {
         /* arguments from $HOME/.sge_ar_request file */
         if (get_user_home_file_path(&file, SGE_HOME_DEF_AR_REQ_FILE, user, &alp)) {
            lFreeList(&alp);
            alp = parse_script_file(QRSUB, sge_dstring_get_string(&file), "", &pcmdline, environ, 
            FLG_HIGHER_PRIOR | FLG_IGN_NO_FILE);
         }
      }
      sge_dstring_free(&file); 

      if (alp) {
         answer_list_output(&alp);
         lFreeList(&pcmdline);
         goto error_exit;
      }
   }
   
   alp = cull_parse_cmdline(QRSUB, argv+1, environ, &pcmdline, FLG_USE_PSEUDOS);

   if (answer_list_print_err_warn(&alp, NULL, "qrsub: ", MSG_WARNING) > 0) {
      lFreeList(&pcmdline);
      goto error_exit;
   }
   
   if (!pcmdline) {
      /* no command line option is present: print help to stderr */
      sge_usage(QRSUB, stderr);
      fprintf(stderr, "%s\n", MSG_PARSE_NOOPTIONARGUMENT);
      goto error_exit;
   }

   /*
   ** stage 2 of command line parsing
   */
   ar = lCreateElem(AR_Type);

   if (!sge_parse_qrsub(ctx, pcmdline, &alp, &ar)) {
      answer_list_output(&alp);
      lFreeList(&pcmdline);
      goto error_exit;
   }

   ar_lp = lCreateList(NULL, AR_Type);
   lAppendElem(ar_lp, ar);

   alp = ctx->gdi(ctx, SGE_AR_LIST, SGE_GDI_ADD | SGE_GDI_RETURN_NEW_VERSION, &ar_lp, NULL, NULL);
   lFreeList(&ar_lp);
   answer_list_on_error_print_or_exit(&alp, stdout);
   if (answer_list_has_error(&alp)) {
      sge_gdi2_shutdown((void**)&ctx);
      sge_prof_cleanup();
      if (answer_list_has_status(&alp, STATUS_NOTOK_DOAGAIN)) {
         DRETURN(25);
      } else {
         DRETURN(1);
      }
   }

   sge_gdi2_shutdown((void**)&ctx);
   sge_prof_cleanup();
   DRETURN(0);

error_exit:
   sge_gdi2_shutdown((void**)&ctx);
   sge_prof_cleanup();
   SGE_EXIT((void**)&ctx, 1);
   DRETURN(1);
}
示例#24
0
            lSetUlong(ep2, OQ_slots, qslots);
            lSetString(ep2, OQ_dest_queue, lGetString(gel, JG_qname));
            lSetUlong(ep2, OQ_dest_version, lGetUlong(gel, JG_qversion));
            lSetDouble(ep2, OQ_ticket, lGetDouble(gel, JG_ticket));
            lSetDouble(ep2, OQ_oticket, lGetDouble(gel, JG_oticket));
            lSetDouble(ep2, OQ_fticket, lGetDouble(gel, JG_fticket));
            lSetDouble(ep2, OQ_sticket, lGetDouble(gel, JG_sticket));
            if (!ql)
               ql=lCreateList("orderlist",OQ_Type);
            lAppendElem(ql, ep2);
         }
      }
   }

   /* build order */
   ep=lCreateElem(OR_Type);

   if(ja_task != NULL) {
      lSetDouble(ep, OR_ticket,    lGetDouble(ja_task, JAT_tix));
      lSetDouble(ep, OR_ntix,      lGetDouble(ja_task, JAT_ntix));
      lSetDouble(ep, OR_prio,      lGetDouble(ja_task, JAT_prio));
   }
   
   if (type == ORT_tickets || type == ORT_ptickets) {
      
      static order_pos_t *order_pos = NULL;
      
      const lDescr tixDesc[] = {
                            {JAT_task_number, lUlongT | CULL_IS_REDUCED, NULL},
                            {JAT_tix, lDoubleT | CULL_IS_REDUCED, NULL},
                            {JAT_oticket, lDoubleT | CULL_IS_REDUCED, NULL}, 
int main(int argc, char *argv[])
{
   lListElem *queue, *copy;
   const lDescr *descr;
   spooling_field *fields;

   dstring queue_str = DSTRING_INIT;
   dstring copy_str  = DSTRING_INIT;

   lList *answer_list;

   int i;

   lInit(nmv);

   descr = QU_Type;
   copy  = lCreateElem(descr);

/*    lWriteElemTo(queue, stdout); */

   for(i = 0; mt_get_type(descr[i].mt) != lEndT; i++) {
      int nm;
      const char *name;
      const char *value, *reread_value;

      nm = descr[i].nm;
      name = lNm2Str(nm);
      value = object_append_field_to_dstring(queue, &answer_list, 
                                             &queue_str, nm, '\0');
      reread_value = NULL;

      if(value != NULL) {
         if(!object_parse_field_from_string(copy, &answer_list, nm, value)) {
            fprintf(stderr, "setting value for field %s failed\n", name);
         } else {
            reread_value = object_append_field_to_dstring(copy, &answer_list, 
                                                          &copy_str, nm, '\0');
         }
      }

#if 1
      printf("%s\t%s\t%s\n", name, 
             value == NULL ? "<null>" : value,
             reread_value == NULL ? "<null>" : reread_value);
#endif

      if(sge_strnullcmp(value, reread_value) != 0) {
         fprintf(stderr, "regression test for object_[gs]et_field_contents failed for attribute "SFQ": "SFQ" != "SFQ"\n", 
                 name, 
                 value != NULL ? value : "<null>", 
                 reread_value != NULL ? reread_value : "<null>");
      }
   }

   fields = spool_get_fields_to_spool(&answer_list, QU_Type, &spool_config_instr);
   printf("\nthe following fields will be spooled:");
   for(i = 0; fields[i].nm != NoName; i++) {
      printf(" %s", lNm2Str(fields[i].nm));
   }
   printf("\n");
   fields = spool_free_spooling_fields(fields);

   /* cleanup */
   lFreeElem(&queue);
   lFreeElem(&copy);

   sge_dstring_free(&queue_str);
   sge_dstring_free(&copy_str);

   return EXIT_SUCCESS;
}
示例#26
0
int main(int argc, char *argv[])
{
   int pos_tests_failed = 0;
   int neg_tests_failed = 0;
   int i = 0;
   lList *answer_list = NULL;


   filter_test_t positiv_test[] = {
      {"num_proc", 4}, 
      {"$num_proc", 4},
      {"$num_proc*2", 8},
      {"$num_proc*0.5", 2.0},
      {"num_proc*2", 8},
      {"num_proc+1", 5}, 
      {"$num_proc-2", 2}, 
      {"$num_proc+0.1", 4.1}, 
      {"1+$num_proc+0.1", 5.1}, 
      {NULL, 0}
   };

   filter_test_t negativ_test[] = {
      {"2*num_proc", 0}, 
      {"2,0+num_proc", 0}, 
      {"none", 0}, 
      {NULL, 0}
   };

   lList *centry_list;
   lList *host_centry_list;
   lListElem *centry;
   lListElem *host;

   DENTER_MAIN(TOP_LAYER, "test_sge_load_formula");

   lInit(nmv);

   /* set up centry */
   centry_list = lCreateList("", CE_Type);
   centry = lCreateElem(CE_Type);
   lSetString(centry, CE_name, "num_proc");
   lSetString(centry, CE_stringval, "4");
   lSetDouble(centry, CE_doubleval, 4);
   lAppendElem(centry_list, centry);

   /* set up host */
   host_centry_list = lCreateList("", CE_Type);
   lAppendElem(host_centry_list, lCopyElem(centry));
   host = lCreateElem(EH_Type);
   lSetList(host, EH_consumable_config_list, host_centry_list);

   for (i=0; ; i++){
      double val;
      if (positiv_test[i].formula == NULL) {
         break;
      }
      if (!validate_load_formula(positiv_test[i].formula, &answer_list, centry_list, "load_formula")) {
         answer_list_output(&answer_list);
         pos_tests_failed++;
      }

      val = scaled_mixed_load(positiv_test[i].formula, NULL, host, centry_list);
      if (val != positiv_test[i].value) {
         printf("got %f, but expected %f(%g,%g)\n", val, positiv_test[i].value, val, positiv_test[i].value);
         pos_tests_failed++;
      }
   }
   
   for (i=0; ; i++){
     if (negativ_test[i].formula == NULL) {
         break;
      }
      if (validate_load_formula(negativ_test[i].formula, &answer_list, centry_list, "load_formula") == true) {
         printf("load_formula \"%s\" returned no error\n", negativ_test[i].formula);
         neg_tests_failed++;
      }
      lFreeList(&answer_list);
   }

   lFreeList(&centry_list);
   lFreeElem(&host);

   printf("\n");
   printf("%d positiv test(s) failed\n", pos_tests_failed);
   printf("%d negativ test(s) failed\n", neg_tests_failed);

   DRETURN(pos_tests_failed + neg_tests_failed);
}
示例#27
0
int pt_dispatch_proc_to_job(
lnk_link_t *job_list,
int time_stamp,
time_t last_time
) {
   char procnam[128];
   int fd = -1;
#if defined(LINUX)
   char buffer[BIGLINE];
   lListElem *pr = NULL;
   SGE_STRUCT_STAT fst;
   unsigned long utime, stime, vsize, pid;
   int pos_pid = lGetPosInDescr(PRO_Type, PRO_pid);
   int pos_utime = lGetPosInDescr(PRO_Type, PRO_utime);
   int pos_stime = lGetPosInDescr(PRO_Type, PRO_stime);
   int pos_vsize = lGetPosInDescr(PRO_Type, PRO_vsize);
   int pos_groups = lGetPosInDescr(PRO_Type, PRO_groups);
   int pos_rel = lGetPosInDescr(PRO_Type, PRO_rel);
   int pos_run = lGetPosInDescr(PRO_Type, PRO_run);
   int pos_io = lGetPosInDescr(PRO_Type, PRO_io);
   int pos_group = lGetPosInDescr(GR_Type, GR_group);
#else
   prstatus_t pr;
   prpsinfo_t pri;
#endif

#if defined(SOLARIS) || defined(ALPHA)   
   prcred_t proc_cred;
#endif

   int ret;
   u_long32 max_groups;
   gid_t *list;
   int groups=0;
   int pid_tmp;

   proc_elem_t *proc_elem = NULL;
   job_elem_t *job_elem = NULL;
   lnk_link_t *curr;
   double old_time = 0;
   uint64 old_vmem = 0;

   DENTER(TOP_LAYER, "pt_dispatch_proc_to_job");

   max_groups = sge_sysconf(SGE_SYSCONF_NGROUPS_MAX);
   if (max_groups <= 0) {
      ERROR((SGE_EVENT, SFNMAX, MSG_SGE_NGROUPS_MAXOSRECONFIGURATIONNECESSARY));
      DEXIT;
      return 1;  
   }   

   list = (gid_t*) malloc(max_groups*sizeof(gid_t));
   if (list == NULL) {
      ERROR((SGE_EVENT, SFNMAX, MSG_SGE_PTDISPATCHPROCTOJOBMALLOCFAILED));
      DEXIT;
      return 1;
   }

   /* find next valid entry in procfs */ 
   while ((dent = readdir(cwd))) {
      char *pidname;

      if (!dent->d_name)
         continue;
      if (!dent->d_name[0])
         continue;

      if (!strcmp(dent->d_name, "..") || !strcmp(dent->d_name, "."))
         continue;

      if (dent->d_name[0] == '.')
          pidname = &dent->d_name[1];
      else
          pidname = dent->d_name;

      if (atoi(pidname) == 0)
         continue;

#if defined(LINUX)
      /* check only processes which belongs to a GE job */
      if ((pr = get_pr(atoi(pidname))) != NULL) {
         /* set process as still running */
         lSetPosBool(pr, pos_run, true);
         if (lGetPosBool(pr, pos_rel) != true) {
            continue;
         }
      }
      sprintf(procnam, PROC_DIR "/%s/stat", dent->d_name);

      if (SGE_STAT(procnam, &fst)) {
         if (errno != ENOENT) {
#ifdef MONITOR_PDC
            INFO((SGE_EVENT, "could not stat %s: %s\n", procnam, strerror(errno)));
#endif
            touch_time_stamp(dent->d_name, time_stamp, job_list);
         }
         continue;
      }
      /* TODO (SH): This does not work with Linux 2.6. I'm looking for a workaround.
       * If the stat file was not changed since our last parsing there is no need to do it again
       */
      /*if (pr == NULL || fst.st_mtime > last_time) {*/
      {
#else
         sprintf(procnam, "%s/%s", PROC_DIR, dent->d_name);
#endif
         if ((fd = open(procnam, O_RDONLY, 0)) == -1) {
            if (errno != ENOENT) {
#ifdef MONITOR_PDC
               if (errno == EACCES)
                  INFO((SGE_EVENT, "(uid:"gid_t_fmt" euid:"gid_t_fmt") could not open %s: %s\n",
                           getuid(), geteuid(), procnam, strerror(errno)));
               else
                  INFO((SGE_EVENT, "could not open %s: %s\n", procnam, strerror(errno)));
#endif
                  touch_time_stamp(dent->d_name, time_stamp, job_list);
            }
            continue;
         }

         /** 
          ** get a list of supplementary group ids to decide
          ** whether this process will be needed;
          ** read also prstatus
          **/

#  if defined(LINUX)

         /* 
          * Read the line and append a 0-Byte 
          */
         if ((ret = read(fd, buffer, BIGLINE-1))<=0) {
            close(fd);
            if (ret == -1 && errno != ENOENT) {
#ifdef MONITOR_PDC
               INFO((SGE_EVENT, "could not read %s: %s\n", procnam, strerror(errno)));
#endif
               touch_time_stamp(dent->d_name, time_stamp, job_list);
            }
            continue;
         }
         buffer[BIGLINE-1] = '\0';

         /* 
          * get prstatus
          */
         ret = sscanf(buffer, "%lu %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu %*d %*d %*d %*d %*d %*d %*u %lu",
                      &pid,
                      &utime,
                      &stime,
                      &vsize);

         if (ret != 4) {
            close(fd);
            continue;
         }

         if (pr == NULL) {
            pr = lCreateElem(PRO_Type);
            lSetPosUlong(pr, pos_pid, pid);
            lSetPosBool(pr, pos_rel, false);
            append_pr(pr);
         }
         
         lSetPosUlong(pr, pos_utime, utime);
         lSetPosUlong(pr, pos_stime, stime);
         lSetPosUlong(pr, pos_vsize, vsize);
         
         close(fd);
      }
      /* mark this proc as running */
      lSetPosBool(pr, pos_run, true);

      /* 
       * get number of groups; 
       * get list of supplementary groups 
       */
      {
         char procnam[256];
         lList *groupTable = lGetPosList(pr, pos_groups);

         sprintf(procnam, PROC_DIR "/%s/status", dent->d_name);
         if (SGE_STAT(procnam, &fst) != 0) {
            if (errno != ENOENT) {
#ifdef MONITOR_PDC
               INFO((SGE_EVENT, "could not stat %s: %s\n", procnam, strerror(errno)));
#endif
               touch_time_stamp(dent->d_name, time_stamp, job_list);
            }
            continue;
         }

         groups = 0;
         if (fst.st_mtime < last_time && groupTable != NULL) {
            lListElem *group;

            for_each(group, groupTable) {
               list[groups] = lGetPosUlong(group, pos_group);
               groups++;
            }
         } else {
示例#28
0
bool test_lWhat_lSelect(void)
{
   bool ret = true;
   lEnumeration *what = lWhat("%T(%I %I -> %T( %I %I -> %T (%I %I %I %I) %I %I) %I -> %T(%I) %I)",
                              TEST_Type, 
                                 TEST_int, 
                                 TEST_list, TEST1_Type, 
                                    TEST1_int,
                                    TEST1_list, TEST_Type,
                                       TEST_int,
                                       TEST_list,
                                       TEST_object,
                                       TEST_string,
                                    TEST1_object,
                                    TEST1_string,
                                 TEST_object, TEST1_Type, 
                                    TEST1_string,
                                 TEST_string);
   lListElem *elem;
   lListElem *elem1;
   lList *list = lCreateList("", TEST_Type);
   lList *list1 = NULL;
   int i;

   elem = lCreateElem(TEST_Type); 
   lSetInt(elem, TEST_int, 0);
   lSetHost(elem, TEST_host, "zero");
   lSetString(elem, TEST_string, "zero");
   lSetFloat(elem, TEST_float, 0);
   lSetDouble(elem, TEST_double, 0); 
   lSetChar(elem, TEST_char, 'z');
   lSetLong(elem, TEST_long, 0);
   lSetUlong(elem, TEST_ulong, 0);
   lSetBool(elem, TEST_bool, false);

   elem1 = lCreateElem(TEST1_Type); 
   lSetInt(elem1, TEST1_int, 1);
   lSetHost(elem1, TEST1_host, "one");
   lSetString(elem1, TEST1_string, "one");
   lSetFloat(elem1, TEST1_float, 1);
   lSetDouble(elem1, TEST1_double, 1); 
   lSetChar(elem1, TEST1_char, 'o');
   lSetLong(elem1, TEST1_long, 1);
   lSetUlong(elem1, TEST1_ulong, 1);
   lSetBool(elem1, TEST1_bool, true);

   for (i = 0; i < 5; i++) {
      lList *tmp_list = lCreateList("", TEST1_Type);
      lListElem *tmp_elem = lCopyElem(elem);
      int j;

      for (j = 0; j < 5; j++) {
         lList *tmp_list1 = lCreateList("", TEST_Type);
         lListElem *tmp_elem1 = lCopyElem(elem);
         int k;
   
         for (k = 0; k < 5; k++) {
            lList *tmp_list2 = lCreateList("", TEST1_Type);
            lListElem *tmp_elem2 = lCopyElem(elem);

            lSetList(tmp_elem2, TEST_list, tmp_list2);
            lAppendElem(tmp_list1, tmp_elem2);
         }

         lSetList(tmp_elem1, TEST_list, tmp_list1);
         lAppendElem(tmp_list, tmp_elem1);
      }

      lSetList(tmp_elem, TEST_list, tmp_list);
      lAppendElem(list, tmp_elem);
   }

   list1 = lSelect("", list, NULL, what);

   /* EB: Replace this function */
#if 0
   lWriteListTo(list1, stderr);
#endif

   lFreeWhat(&what);
   lFreeElem(&elem);
   lFreeElem(&elem1);
   lFreeList(&list);
   lFreeList(&list1);

   return ret;
}
int main(int argc, char *argv[])
{
   lListElem *queue, *copy;
   lList *queue_list;
   lList *answer_list = NULL;
   const lDescr *descr;
   spooling_field *fields;
   const char *filepath;
   int i;
   int width;
   char format[100];

   lInit(nmv);

   queue = queue_create_template();
   lSetString(queue, QU_terminate_method, "/tmp/myterminate_method.sh");
   lAddSubStr(queue, CE_name, "foo", QU_suspend_thresholds, CE_Type);
   lAddSubStr(queue, CE_name, "bar", QU_suspend_thresholds, CE_Type);
   copy  = lCreateElem(QU_Type);

   queue_list = lCreateList("queue_list", QU_Type);
   lAppendElem(queue_list, queue);
   lAppendElem(queue_list, copy);

   descr = lGetElemDescr(queue);
   
   fields = spool_get_fields_to_spool(&answer_list, QU_Type, &spool_config_instr);
   printf("\nthe following fields are spooled:");
   for(i = 0; fields[i].nm != NoName; i++) {
      printf(" %s", lNm2Str(fields[i].nm));
   }
   printf("\n");

   spool_flatfile_align_object(&answer_list, fields);
   width = fields[0].width;
   printf("alignment for attribute names is %d\n", width);

   spool_flatfile_align_list(&answer_list, queue_list, fields);
   printf("field widths for list output is as follows:\n");
   
   sprintf(format, "%%%ds: %%d\n", width);

   for(i = 0; fields[i].nm != NoName; i++) {
      printf(format, lNm2Str(fields[i].nm), fields[i].width);
   }

   filepath = spool_flatfile_write_object(&answer_list, queue,
                                          NULL,
                                          &spool_flatfile_instr_config,
                                          SP_DEST_STDOUT, SP_FORM_ASCII, NULL);
   if(filepath != NULL) {
      printf("\ndata successfully written to stdout\n");
      FREE(filepath);
   } else {
      answer_list_print_err_warn(&answer_list, NULL, NULL);
   }
                               
   printf("\n");

   filepath = spool_flatfile_write_object(&answer_list, queue,
                               NULL,
                               &spool_flatfile_instr_config,
                               SP_DEST_TMP, SP_FORM_ASCII, NULL);
   if(filepath != NULL) {
      printf("temporary file %s successfully written\n", filepath);
      sge_unlink(NULL, filepath);
      FREE(filepath);
   } else {
      answer_list_print_err_warn(&answer_list, NULL, NULL);
   }
                               
   filepath = spool_flatfile_write_object(&answer_list, queue,
                               NULL,
                               &spool_flatfile_instr_config,
                               SP_DEST_SPOOL, SP_FORM_ASCII, 
                               "test_sge_spooling_flatfile.dat");
   if(filepath != NULL) {
      lListElem *reread_queue;

      printf("spool file %s successfully written\n", filepath);

      /* reread queue from file */
      reread_queue = spool_flatfile_read_object(&answer_list, QU_Type, NULL, NULL,
                                                &spool_flatfile_instr_config, 
                                                SP_FORM_ASCII, NULL, 
                                                "test_sge_spooling_flatfile.dat");
     
      if(reread_queue == NULL) {
         answer_list_print_err_warn(&answer_list, NULL, NULL);
      } else {
         lWriteElemTo(reread_queue, stdout);
         lFreeElem(&reread_queue);
      }
     
      sge_unlink(NULL, filepath);
      FREE(filepath);
   } else {
      answer_list_print_err_warn(&answer_list, NULL, NULL);
   }
   
   filepath = spool_flatfile_write_list(&answer_list, queue_list,
                                        NULL,
                                        &spool_flatfile_instr_config_list,
                                        SP_DEST_STDOUT, SP_FORM_ASCII, 
                                        NULL);
   if(filepath != NULL) {
      printf("\ndata successfully written to stdout\n");
      FREE(filepath);
   } else {
      answer_list_print_err_warn(&answer_list, NULL, NULL);
   }
   
   filepath = spool_flatfile_write_list(&answer_list, queue_list,
                                        NULL,
                                        &spool_flatfile_instr_config_list,
                                        SP_DEST_SPOOL, SP_FORM_ASCII, 
                                        "test_sge_spooling_flatfile.dat");
   if(filepath != NULL) {
      lList *reread_list;

      printf("spool file %s successfully written\n", filepath);

      reread_list = spool_flatfile_read_list(&answer_list, QU_Type, NULL, NULL, &spool_flatfile_instr_config_list, SP_FORM_ASCII, NULL, "test_sge_spooling_flatfile.dat");
      if (reread_list == NULL) {
         answer_list_print_err_warn(&answer_list, NULL, NULL);
      } else {
         lWriteListTo(reread_list, stdout);
         lFreeList(&reread_list);
      }
/*       sge_unlink(NULL, filepath); */
      FREE(filepath);
   } else {
      answer_list_print_err_warn(&answer_list, NULL, NULL);
   }

   /* test reading object */
   /* test nonexisting filename */
   
   /* test behaviour with NULL-pointer passed */
   printf("\n\ntesting error handling, the next calls have to fail\n");
   spool_flatfile_align_object(&answer_list, NULL);
   spool_flatfile_align_list(&answer_list, NULL, fields);
   spool_flatfile_align_list(&answer_list, queue_list, NULL);
   answer_list_print_err_warn(&answer_list, NULL, NULL);

   /* cleanup */
   lFreeList(&queue_list);

   fields = spool_free_spooling_fields(fields);

   fprintf(stdout, "file handle stdout still alive\n");
   fprintf(stderr, "file handle stderr still alive\n");

   return EXIT_SUCCESS;
}
示例#30
0
/****** sge_var/var_list_parse_from_string() *******************************
*  NAME
*     var_list_parse_from_string() -- parse vars from string list 
*
*  SYNOPSIS
*     int var_list_parse_from_string(lList **lpp, 
*                                    const char *variable_str, 
*                                    int check_environment) 
*
*  FUNCTION
*     Parse a list of variables ("lpp") from a comma separated 
*     string list ("variable_str"). The boolean "check_environment"
*     defined wether the current value of a variable is taken from
*     the environment of the calling process.
*
*  INPUTS
*     lList **lpp              - VA_Type list 
*     const char *variable_str - source string 
*     int check_environment    - boolean
*
*  RESULT
*     int - error state
*         0 - OK
*        >0 - Error
*
*  NOTES
*     MT-NOTE: var_list_parse_from_string() is MT safe
*******************************************************************************/
int var_list_parse_from_string(lList **lpp, const char *variable_str,
                               int check_environment)
{
   char *variable;
   char *val_str;
   int var_len;
   char **str_str;
   char **pstr;
   lListElem *ep;
   char *va_string;

   DENTER(TOP_LAYER, "var_list_parse_from_string");

   if (!lpp) {
      DEXIT;
      return 1;
   }

   va_string = sge_strdup(NULL, variable_str);
   if (!va_string) {
      *lpp = NULL;
      DEXIT;
      return 2;
   }
   str_str = string_list(va_string, ",", NULL);
   if (!str_str || !*str_str) {
      *lpp = NULL;
      sge_free(&va_string);
      DEXIT;
      return 3;
   }

   if (!*lpp) {
      *lpp = lCreateList("variable list", VA_Type);
      if (!*lpp) {
         sge_free(&va_string);
         sge_free(&str_str);
         DEXIT;
         return 4;
      }
   }

   for (pstr = str_str; *pstr; pstr++) {
      struct saved_vars_s *context;
      ep = lCreateElem(VA_Type);
      /* SGE_ASSERT(ep); */
      lAppendElem(*lpp, ep);

      context = NULL;
      variable = sge_strtok_r(*pstr, "=", &context);
      SGE_ASSERT((variable));
      var_len=strlen(variable);
      lSetString(ep, VA_variable, variable);
      val_str=*pstr;

      /* 
       * The character at the end of the first token must be either '=' or '\0'.
       * If it's a '=' then we treat the following string as the value 
       * If it's a '\0' and check_environment is set, then we get the value from
       * the environment variable value. 
       * If it's a '\0' and check_environment is not set, then we set the value
       * to NULL.
       */
      if (val_str[var_len] == '=') {
          lSetString(ep, VA_value, &val_str[var_len+1]);
      } else if (check_environment) {
         lSetString(ep, VA_value, sge_getenv(variable));
      } else {
         lSetString(ep, VA_value, NULL);
      }
      sge_free_saved_vars(context);
   }
   sge_free(&va_string);
   sge_free(&str_str);
   DRETURN(0);
}