Exemplo n.º 1
0
void req_reject(

  int                   code,      /* I */
  int                   aux,       /* I */
  struct batch_request *preq,      /* I */
  char                 *HostName,  /* I (optional) */
  char                 *Msg)       /* I (optional) */

  {
  char msgbuf[ERR_MSG_SIZE + 256 + 1];
  char msgbuf2[ERR_MSG_SIZE + 256 + 1];

  set_err_msg(code, msgbuf);

  snprintf(msgbuf2, sizeof(msgbuf2), "%s", msgbuf);

  if ((HostName != NULL) && (*HostName != '\0'))
    {
    snprintf(msgbuf, sizeof(msgbuf), "%s REJHOST=%s",
             msgbuf2,
             HostName);

    snprintf(msgbuf2, sizeof(msgbuf2), "%s", msgbuf);
    }

  if ((Msg != NULL) && (*Msg != '\0'))
    {
    snprintf(msgbuf, sizeof(msgbuf), "%s MSG=%s",
             msgbuf2,
             Msg);

    /* NOTE: Don't need this last snprintf() unless another message is concatenated. */
    }

  sprintf(log_buffer, "Reject reply code=%d(%s), aux=%d, type=%s, from %s@%s",

          code,
          msgbuf,
          aux,
          reqtype_to_txt(preq->rq_type),
          preq->rq_user,
          preq->rq_host);

  LOG_EVENT(
    PBSEVENT_DEBUG,
    PBS_EVENTCLASS_REQUEST,
    "req_reject",
    log_buffer);

  preq->rq_reply.brp_auxcode = aux;

  reply_text(preq, code, msgbuf);

  return;
  }  /* END req_reject() */
Exemplo n.º 2
0
void test_set_err_msg(void **state)
{
    struct extdom_req *req;
    struct test_data *test_data;

    test_data = (struct test_data *) *state;
    req = test_data->req;

    assert_null(req->err_msg);

    set_err_msg(NULL, NULL);
    assert_null(req->err_msg);

    set_err_msg(req, NULL);
    assert_null(req->err_msg);

    set_err_msg(req, "Test [%s][%d].", "ABCD", 1234);
    assert_non_null(req->err_msg);
    assert_string_equal(req->err_msg, "Test [ABCD][1234].");

    set_err_msg(req, "2nd Test [%s][%d].", "ABCD", 1234);
    assert_non_null(req->err_msg);
    assert_string_equal(req->err_msg, "Test [ABCD][1234].");
}
Exemplo n.º 3
0
void reply_badattr(

  int                   code,
  int                   aux,
  svrattrl        *pal,
  struct batch_request *preq)

  {
  int   i = 1;
  char  msgbuf[ERR_MSG_SIZE+1];

  set_err_msg(code, msgbuf);

  while (pal)
    {
    if (i == aux)
      {
      strcat(msgbuf, " ");
      strcat(msgbuf, pal->al_name);

      if (pal->al_resc)
        {
        strcat(msgbuf, ".");
        strcat(msgbuf, pal->al_resc);
        }

      break;
      }

    pal = (svrattrl *)GET_NEXT(pal->al_link);

    ++i;
    }

  reply_text(preq, code, msgbuf);

  return;
  }  /* END reply_badattr() */
Exemplo n.º 4
0
void reply_badattr(

  int                   code,
  int                   aux,
  svrattrl             *pal,
  struct batch_request *preq)

  {
  int   i = 1;
  char  msgbuf[ERR_MSG_SIZE+1];

  set_err_msg(code, msgbuf, sizeof(msgbuf));

  while (pal)
    {
    if (i == aux)
      {
      int len = strlen(msgbuf);

      if (pal->al_resc)
        snprintf(msgbuf + len, sizeof(msgbuf) - len, " %s.%s", pal->al_name, pal->al_resc);
      else
        snprintf(msgbuf + len, sizeof(msgbuf) - len, " %s", pal->al_name);

      break;
      }

    pal = (svrattrl *)GET_NEXT(pal->al_link);

    ++i;
    }

  reply_text(preq, code, msgbuf);

  return;
  }  /* END reply_badattr() */
