/** * Initializes this module: * - Opens the product-queue named by `getQueuePath()`; * - Redirects the standard input stream to the given input file; * - Initializes the structure `prod`; and * - Initializes the PRNG module associated with the function `random()`. * * @retval true if and only if successful. */ static bool pti_init(void) { int success = false; const char* const pqfname = getQueuePath(); int status = pq_open(pqfname, PQ_DEFAULT, &pq); if (PQ_CORRUPT == status) { log_add("The product-queue \"%s\" is corrupt\n", pqfname); } else if (status) { log_errno_q(status, "Couldn't open product-queue \"%s\"", pqfname); } else { prod.data = malloc(max_prod_size); if (prod.data == NULL) { log_syserr_q("Couldn't allocate buffer for data-product"); } else { (void)strncpy(myname, ghostname(), sizeof(myname)); myname[sizeof(myname)-1] = 0; prod.info.origin = myname; prod.info.feedtype = feedtype; srandom(1); // for `random()` seed[2] = random(); seed[1] = random(); seed[0] = random(); (void)seed48(seed); // for `mrand48()` success = true; } } return success; }
/*ARGSUSED0*/ int cfGetProduct( pq_match mt, const prod_class_t* clss, prod_info* info, void** data, void** encProd, size_t* len) { int status; if (currState != READY) { log_error_q("Configuration file not ready"); status = ENOENT; } else { ensure_delay(); *info = prodInfo; status = set_timestamp(&info->arrival); if (status != 0) { log_errno_q(status, "Couldn't set product arrival time"); } else { XDR xdr; info->seqno = ++prodCount; nextSignature(&info->signature); prod.info = *info; *data = prodData; *len = prodXdrLen; *encProd = prodXdrBuf; xdrmem_create(&xdr, *encProd, *len, XDR_ENCODE); if(xdr_product(&xdr, &prod)) { status = ENOERR; } else { log_error_q("Couldn't XDR_ENCODE product"); status = EIO; } xdr_destroy(&xdr); } } return status; }