Ejemplo n.º 1
0
Archivo: MGroup.c Proyecto: hocks/TSCC
int MGroupToString(

    mgcred_t *G,
    char     *Buf)

{
    const int CPCList[] = {
        mxoStats,
        -1
    };

    mxml_t *E = NULL;

    if ((G == NULL) || (Buf == NULL))
    {
        return(FAILURE);
    }

    Buf[0] = '\0';

    MCOToXML((void *)G,mxoGroup,&E,NULL,(int *)CPCList,0);

    MXMLToString(E,Buf,MAX_MBUFFER,NULL,TRUE);

    MXMLDestroyE(&E);

    return(SUCCESS);
}  /* END MGroupToString() */
Ejemplo n.º 2
0
int MAcctLoadCP(

    mgcred_t *AS, char *Buf)

{
    char tmpHeader[MAX_MNAME];
    char AName[MAX_MNAME];

    char *ptr;

    mgcred_t *A;

    long CkTime;

    mxml_t *E = NULL;

    const char *FName = "MAcctLoadCP";

    DBG(4, fCKPT) DPrint("%s(AS,%s)\n", FName, (Buf != NULL) ? Buf : "NULL");

    if (Buf == NULL) return (FAILURE);

    /* FORMAT:  <HEADER> <GID> <CKTIME> <GSTRING> */

    /* load CP header */

    sscanf(Buf, "%s %s %ld", tmpHeader, AName, &CkTime);

    if (((long)MSched.Time - CkTime) > MCP.CPExpirationTime) return (SUCCESS);

    if (AS == NULL) {
        if (MAcctAdd(AName, &A) != SUCCESS) {
            DBG(5, fCKPT)
            DPrint("ALERT:    cannot load CP account '%s'\n", AName);

            return (FAILURE);
        }
    } else {
        A = AS;
    }

    if ((ptr = strchr(Buf, '<')) == NULL) {
        return (FAILURE);
    }

    MXMLFromString(&E, ptr, NULL, NULL);

    MOFromXML((void *)A, mxoAcct, E);

    MXMLDestroyE(&E);

    return (SUCCESS);
} /* END MAcctLoadCP() */
Ejemplo n.º 3
0
int MRMStoreCP(

  mrm_t   *R,       /* I */
  char    *Buf,     /* O */
  int      BufSize) /* I */

  {
  const enum MRMAttrEnum DeltaRMAList[] = {
    mrmaJobCounter,
    mrmaSQLData,
    mrmaNONE };

  mxml_t *RME = NULL;

  if (Buf != NULL)
    Buf[0] = '\0';

  if ((R == NULL) || (Buf == NULL))
    {
    return(FAILURE);
    }

  MRMToXML(
    R,
    &RME,
    (enum MRMAttrEnum *)DeltaRMAList);

  if (MXMLToString(RME,Buf,BufSize,NULL,TRUE) == FAILURE)
    {
    MXMLDestroyE(&RME);

    return(FAILURE);
    }

  MXMLDestroyE(&RME);

  return(SUCCESS);
  }  /* END MRMStoreCP() */
