Beispiel #1
0
/*
 * Closes an open product queue and frees any allocated resources.  Do not use
 * the product queue structure after this method.
 *
 * pq               The product queue to be closed. (in/out)
 *
 * Returns:
 *   pq.h:ENOERR    if success.
 *   errno.h:EINVAL if the queue argument is NULL or the queue has already been
 *                  closed.
 */
int pq_close(pqueue *pq)
{
    int       status;

    if (pq == NULL || !pq->isOpen) {
        status = EINVAL;
    }
    else {
        pq->isOpen = 0;
        free((void*)pq);
        cfClose();
        status = ENOERR;
    }

    return status;
}
Beispiel #2
0
/* 
 * Opens the configuration file.  Any previously opened configuration file will
 * be closed.  The ulog(3) facility will be used to log any problems.
 *
 * pathname          The pathname of the file. (in)
 *
 * Returns:
 *   pq.h:ENOERR     if success.
 *   errno.h:ENOMEM  if out of memory.
 *   errno.h:EINVAL  if the pathname is NULL or if the configuration file was 
 *                   invalid.
 *   (else)          <errno.h> error code.
 */
int cfOpen(const char* pathname)
{
    int              status;

    if (pathname == NULL) {
        log_error_q("NULL pathname");
        status = EINVAL;
    }
    else {
        if (currState != CLOSED)
            cfClose();

        md5 = new_MD5_CTX();

        if (saxer.startDocument != myStartDocument) {
            saxer.startDocument = myStartDocument;
            saxer.startElement = myStartElement;
            saxer.getEntity = myGetEntity;
            saxer.characters = myCharacters;
            saxer.endElement = myEndElement;
            saxer.endDocument = myEndDocument;
            saxer.warning = xmlWarning;
            saxer.error = xmlError;
            saxer.fatalError = xmlError;
        }

        (void)xmlSAXUserParseFile(&saxer, NULL, pathname);

        if (currState != READY) {
            cfClose();
            status = EINVAL;
        }
        else {
            prodData = realloc(prodData, prodSize);

            if (prodData == NULL) {
                log_syserr_q("Couldn't allocate %u bytes for product data",
                        prodSize);
                status = ENOMEM;
            }
            else {
                (void)memset(prodData, 'x', prodSize);

                prodInfo.origin = (char*)ghostname();
                prodInfo.feedtype = feedType;
                prodInfo.ident = prodId;
                prodInfo.sz = prodSize;
                prodXdrLen = xlen_prod_i(&prodInfo);
                prodXdrBuf = realloc(prodXdrBuf, prodXdrLen);

                if (prodXdrBuf == NULL) {
                    log_syserr_q("Couldn't allocate %lu bytes for product XDR "
                            "buffer", prodXdrLen);
                    status = errno;
                }
                else {
                    prod.data = prodData;
                    status = ENOERR;
                }

                if (status != ENOERR) {
                    free(prodData);
                    prodData = NULL;
                }
            }
        }
    }

    return status;
}