Exemplo n.º 5
0
int parse_data_file(struct Params *params, struct Layout *layout)
{
    FILE *ifp, *ofp;
    int nrecord;      /* number of result records in data file */
    int nrec;         /* number of records read so far */
    int ncolumn;      /* number of columns in regression results */
    size_t nbytes;    /* number of bytes used by regression results */
    char *buf;        /* buffer to hold regression result bytes */
    double *v;        /* buffer to hold actual regression results */
    int snp;          /* index of snp in current trait-snp pair */
    int trait;        /* index of trait in current trait-snp pair */
    int i;

    if ((ifp = fopen(params->data_file, "rb")) == NULL) {
        set_err_msg("failed to open file for reading: %s",
                    params->data_file);
        goto RETURN_ZERO;
    }

    if (params->output_file == NULL)
        ofp = stdout;
    else if ((ofp = fopen(params->output_file, "wb")) == NULL) {
        set_err_msg("failed to open file for writing: %s",
                    params->output_file);
        goto CLOSE_DATA_FILE;
    }

    /* Allocate a buffer large enough to hold the bytes containing the
       regression results of a single trait-snp pair.  There are nvar
       betas, nvar standard errors, and ncov covariances.  Each value
       represents a double of bytes_per_double bytes. */
    ncolumn = layout->nvar + layout->nvar + layout->ncov;
    nbytes = ncolumn * layout->bytes_per_double;
    if ((buf = (char *) malloc(nbytes)) == NULL) {
        set_err_msg("failed to allocate %lu bytes",
                    (unsigned long) nbytes);
        goto CLOSE_OUTPUT_FILE;
    }

    /* Print header. */
    fprintf(ofp, "snp trait");
    if (params->columns != NULL)
        for (i = 0; i < params->ncolumn; i++)
            fprintf(ofp, " %s", params->columns[i]);
    else {
        for (i = 0; i < layout->nvar; i++)
            fprintf(ofp, " %s", layout->beta_labels[i]);
        for (i = 0; i < layout->nvar; i++)
            fprintf(ofp, " %s", layout->se_labels[i]);
        for (i = 0; i < layout->ncov; i++)
            fprintf(ofp, " %s", layout->cov_labels[i]);
    }
    fprintf(ofp, "\n");

    nrecord = layout->nsnp * layout->ntrait;
    nrec = 0;
    while (nrec < nrecord) {
        assert(1 == fread(buf, nbytes, 1, ifp));
        v = (double *) buf;
        offset2index(nrec, &snp, &trait, layout);
        fprintf(ofp, "%s %s", layout->snp_labels[snp],
                layout->trait_labels[trait]);
        if (params->ncolumn)
            for (i = 0; i < params->ncolumn; i++)
                fprintf(ofp, " %.*g", params->ndigit,
                        v[params->ucp2acp[i]]);
        else
            for (i = 0; i < ncolumn; i++)
                fprintf(ofp, " %.*g", params->ndigit, v[i]);
        fprintf(ofp, "\n");
        ++nrec;
    }

    free(buf);

    if (params->output_file != NULL  &&  fclose(ofp)) {
        set_err_msg("failed to close file: %s",
                    params->output_file);
        goto CLOSE_DATA_FILE;
    }

    if (fclose(ifp)) {
        set_err_msg("failed to close file: %s",
                    params->data_file);
        goto RETURN_ZERO;
    }

    return 1;

    /* Don't use set_err_msg from here on: if we got here, it means
       there already was a problem and set_err_msg was used.  Using it
       again would overwrite the error message which states the
       initial problem and thus the actual reason behind the 0 return
       value. */
CLOSE_OUTPUT_FILE:
    if (params->output_file != NULL)
        fclose(ofp);
CLOSE_DATA_FILE:
    fclose(ifp);
RETURN_ZERO:
    return 0;
}