Ejemplo n.º 4
0
int main(

  int  argc,  /* I */
  char **argv)  /* I */

  {
  struct batch_status  *bstatus = NULL;
  int                   con;
  char                 *specified_server = NULL;
  int                   errflg = 0;
  int                   i;
  extern char          *optarg;
  extern int            optind;
  char                **pa;

  struct batch_status  *pbstat;
  int                   flag = ALLI;
  char                 *note = NULL;
  enum  note_flags      note_flag = unused;
  char                **nodeargs = NULL;
  int                   lindex;

  enum NStateEnum ListType = tnsNONE;

  /* get default server, may be changed by -s option */

  progname = strdup(argv[0]);

  while ((i = getopt(argc, argv, "acdlopqrs:x-:N:n")) != EOF)
    {
    switch (i)
      {
      case 'a':

        flag = ALLI;

        break;

      case 'c':

        flag = CLEAR;

        break;

      case 'd':

        flag = DIAG;

        break;

      case 'l':

        flag = LIST;

        break;

      case 'o':

        flag = OFFLINE;

        break;

      case 'p':

        flag = PURGE;

        break;

      case 'q':

        quiet = 1;

        break;

      case 'r':

        flag = RESET;

        break;

      case 's':

        specified_server = optarg;

        break;

      case 'x':

        flag = ALLI;

        DisplayXML = TRUE;

        break;

      case 'N':

        /* preserve any previous option other than the default,
         * to allow -N to be combined with -o, -c, etc
         */

        if (flag == ALLI)
          flag = NOTE;

        note = strdup(optarg);

        if (note == NULL)
          {
          perror("Error: strdup() returned NULL");

          exit(1);
          }

        note_flag = set;

        /* -N n is the same as -N ""  -- it clears the note */

        if (!strcmp(note, "n"))
          *note = '\0';

        if (strlen(note) > MAX_NOTE)
          {
          fprintf(stderr, "Warning: note exceeds length limit (%d) - server may reject it...\n",
            MAX_NOTE);
          }

        if (strchr(note, '\n') != NULL)
          fprintf(stderr, "Warning: note contains a newline - server may reject it...\n");

        break;

      case 'n':

        note_flag = list;

        break;

      case '-':

        if ((optarg != NULL) && !strcmp(optarg, "version"))
          {
          fprintf(stderr, "Version: %s\nRevision: %s\n",
            PACKAGE_VERSION, SVN_VERSION);

          exit(0);
          }
        else if ((optarg != NULL) && !strcmp(optarg, "about"))
          {
          TShowAbout_exit();
          }

        errflg = 1;

        break;

      case '?':

      default:

        errflg = 1;

        break;
      }  /* END switch (i) */
    }    /* END while (i = getopt()) */

  if ((note_flag == list) && (flag != LIST))
    {
    fprintf(stderr, "Error: -n requires -l\n");
    errflg = 1;
    }

  for (pa = argv + optind;*pa;pa++)
    {
    if (strlen(*pa) == 0)
      {
      errflg = 1;
      }
    }

  if (errflg != 0)
    {
    if (!quiet)
      {
      fprintf(stderr, "usage:\t%s [-{c|d|l|o|p|r}] [-s server] [-n] [-N \"note\"] [-q] node ...\n",
              progname);

      fprintf(stderr, "\t%s [-{a|x}] [-s server] [-q] [node]\n",
              progname);
      }

    exit(1);
    }

  con = cnt2server(specified_server);

  if (con <= 0)
    {
    if (!quiet)
      {
      fprintf(stderr, "%s: cannot connect to server %s, error=%d (%s)\n",
        progname,
        (specified_server) ? specified_server : pbs_default(),
        con * -1,
        pbs_strerror(con * -1));
      }

    exit(1);
    }

  /* if flag is ALLI, LIST, get status of all nodes */

  if ((flag == ALLI) || (flag == LIST) || (flag == DIAG))
    {
    if ((flag == ALLI) || (flag == LIST) || (flag == DIAG))
      {
      if (flag == LIST)
        {
        /* allow state specification */

        if (argv[optind] != NULL)
          {

          for (lindex = 1;lindex < tnsLAST;lindex++)
            {
            if (!strcasecmp(NState[lindex], argv[optind]))
              {
              ListType = lindex;

              optind++;

              break;
              }
            }
          }
        }

      /* allow node specification (if none, then create an empty list) */

      if (argv[optind] != NULL)
        {
        nodeargs = argv + optind;
        }
      else
        {
        nodeargs = calloc(2, sizeof(char **));
        nodeargs[0] = strdup("");
        nodeargs[1] = '\0';
        }
      }
    }


  if ((note_flag == set) && (note != NULL))
    {
    /* set the note attrib string on specified nodes */

    for (pa = argv + optind;*pa;pa++)
      {
      set_note(con, *pa, note);
      }
    }

  switch (flag)
    {

    case DIAG:

      /* NYI */

      break;

    case CLEAR:

      /* clear  OFFLINE from specified nodes */

      for (pa = argv + optind;*pa;pa++)
        {
        marknode(con, *pa, ND_offline, DECR, NULL, DECR);
        }

      break;

    case RESET:

      /* clear OFFLINE, add DOWN to specified nodes */

      for (pa = argv + optind;*pa;pa++)
        {
        marknode(con, *pa, ND_offline, DECR, ND_down, INCR);
        }

      break;

    case OFFLINE:

      /* set OFFLINE on specified nodes */

      for (pa = argv + optind;*pa;pa++)
        {
        marknode(con, *pa, ND_offline, INCR, NULL, INCR);
        }

      break;

    case PURGE:

      /* remove node record */

      /* NYI */

      break;

    case ALLI:

      if (DisplayXML == TRUE)
        {

        char *tmpBuf = NULL, *tail = NULL;
        int  bufsize;

        mxml_t *DE;

        DE = NULL;

        MXMLCreateE(&DE, "Data");

        for (lindex = 0;nodeargs[lindex] != '\0';lindex++)
          {
          bstatus = statnode(con, nodeargs[lindex]);

          for (pbstat = bstatus;pbstat;pbstat = pbstat->next)
            {
            addxmlnode(DE, pbstat);
            }    /* END for (pbstat) */

          pbs_statfree(pbstat);
          }

        MXMLToXString(DE, &tmpBuf, &bufsize, INT_MAX, &tail, TRUE);

        MXMLDestroyE(&DE);

        fprintf(stdout, "%s\n",
                tmpBuf);
        }
      else
        {
        for (lindex = 0;nodeargs[lindex] != '\0';lindex++)
          {
          bstatus = statnode(con, nodeargs[lindex]);

          for (pbstat = bstatus;pbstat;pbstat = pbstat->next)
            {
            printf("%s\n",
                   pbstat->name);

            prt_node_attr(pbstat, 0);

            putchar('\n');
            }  /* END for (bpstat) */

          pbs_statfree(pbstat);
          }
        }

      break;

    case LIST:

      /* list any node that is DOWN, OFFLINE, or UNKNOWN */

      for (lindex = 0;nodeargs[lindex] != '\0';lindex++)
        {
        bstatus = statnode(con, nodeargs[lindex]);

        for (pbstat = bstatus;pbstat != NULL;pbstat = pbstat->next)
          {
          char *S;

          S = get_nstate(pbstat);

          if (filterbystate(pbstat, ListType, S))
            {
            char *n;

            if ((note_flag == list) && (n = get_note(pbstat)))
              {
              printf("%-20.20s %-26.26s %s\n",
                     pbstat->name,
                     S,
                     n);
              }
            else
              {
              printf("%-20.20s %s\n",
                     pbstat->name,
                     S);
              }
            }
          }

        pbs_statfree(pbstat);
        }

      break;
    }  /* END switch (flag) */

  pbs_disconnect(con);

  return(0);
  }  /* END main() */
Ejemplo n.º 5
0
Archivo: MGroup.c Proyecto: hocks/TSCC
int MGroupLoadCP(

    mgcred_t *GS,  /* I */
    char     *Buf) /* O */

