Пример #1
0
/****** pack_job_delivery/pack_job_delivery() **********************************
*  NAME
*     pack_job_delivery() -- pack a job to be sent to execd
*
*  SYNOPSIS
*     int pack_job_delivery(sge_pack_buffer *pb, lListElem *jep, lList *qlp, 
*     lListElem *pep) 
*
*  FUNCTION
*     This function is used in qmaster and by qrsh -inherit to deliver
*     jobs to execd's.
*
*  INPUTS
*     sge_pack_buffer *pb - packing buffer
*     lListElem *jep      - JB_Type
*
*  RESULT
*     int - PACK_SUCCESS on success
*
*  NOTES
*     MT-NOTE: pack_job_delivery() is MT safe
*******************************************************************************/
int pack_job_delivery(sge_pack_buffer *pb, lListElem *jep)
{
   int ret;

   if ((ret=packint(pb, feature_get_active_featureset_id()))) {
      return ret;  
   }
   if ((ret=cull_pack_elem(pb, jep)) != PACK_SUCCESS) {
      return ret;
   }
   return PACK_SUCCESS;
}
/****** gdi/request_internal/sge_gdi_packet_pack_task() **********************
*  NAME
*     sge_gdi_packet_pack_task() -- pack a single GDI task 
*
*  SYNOPSIS
*     bool 
*     sge_gdi_packet_pack_task(sge_gdi_packet_class_t * packet, 
*                              sge_gdi_task_class_t * task, 
*                              lList **answer_list, 
*                              sge_pack_buffer *pb) 
*
*  FUNCTION
*     This functions packs all data representing one GDI request
*     of a mutli GDI request (represented by "packet" and "task")
*     into "pb". Errors will be reported with a corresponding
*     "answer_list" message and a negative return value.
*
*     "pb" has to be initialized before this function is called.
*     init_packbuffer() or a similar function has do be used to
*     initialize this "pb". The function sge_gdi_packet_get_pb_size()
*     might be used to calculate the maximum size as if the buffer
*     would be needed to pack all tasks of a multi GDI request. 
*     Using this size as initial size for the "pb"
*     will prevent continuous reallocation of memory in this 
*     function.
*
*  INPUTS
*     sge_gdi_packet_class_t * packet - GDI packet 
*     sge_gdi_task_class_t * task     - GDI task 
*     lList **answer_list             - answer_list 
*     sge_pack_buffer *pb             - packing buffer 
*
*  RESULT
*     bool - error state
*        true  - success
*        false - failure 
*
*  NOTES
*     MT-NOTE: sge_gdi_packet_pack_task() is MT safe 
*
*  SEE ALSO
*     gdi/request_internal/sge_gdi_packet_get_pb_size() 
*     gdi/request_internal/sge_gdi_packet_pack() 
*******************************************************************************/
bool
sge_gdi_packet_pack_task(sge_gdi_packet_class_t *packet,
                         sge_gdi_task_class_t *task, lList **answer_list,
                         sge_pack_buffer *pb)
{
   bool ret = true;
   int pack_ret = PACK_SUCCESS;

   DENTER(TOP_LAYER, "sge_gdi_packet_pack_task");

   if ((task != NULL) && (packet != NULL)
       && (packet->is_intern_request == false)) {
      sge_pack_gdi_info(task->command);

      /* ===> pack the prefix */
      pack_ret = packint(pb, task->command);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = packint(pb, task->target);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = packint(pb, packet->version);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }

      /* 
       * if the lSelect call was postponed then it will be done here.
       * here we are able to pack the result list directly into the packbuffer.
       * additionally it is necessary to add an answer to the answer list.
       * (which will be packed below). 
       */
      if (task->do_select_pack_simultaneous) {
         lSelectHashPack("", task->data_list, task->condition,
                         task->enumeration, false, pb);
         lFreeWhat(&(task->enumeration));
         lFreeWhere(&(task->condition));
         task->data_list = NULL;

         /* DIRTY HACK: The "ok" message should be removed from the answer list
          * 05/21/2007 qualitiy was ANSWER_QUALITY_INFO but this results in "ok"
          * messages on qconf side */
         answer_list_add(&(task->answer_list), MSG_GDI_OKNL, STATUS_OK,
                         ANSWER_QUALITY_END);
      } else {
         /* ===> pack the list */
         pack_ret = cull_pack_list(pb, task->data_list);
         if (pack_ret != PACK_SUCCESS) {
            goto error_with_mapping;
         }
      }

      /* ===> pack the suffix */
      pack_ret = cull_pack_list(pb, task->answer_list);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = cull_pack_cond(pb, task->condition);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = cull_pack_enum(pb, task->enumeration);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = packstr(pb, packet->auth_info);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = packint(pb, task->id);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = packint(pb, packet->id);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
      pack_ret = packint(pb, (task->next != NULL) ? 1 : 0);
      if (pack_ret != PACK_SUCCESS) {
         goto error_with_mapping;
      }
   }

   DRETURN(ret);
 error_with_mapping:
   ret = sge_gdi_map_pack_errors(pack_ret, answer_list);
   DRETURN(ret);
}
Пример #3
0
static int str_pack (lua_State *L) {
  luaL_Buffer b;
  Header h;
  const char *fmt = luaL_checkstring(L, 1);  /* format string */
  int arg = 1;  /* current argument to pack */
  size_t totalsize = 0;  /* accumulate total size of result */
  initheader(L, &h);
  lua_pushnil(L);  /* mark to separate arguments from string buffer */
  luaL_buffinit(L, &b);
  while (*fmt != '\0') {
    int size, ntoalign;
    KOption opt = getdetails(&h, totalsize, &fmt, &size, &ntoalign);
    totalsize += ntoalign + size;
    while (ntoalign-- > 0)
     luaL_addchar(&b, LUAL_PACKPADBYTE);  /* fill alignment */
    arg++;
    switch (opt) {
      case Kint: {  /* signed integers */
        lua_Integer n = luaL_checkinteger(L, arg);
        if (size < SZINT) {  /* need overflow check? */
          lua_Integer lim = (lua_Integer)1 << ((size * NB) - 1);
          luaL_argcheck(L, -lim <= n && n < lim, arg, "integer overflow");
        }
        packint(&b, (lua_Unsigned)n, h.islittle, size, (n < 0));
        break;
      }
      case Kuint: {  /* unsigned integers */
        lua_Integer n = luaL_checkinteger(L, arg);
        if (size < SZINT)  /* need overflow check? */
          luaL_argcheck(L, (lua_Unsigned)n < ((lua_Unsigned)1 << (size * NB)),
                           arg, "unsigned overflow");
        packint(&b, (lua_Unsigned)n, h.islittle, size, 0);
        break;
      }
      case Kfloat: {  /* floating-point options */
        volatile Ftypes u;
        char *buff = luaL_prepbuffsize(&b, size);
        lua_Number n = luaL_checknumber(L, arg);  /* get argument */
        if (size == sizeof(u.f)) u.f = (float)n;  /* copy it into 'u' */
        else if (size == sizeof(u.d)) u.d = (double)n;
        else u.n = n;
        /* move 'u' to final result, correcting endianness if needed */
        copywithendian(buff, u.buff, size, h.islittle);
        luaL_addsize(&b, size);
        break;
      }
      case Kchar: {  /* fixed-size string */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len);
        luaL_argcheck(L, len <= (size_t)size, arg,
                         "string longer than given size");
        luaL_addlstring(&b, s, len);  /* add string */
        while (len++ < (size_t)size)  /* pad extra space */
          luaL_addchar(&b, LUAL_PACKPADBYTE);
        break;
      }
      case Kstring: {  /* strings with length count */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len);
        luaL_argcheck(L, size >= (int)sizeof(size_t) ||
                         len < ((size_t)1 << (size * NB)),
                         arg, "string length does not fit in given size");
        packint(&b, (lua_Unsigned)len, h.islittle, size, 0);  /* pack length */
        luaL_addlstring(&b, s, len);
        totalsize += len;
        break;
      }
      case Kzstr: {  /* zero-terminated string */
        size_t len;
        const char *s = luaL_checklstring(L, arg, &len);
        luaL_argcheck(L, strlen(s) == len, arg, "string contains zeros");
        luaL_addlstring(&b, s, len);
        luaL_addchar(&b, '\0');  /* add zero at the end */
        totalsize += len + 1;
        break;
      }
      case Kpadding: luaL_addchar(&b, LUAL_PACKPADBYTE);  /* FALLTHROUGH */
      case Kpaddalign: case Knop:
        arg--;  /* undo increment */
        break;
    }
  }
  luaL_pushresult(&b);
  return 1;
}