{
    char    tmpHeader[MAX_MNAME];
    char    GName[MAX_MNAME];

    char   *ptr;

    mgcred_t *G;

    long    CkTime;

    mxml_t *E = NULL;

    const char *FName = "MGroupLoadCP";

    DBG(4,fCKPT) DPrint("%s(GS,%s)\n",
                        FName,
                        (Buf != NULL) ? Buf : "NULL");

    if (Buf == NULL)
    {
        return(FAILURE);
    }

    /* FORMAT:  <HEADER> <GID> <CKTIME> <GSTRING> */

    /* load CP header */

    sscanf(Buf,"%s %s %ld",
           tmpHeader,
           GName,
           &CkTime);

    if (((long)MSched.Time - CkTime) > MCP.CPExpirationTime)
    {
        return(SUCCESS);
    }

    if (GS == NULL)
    {
        if (MGroupAdd(GName,&G) != SUCCESS)
        {
            DBG(5,fCKPT) DPrint("ALERT:    cannot load CP group '%s'\n",
                                GName);

            return(FAILURE);
        }
    }
    else
    {
        G = GS;
    }

    if ((ptr = strchr(Buf,'<')) == NULL)
    {
        return(FAILURE);
    }

    MXMLFromString(&E,ptr,NULL,NULL);

    MOFromXML((void *)G,mxoGroup,E);

    MXMLDestroyE(&E);

    return(SUCCESS);
}  /* END MGroupLoadCP() */
Ejemplo n.º 6
0
int MXMLDestroyE(

  mxml_t **EP)  /* I (modified) */

  {
  int index;

  mxml_t *E;

  if (EP == NULL)
    {
    return(FAILURE);
    }

  E = *EP;

  if (E == NULL)
    {
    return(SUCCESS);
    }

  if (E->C != NULL)
    {
    /* destroy children */

    for (index = 0;index < E->CCount;index++)
      {
      if (E->C[index] == NULL)
        continue;

      MXMLDestroyE(&E->C[index]);
      }  /* END for (index) */

    free(E->C);
    }  /* END if (E->C != NULL) */

  /* free attributes */

  if (E->AName != NULL)
    {
    for (index = 0;index < E->ACount;index++)
      {
      if (E->AName[index] == NULL)
        break;

      free(E->AName[index]);

      if ((E->AVal != NULL) && (E->AVal[index] != NULL))
        free(E->AVal[index]);
      }  /* END for (index) */

    if (E->AVal != NULL)
      {
      free(E->AVal);
      }

    if (E->AName != NULL)
      {
      free(E->AName);
      }
    }    /* END if (E->AName != NULL) */

  /* free name */

  if (E->Name != NULL)
    free(E->Name);

  if (E->Val != NULL)
    free(E->Val);

  free(E);

  *EP = NULL;

  return(SUCCESS);
  }  /* END MXMLDestroyE() */
Ejemplo n.º 7
0
int MXMLFromString(

  mxml_t **EP,        /* O (populate or create) */
  char    *XMLString, /* I */
  char   **Tail,      /* O (optional) */
  char    *EMsg,      /* O (optional) */
  int      emsg_size) /* I */

  {
  mxml_t  *E;
  char    *ptr;

  char    *tail;

  int      index;

  mbool_t  ElementIsClosed = FALSE;

  mbool_t  DoAppend = FALSE;

  char tmpNLine[MMAX_LINE + 1];
  char tmpVLine[MMAX_XBUFFER + 1];

  if (EP != NULL)
    *EP = NULL;

  if (EMsg != NULL)
    EMsg[0] = '\0';

  if ((XMLString == NULL) || (EP == NULL))
    {
    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "invalid arguments");

    return(FAILURE);
    }

  if ((ptr = strchr(XMLString, '<')) == NULL)
    {
    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "no XML in string");

    return(FAILURE);
    }

  if (ptr[1] == '/')
    {
    /* located tail marker */

    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "premature termination marker");

    return(FAILURE);
    }

  /* NOTE:  should support append/overlay parameter (NYI) */

  /* ignore 'meta' elements */

  while ((ptr[1] == '?') || (ptr[1] == '!'))
    {
    ptr++;

    /* ignore 'meta' elements */

    if (*ptr == '?')
      {
      ptr++;

      if ((ptr = strstr(ptr, "?>")) == NULL)
        {
        /* cannot locate end of meta element */

        return(FAILURE);
        }

      if ((ptr = strchr(ptr, '<')) == NULL)
        {
        /* cannot locate next element */

        if (EMsg != NULL)
          snprintf(EMsg, emsg_size, "cannot locate post-meta XML");

        return(FAILURE);
        }
      }    /* END if (*ptr == '?') */

    /* ignore 'comment' element */

    if (!strncmp(ptr, "!--", 3))
      {
      ptr += 3;

      if ((ptr = strstr(ptr, "-->")) == NULL)
        {
        /* cannot locate end of comment element */

        if (EMsg != NULL)
          snprintf(EMsg, emsg_size, "cannot locate comment termination marker");

        return(FAILURE);
        }

      if ((ptr = strchr(ptr, '<')) == NULL)
        {
        /* cannot locate next element */

        if (EMsg != NULL)
          snprintf(EMsg, emsg_size, "cannot locate post-comment XML");

        return(FAILURE);
        }
      }    /* END if (!strncmp(ptr,"!--",3)) */
    }      /* END while ((ptr[1] == '?') || (ptr[1] == '!')) */

  /* remove whitespace */

  while (isspace(*ptr))
    ptr++;

  /* extract root element */

  if (*ptr != '<')
    {
    /* cannot located start of element */

    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "cannot locate start of root element");

    return(FAILURE);
    }

  ptr++;  /* ignore '<' */

  index = 0;

  while ((*ptr != ' ') && (*ptr != '>'))
    {
    if ((ptr[0] == '/') && (ptr[1] == '>'))
      {
      ElementIsClosed = TRUE;

      break;
      }

    tmpNLine[index++] = *(ptr++);

    if ((index >= MMAX_LINE) || (ptr[0] == '\0'))
      {
      if (EMsg != NULL)
        snprintf(EMsg, emsg_size, "element name is too long - %.10s", tmpNLine);

      return(FAILURE);
      }
    }

  tmpNLine[index] = '\0';

  if ((*EP == NULL) && (MXMLCreateE(EP, tmpNLine) == FAILURE))
    {
    if (EMsg != NULL)
      snprintf(EMsg, emsg_size, "cannot create XML element '%s'", tmpNLine);

    return(FAILURE);
    }

  E = *EP;

  if ((E->ACount > 0) || (E->CCount > 0))
    {
    DoAppend = TRUE;
    }

  if (ElementIsClosed == TRUE)
    {
    ptr += 2; /* skip '/>' */

    if (Tail != NULL)
      *Tail = ptr;

    return(SUCCESS);
    }

  while (*ptr == ' ')
    ptr++;

  while (*ptr != '>')
    {
    /* extract attributes */

    /* FORMAT:  <ATTR>="<VAL>" */

    index = 0;

    while ((*ptr != '=') && (*ptr != '\0'))
      {
      tmpNLine[index++] = *(ptr++);

      if (index >= MMAX_LINE)
        break;
      }

    tmpNLine[index] = '\0';

    if (*ptr != '\0')
      ptr++;  /* skip '=' */

    if (*ptr != '\0')
      ptr++;  /* skip '"' */

    if (*ptr == '\0')
      {
      if (EMsg != NULL)
        snprintf(EMsg, emsg_size, "string is corrupt - early termination");

      return(FAILURE);
      }

    index = 0;

    while ((*ptr != '"') ||
           ((ptr > XMLString) && (*(ptr - 1) == '\\')))
      {
      tmpVLine[index++] = *(ptr++);

      if ((index >= MMAX_XBUFFER) || (*ptr == '\0'))
        {
        MXMLDestroyE(EP);

        /* locate tail */

        if (Tail != NULL)
          *Tail = ptr + strlen(ptr);

        if (EMsg != NULL)
          {
          snprintf(EMsg, emsg_size, "attribute name is too long - %.10s", tmpVLine);
          }

        return(FAILURE);
        }
      }

    tmpVLine[index] = '\0';

    MXMLSetAttr(E,tmpNLine,(void *)tmpVLine,mdfString);

    ptr++; /* ignore '"' */

    while (*ptr == ' ')
      ptr++;

    if ((ptr[0] == '/') && (ptr[1] == '>'))
      {
      /* element terminator reached */

      ptr += 2; /* skip '/>' */

      if (Tail != NULL)
        *Tail = ptr;

      return(SUCCESS);
      }
    }  /* END while (*ptr != '>') */

  ptr++; /* ignore '>' */

  /* skip whitespace */

  while (isspace(*ptr))
    ptr++;

  /* extract value */

  if (*ptr != '<')
    {
    char *ptr2;

    index = 0;

    while (*ptr != '<')
      {
      tmpVLine[index++] = *(ptr++);

      if (index >= MMAX_XBUFFER)
        break;
      }

    tmpVLine[index] = '\0';

    E->Val = strdup(tmpVLine);

    if (E->Val == NULL)
      {
      if (EMsg != NULL)
        {
        snprintf(EMsg, emsg_size, "cannot alloc memory for value - %.10s", tmpVLine);
        }

      return(FAILURE);
      }

    /* restore '<' symbols */

    for (ptr2 = strchr(E->Val,(char)14);ptr2 != NULL;ptr2 = strchr(ptr2,(char)14))
      *ptr2 = '<';
    }  /* END if (*ptr != '<') */

  /* extract children */

  while (ptr[1] != '/')
    {
    mxml_t *C;

    C = NULL;

    if (DoAppend == TRUE)
      {
      char *ptr2;
      char  tmpCName[MMAX_NAME];

      int   index;

      /* FORMAT:  <NAME>... */

      /* locate name */

      ptr2 = ptr + 1;  /* ignore '<' */

      index = 0;

      while ((*ptr2 != ' ') && (*ptr2 != '>'))
        {
        if ((ptr2[0] == '/') && (ptr2[1] == '>'))
          {
          break;
          }

        tmpCName[index++] = *(ptr2++);

        if ((index >= MMAX_LINE) || (ptr2[0] == '\0'))
          {
          if (EMsg != NULL)
            {
            snprintf(EMsg, emsg_size, "element name is too long - %.10s", tmpCName);
            }
 
          return(FAILURE);
          }
        }

      tmpCName[index] = '\0';

      MXMLGetChild(E, tmpCName, NULL, &C);
      }

    if ((MXMLFromString(&C, ptr, &tail, EMsg, emsg_size) == FAILURE) ||
        (MXMLAddE(E, C) == FAILURE))
      {
      break;
      }

    ptr = tail;

    if ((ptr == NULL) || (ptr[0] == '\0'))
      {
      /* XML is corrupt */

      if (Tail != NULL)
        *Tail = ptr;

      if ((EMsg != NULL) && (EMsg[0] == '\0'))
        snprintf(EMsg, emsg_size, "cannot extract child");

      return(FAILURE);
      }
    }  /* END while (ptr[1] != '/') */

  /* ignore whitespace */

  while (isspace(*ptr))
    ptr++;

  /* process tail */

  if (*ptr == '/')
    {
    /* process '/>' */

    ptr++; /* ignore '/' */
    }
  else
    {
    ptr++; /* ignore '<' */

    ptr++; /* ignore '/' */

    ptr += strlen(E->Name);
    }

  ptr++; /* ignore '>' */

  if (Tail != NULL)
    *Tail = ptr;

  return(SUCCESS);
  }  /* END MXMLFromString() */
Ejemplo n.º 8
0
int MCPStoreResList(
 
  mckpt_t  *CP,
  mres_t  **RL)
 
  {
  int     rindex;

  mres_t *R;
 
  char   tmpBuf[MAX_MBUFFER];

  mxml_t *E = NULL;
 
  const char *FName = "MCPStoreResList";
 
  DBG(3,fCKPT) DPrint("%s(CP,RL)\n",
    FName);
 
  if ((CP == NULL) || (RL == NULL))
    {
    return(FAILURE);
    }
 
  for (rindex = 0;rindex < MAX_MRES;rindex++)
    {
    R = RL[rindex];
 
    if ((R == NULL) || (R->Name[0] == '\0'))
      break;
 
    if (R->Name[0] == '\1')
      {
      DBG(7,fCKPT) DPrint("INFO:     skipping empty reservation[%02d]\n",
        rindex);
 
      continue;
      } 
 
    /* ignore job and SR based reservations */
 
    if ((R->Type == mrtJob) || (R->Flags & (1 << mrfStandingRes)))
      {
      DBG(6,fCKPT) DPrint("INFO:     ignoring reservation[%02d] '%s'\n",
        rindex,
        R->Name);
 
      continue;
      }
 
    DBG(4,fCKPT) DPrint("INFO:     checkpointing Res[%02d] '%s'\n",
      rindex,
      R->Name);
 
    MXMLCreateE(&E,"res");
 
    MResToXML(R,E,NULL);
 
    MXMLToString(E,tmpBuf,MAX_MBUFFER,NULL,TRUE);
 
    MXMLDestroyE(&E);

    MCPStoreObj(CP->fp,mcpRes,R->Name,tmpBuf); 
    }    /* END for (rindex) */
 
  return(SUCCESS);
  }  /* END MCPStoreResList() */
Ejemplo n.º 9
0
Archivo: MMB.c Proyecto: dhh1128/cbase
int MMBFromString(

  char   *Buf,  /* I */
  mmb_t **MBP)  /* O (alloc) */

  {
  int CTok;

  mxml_t *E = NULL;
  mxml_t *ME;

  char tmpLine[MMAX_LINE << 1];
  char Owner[MMAX_NAME];
  char Label[MMAX_NAME];

  int count;
  int priority;

  mmb_t *tmpMB;

  enum MMBTypeEnum type;

  mulong etime;

  char *ptr;

  /* NOTE:  sync w/MMBFromXML() */
 
  if ((Buf == NULL) || (MBP == NULL))
    {
    return(FAILURE);
    }

  if (MXMLFromString(&E,Buf,NULL,NULL) == FAILURE)
    {
    return(FAILURE);
    }

  CTok = -1;

  while (MXMLGetChild(E,"message",&CTok,&ME) == SUCCESS)
    {
    if (MXMLGetAttr(ME,(char *)MMBAttr[mmbaCount],NULL,tmpLine,sizeof(tmpLine)) == SUCCESS)
      {
      count = (int)strtol(tmpLine,NULL,10);
      }
    else
      {
      count = 1;
      }

    if (MXMLGetAttr(ME,(char *)MMBAttr[mmbaPriority],NULL,tmpLine,sizeof(tmpLine)) == SUCCESS)
      {
      priority = (int)strtol(tmpLine,NULL,10);
      }
    else
      {
      priority = 1;
      }

    MXMLGetAttr(ME,(char *)MMBAttr[mmbaType],NULL,tmpLine,sizeof(tmpLine));

    type = (enum MMBTypeEnum)MUGetIndexCI(tmpLine,MMBType,FALSE,mmbtNONE);

    if (MXMLGetAttr(ME,(char *)MMBAttr[mmbaExpireTime],NULL,tmpLine,sizeof(tmpLine)) == SUCCESS)
      {
      etime = strtol(tmpLine,NULL,10);
      }
    else
      {
      etime = MSched.Time + MCONST_DAYLEN;
      }

    if (MXMLGetAttr(ME,(char *)MMBAttr[mmbaOwner],NULL,Owner,sizeof(Owner)) == FAILURE)
      strcpy(Owner,"N/A");

    MXMLGetAttr(ME,(char *)MMBAttr[mmbaLabel],NULL,Label,sizeof(Label));

    if (MXMLGetAttr(ME,(char *)MMBAttr[mmbaData],NULL,tmpLine,sizeof(tmpLine)) == FAILURE)
      {
      MXMLDestroyE(&E);

      return(FAILURE);
      }

    ptr = tmpLine;

    /* NOTE:  restore checkpoint newlines - sync w/MJobToXML() */

    while ((ptr = strchr(ptr,'\7')) != NULL)
      {
      *ptr = '\n';
      }

    MXMLDestroyE(&E);

    if (MMBAdd(
          MBP,
          tmpLine,  /* I */
          Owner,
          type,
          etime,
          priority,
          &tmpMB) == FAILURE)
      {
      return(FAILURE);
      }

    if (count > 1)
      MMBSetAttr(tmpMB,mmbaCount,(void *)&count,mdfInt);

    if (Label[0] != '\0')
      MUStrDup(&tmpMB->Label,Label);
    }    /* END while (MXMLGetChild() == SUCCESS) */

  return(SUCCESS);
  }  /* END MMBFromString() */
Ejemplo n.º 10
0
Archivo: MMB.c Proyecto: dhh1128/cbase
char *MMBPrintMessages(

  mmb_t               *Head,        /* I (optional) */
  enum MFormatModeEnum DFormat,     /* I */
  mbool_t              ShowVerbose, /* I */
  int                  MinPrio,     /* I (only display messages of this priority or higher) */
  char                *Buf,         /* O (optional,char * or mxml_t *) */
  int                  BufSize)     /* I */

  {
  mmb_t *mptr;

  char *BPtr = NULL;
  int   BSpace;

  char *hptr = NULL;

  static char tmpMBuf[MMAX_BUFFER];

  char  tmpLine[MMAX_LINE << 2];
  char  tmpLine2[MMAX_LINE << 2];

  if (Buf != NULL)
    {
    BPtr = Buf;
    BSpace = BufSize;
    }
  else
    {
    BPtr = tmpMBuf;
    BSpace = sizeof(tmpMBuf);
    }

  hptr = BPtr;

  switch (DFormat)
    {
    case mfmXML:
    case mfmAVP:  /* KLUDGE - use AVP to create packed XML data */

      {
      mxml_t *DE;
      mxml_t *CE;
      mxml_t *UE;

      int     count = 0;

      DE = (mxml_t *)Buf;

      if (DE == NULL)
        break;

      if (Head == NULL)
        {
        /* header not required in XML */

        break;
        }  /* END if (Head == NULL) */

      if (DFormat == mfmAVP)
        {
        /* initialize temporary parent XML element */

        UE = NULL;
        }
    
      for (mptr = Head;mptr != NULL;mptr = mptr->Next)
        {
        if (mptr->Priority < MinPrio)
          continue;

        CE = NULL;

        MXMLCreateE(&CE,"message");

        MXMLSetAttr(CE,"index",(void *)&count,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaCTime],(void *)&mptr->CTime,mdfLong);

        if (mptr->Owner != NULL)
          MXMLSetAttr(CE,(char *)MMBAttr[mmbaOwner],(void *)mptr->Owner,mdfString);

        MXMLSetAttr(CE,(char *)MMBAttr[mmbaPriority],(void *)&mptr->Priority,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaCount],(void *)&mptr->Count,mdfInt);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaExpireTime],(void *)&mptr->ExpireTime,mdfLong);
        MXMLSetAttr(CE,(char *)MMBAttr[mmbaType],(void *)MMBType[mptr->Type],mdfString);

        if (mptr->Data != NULL)
          {
          if (strchr(mptr->Data,'\n') != NULL)
            {
            char tmpData[MMAX_BUFFER];

            MUStrCpy(tmpData,mptr->Data,sizeof(tmpData));

            MUStrReplaceChar(tmpData,'\n',' ',FALSE);

            MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)tmpData,mdfString);
            }
          else
            { 
            MXMLSetAttr(CE,(char *)MMBAttr[mmbaData],(void *)mptr->Data,mdfString);
            }
          }

        if (mptr->Label != NULL)
          MXMLSetAttr(CE,(char *)MMBAttr[mmbaLabel],(void *)mptr->Label,mdfString);

        if (DFormat == mfmAVP)
          {
          /* create/update temporary XML */

          if (UE == NULL)
            MXMLCreateE(&UE,(char*) MSON[msonData]);

          MXMLAddE(UE,CE);
          }
        else
          {
          MXMLAddE(DE,CE);
          }

        count++;
        }  /* END for (mptr) */

      if ((DFormat == mfmAVP) && (UE != NULL))
        {
        /* NOTE:  Buf is mxml_t *, do not populate */

        MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf));

        hptr = BPtr;

        MXMLToString(UE,tmpLine,sizeof(tmpLine),NULL,TRUE);

        MXMLDestroyE(&UE);

        MUStringPack(tmpLine,tmpLine2,sizeof(tmpLine2));

        MUSNCat(&BPtr,&BSpace,tmpLine2);
        }
      }    /* END BLOCK */

      break;

    case mfmHuman:
    default:

      {
      int count = 0;

      char tmpBuf[MMAX_NAME];
      char label[MMAX_NAME];

      if (Buf != NULL)
        MUSNInit(&BPtr,&BSpace,Buf,BufSize);
      else
        MUSNInit(&BPtr,&BSpace,tmpMBuf,sizeof(tmpMBuf));

      hptr = BPtr;

      if (Head == NULL)
        {
        if (ShowVerbose == TRUE)
          {
          MUSNPrintF(&BPtr,&BSpace,"%-7s %10s %10s %8.8s %4.4s %3.3s %s\n",
            "Label",
            "CreateTime",
            "ExpireTime",
            "Owner",
            "Prio",
            "Num",
            "Message");
          }

        break;
        }  /* END if (Head == NULL) */

      for (mptr = Head;mptr != NULL;mptr = mptr->Next)
        {
        if (mptr->Priority < MinPrio)
          continue;

        if (mptr->Label != NULL)
          {
          strncpy(label,mptr->Label,sizeof(label));
          }
        else
          {
          sprintf(label,"%d",
            count);
          }

        count++;

        if (ShowVerbose == TRUE)
          {
          char TString[MMAX_LINE];
          /* display w/relative time */

          MULToTString(mptr->CTime - MSched.Time,TString);

          strcpy(tmpBuf,TString);

          MULToTString(mptr->ExpireTime - MSched.Time,TString);

          MUSNPrintF(&BPtr,&BSpace,"%-8.8s %10s %10s %8.8s %4d %3d %s\n",
            label,
            tmpBuf,
            TString,
            (mptr->Owner != NULL) ? mptr->Owner : "N/A",
            mptr->Priority,
            mptr->Count,
            (mptr->Data != NULL) ? mptr->Data : "-");
          }
        else
          {
          if (mptr->Source != NULL)
            {
            MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] (from %s) %s\n",
              label,
              mptr->Source,
              (mptr->Data != NULL) ? mptr->Data : "-");
            }
          else
            {
            MUSNPrintF(&BPtr,&BSpace,"Message[%.8s] %s\n",
              label,
              (mptr->Data != NULL) ? mptr->Data : "-");
            }
          }
        }  /* END for (mptr) */
      }    /* END BLOCK (case mfmHuman) */

      break;
    }  /* END switch (DFormat) */

  return(hptr);
  }  /* END MMBPrintMessages() */
Ejemplo n.º 11
0
int MClassLoadCP(

  mclass_t *CS,
  char     *Buf)

  {
  char    tmpHeader[MAX_MNAME];
  char    CName[MAX_MNAME];

  char   *ptr;

  mclass_t *C;

  long    CkTime;

  mxml_t *E = NULL;

  const char *FName = "MClassLoadCP";

  DBG(4,fCKPT) DPrint("%s(CS,%s)\n",
    FName,
    (Buf != NULL) ? Buf : "NULL");

  if (Buf == NULL)
    {
    return(FAILURE);
    }

  /* FORMAT:  <HEADER> <GID> <CKTIME> <GSTRING> */

  /* load CP header */

  sscanf(Buf,"%s %s %ld",
    tmpHeader,
    CName,
    &CkTime);

  if (((long)MSched.Time - CkTime) > MCP.CPExpirationTime)
    {
    return(SUCCESS);
    }

  if (CS == NULL)
    {
    if (MClassAdd(CName,&C) != SUCCESS)
      {
      DBG(5,fCKPT) DPrint("ALERT:    cannot load CP class '%s'\n",
        CName);

      return(FAILURE);
      }
    }
  else
    {
    C = CS;
    }

  if ((ptr = strchr(Buf,'<')) == NULL)
    {
    return(FAILURE);
    }

  MXMLCreateE(&E,(char *)MXO[mxoClass]);

  MXMLFromString(&E,ptr,NULL,NULL);

  MOFromXML((void *)C,mxoClass,E);

  MXMLDestroyE(&E);

  return(SUCCESS);
  }  /* END MClassLoadCP() */
Ejemplo n.º 12
0
int __MSysTestXML(
 
  char *XMLString)  /* I */

  {
  char *tail;

  FILE *fp;

  mxml_t *E = NULL;

  char EMsg[MMAX_LINE];

  char buffer[MMAX_BUFFER << 3];

  if ((XMLString != NULL) && (XMLString[0] != '\0'))
    {
    if (XMLString[0] == '/')
      {
      int rc;

      fp = fopen(XMLString,"r");

      rc = fread((void *)buffer,sizeof(buffer),1,fp);

      XMLString = buffer;

      fprintf(stdout,"read in %d\n",rc);
      }

    fprintf(stdout,"XMLString: '%s'\n\n",
      XMLString);
  
    if (MXMLFromString(&E,XMLString,&tail,EMsg) == FAILURE)
      {
      fprintf(stderr,"ERROR: '%s'\n",
        EMsg);
  
      exit(1);
      }
  
    if (tail != NULL)
      {
      fprintf(stdout,"tail: '%s'\n\n",
        XMLString);
      }

    exit(0);
    }

  MXMLCreateE(&E,"Data");
  MXMLSetAttr(E,"Value",(void *)"this >> that",mdfString);

  MXMLToString(E,EMsg,sizeof(EMsg),NULL,TRUE);

  fprintf(stdout,"XML = '%s'\n\n",
    EMsg);

  MXMLDestroyE(&E);

  MXMLFromString(&E,EMsg,NULL,NULL);

  fprintf(stdout,"After MXMLFromString: <Data %s=\"%s\"></Data>\n\n",
    E->AName[0],
    E->AVal[0]);

  EMsg[0] = '\0';

  MXMLToString(E,EMsg,sizeof(EMsg),NULL,TRUE);

  fprintf(stdout,"XML = '%s'\n\n",
    EMsg);

  exit(1);

  /* NOTREACHED */

  return(SUCCESS);
  }  /* END __MSysTestXML() */
Ejemplo n.º 13
0
int MUIRsvDiagnose(

  mbitmap_t *AFlagBM,
  char      *Auth,
  mrsv_t    *SR,
  mstring_t *String,
  mpar_t    *P,
  char      *DiagOpt,
  enum MFormatModeEnum DFormat,
  mbitmap_t *Flags,
  enum MRsvTypeEnum ResType)

  {
  rsv_iter RTI;

  int nindex;

  mnode_t *N;
  mjob_t  *J;

  int   TotalRC;
  int   TotalRsvStatePC;
  int   TotalRsvAPC;

  mrsv_t *R;

  mxml_t *DE = NULL;
  mxml_t *RE = NULL;

  mbool_t IsAdmin;

  mgcred_t *U;

  const char *FName = "MUIRsvDiagnose";

  MDB(3,fUI) MLog("%s(Auth,String,%s,%s,%s,%s)\n",
    FName,
    (P != NULL) ? P->Name : "NULL",
    DiagOpt,
    MFormatMode[DFormat],
    MRsvType[ResType]);

  if (String == NULL)
    {
    return(FAILURE);
    }

  /* check all reservations */

  MDB(4,fUI) MLog("INFO:     diagnosing rsv table (%d slots)\n",
    MSched.M[mxoRsv]);

  if (DFormat == mfmXML)
    {
    /* NOTE:  do not wrap specific rsv requests in Data element */

    if (SR == NULL)
      {
      DE = NULL;

      MXMLCreateE(&DE,(char *)MSON[msonData]);
      }
    }
  else
    {
    /* create header */

    MStringAppend(String,"Diagnosing Reservations\n");

    MRsvShowState(
      NULL,
      Flags,
      NULL,
      String,
      DFormat);
    }

  /* initialize statistics */

  TotalRC = 0;

  TotalRsvAPC     = 0;
  TotalRsvStatePC = 0;

  for (nindex = 0;nindex < MSched.M[mxoNode];nindex++)
    {
    N = MNode[nindex];

    if ((N == NULL) || (N->Name[0] == '\0'))
      break;

    if (N->Name[0] == '\1')
      continue;

    if (N->State == mnsReserved)
      TotalRsvStatePC += N->CRes.Procs;
    }  /* END for (nindex) */

  if (bmisset(AFlagBM,mcalAdmin1) ||
      bmisset(AFlagBM,mcalAdmin2) ||
      bmisset(AFlagBM,mcalAdmin3))
    IsAdmin = TRUE;
  else
    IsAdmin = FALSE;

  MUserAdd(Auth,&U);

  MRsvIterInit(&RTI);

  while (MRsvTableIterate(&RTI,&R) == SUCCESS)
    {
    if ((SR != NULL) && (R != SR))
      continue;

    if ((P != NULL) && (P->Index > 0) && (P->Index != R->PtIndex))
      continue;

    if (strcmp(DiagOpt,NONE) && strcmp(DiagOpt,R->Name))
      {
      if ((R->Label == NULL) || strcmp(DiagOpt,R->Label)) 
        continue;
      }

    /* If a ResType is given (-w type=ResType) and it is not equal to this reservation's type, don't print */

    if ((ResType != mrtNONE) && (R->Type != ResType))
      continue;

    if (!bmisset(AFlagBM,mcalOwner) && (IsAdmin == FALSE))
      { 
      if (MUICheckAuthorization(
            U,
            NULL,
            (void *)R,
            mxoRsv,
            mcsDiagnose,
            mrcmQuery,
            NULL,
            NULL,
            0) == FAILURE)
        {
        /* no authority to diagnose reservation */

        continue;
        }
      }

    MDB(6,fUI) MLog("INFO:     evaluating Rsv '%s'\n",
      R->Name);

    if (DFormat == mfmXML)
      {
      RE = NULL;

      MXMLCreateE(&RE,(char *)MXO[mxoRsv]);

      if (SR == NULL)
        MXMLAddE(DE,RE);

      MRsvShowState(
        R,
        Flags,
        RE,  /* O */
        NULL,
        DFormat);
      }
    else
      {
      MRsvShowState(
        R,
        Flags,
        NULL, 
        String,
        DFormat);

      MRsvDiagnoseState(
        R,
        Flags,
        NULL,
        String,
        DFormat);
      }  /* END else (DFormat == mfmXML) */

    TotalRC++;

    if ((R->J != NULL) && ((R->Type == mrtJob) || (R->Type == mrtUser)))
      {
      /* determine allocated jobs associated with system jobs (user rsv) or regular jobs */

      J = R->J;

      if (MJOBISACTIVE(J))
        TotalRsvAPC += R->AllocPC;
      }

    if (SR != NULL)
      break;
    }  /* END while (MRsvTableIterate()) */

  if ((!strcmp(DiagOpt,NONE)) && !bmisset(AFlagBM,mcalOwner))
    {
    /* set global diagnostic messages */

    if (DFormat != mfmXML)
      {
      char *BPtr;
      int   BSpace;

      char MsgBuf[MMAX_BUFFER];

      MUSNInit(&BPtr,&BSpace,MsgBuf,sizeof(MsgBuf));

      MStringAppendF(String,"\nActive Reserved Processors: %d\n",
        TotalRsvAPC);

      if ((TotalRsvAPC + TotalRsvStatePC) != MPar[0].DRes.Procs)
        {
        MStringAppendF(String,"INFO:  active procs reserved does not equal active procs utilized (%d != %d)\n",
          TotalRsvAPC + TotalRsvStatePC,
          MPar[0].DRes.Procs);
        }

      MRsvDiagGrid(BPtr,BSpace,0);

      MStringAppend(String,MsgBuf);
      }  /* END if (DFormat != mfmXML) */
    }    /* END if (!strcmp(DiagOpt,NONE) */

  if (DFormat == mfmXML)
    {
    /* make into XML encoded string */

    if (MXMLToMString(
        (SR == NULL) ? DE : RE,
        String,
        NULL,
        TRUE) == FAILURE)
      {
      MDB(2,fUI) MLog("ALERT:    could not convert XML to string in %s\n",
        FName);
      }

    MXMLDestroyE(
      (SR == NULL) ? &DE : &RE);
    }  /* END if (DFormat == mfmXML) */

  return(SUCCESS);
  }  /* END MUIRsvDiagnose() */
Ejemplo n.º 14
0
int MRMLoadCP(

  mrm_t *RS,    /* I (optional) */
  const char  *Buf)   /* I */

  {
  char   tmpName[MMAX_NAME + 1];
  char   RMID[MMAX_NAME + 1];

  mrm_t *R;

  mrm_t  tmpR;

  mxml_t *RME;

  /* If you get a seg fault here, increase stacksize with ulimit -s unlimited */
  long    CkTime = 0;

  const char   *ptr;

  const char *FName = "MRMLoadCP";

  MDB(4,fSTRUCT) MLog("%s(%s,%s)\n",
    FName,
    (RS != NULL) ? "RS" : "NULL",
    (Buf != NULL) ? Buf : "NULL");

  if (Buf == NULL)
    {
    return(FAILURE);
    }

  /* FORMAT:  <OTYPE> <OID> <CKTIME> <ODATA> */

  /* determine rm ID */

  sscanf(Buf,"%64s %64s %ld",
    tmpName,
    RMID,
    &CkTime);

  if (((long)MSched.Time - CkTime) > (long)MCP.CPExpirationTime)
    {
    MDB(7,fSTRUCT) MLog("INFO:     checkpoint info expired for RM %s\n",
      RMID);

    return(SUCCESS);
    }

  if (RS == NULL)
    {
    if (MRMFind(RMID,&R) == SUCCESS)
      {
      /* ignore existing RM's if not explicitly specified */

      return(SUCCESS);
      }

    /* rm may be dynamic, load into temp buffer */

    memset(&tmpR,0,sizeof(tmpR));

    R = &tmpR;
    }
  else
    {
    R = RS;
    }

  if ((ptr = strchr(Buf,'<')) == NULL)
    {
    MDB(4,fSTRUCT) MLog("WARNING:  malformed XML data for RM %s\n",
      RMID);

    return(FAILURE);
    }

  RME = NULL;

  if ((MXMLFromString(&RME,ptr,NULL,NULL) == FAILURE) ||
      (MRMFromXML(R,RME) == FAILURE))
    {
    MXMLDestroyE(&RME);

    /* cannot load rm */

    MDB(4,fSTRUCT) MLog("WARNING:  XML cannot be processed for RM %s\n",
      RMID);

    return(FAILURE);
    }

  MXMLDestroyE(&RME);

  return(SUCCESS);
  }  /* END MRMLoadCP() */