static void readTrace(struct tr *tr, char *names, value * covPtr) { struct cfile *cf; int nSelect; T_TESTLIST *selectList; int i; value cov; nSelect = 0; /* No tests seen so far. */ /* * Read trace data and create selectList. */ cf = (struct cfile *) cf_openIn(tr->traces[0]); if (cf == NULL) { fprintf(stderr, "can't open %s\n", tr->traces[0]); exit(1); } selectList = NULL; trace_data(cf, tr->traces[0], tr->mod, tr->n_static, tr->covCount, tr->options, names, &selectList, &nSelect); cf_close(cf); if (nSelect == 1) { covThreshold(selectList[0].cov, tr->covCount, tr->threshold); if (tr->weaker) { covWeaker(tr->mod, tr->n_static, selectList[0].cov, tr->options); } *covPtr = selectList[0].cov; free(selectList); } else { if (nSelect > 1) { fprintf(stderr, "%d: Huh? nSelect should be 1\n", nSelect); exit(1); } if (selectList != NULL) { fprintf(stderr, "Warning: selectList not NULL\n"); selectList = NULL; } cov = (value) malloc((size_t) tr->covCount * sizeof *cov); if (cov == NULL) { fprintf(stderr, "Can't malloc\n"); exit(1); } for (i = 0; i < tr->covCount; ++i) cov[i] = 0; *covPtr = cov; } return; }
int main(int argc, char **argv) { int verdict; unsigned char buf[BUFSIZE]; struct ipq_handle *h; int cfd; int daemonize = 1; if (argc > 1) { if (!strcmp(argv[1], "-nd")) { daemonize = 0; } } srand(0); cfd = make_ipc(); if ( cfd < 0 ) exit(1); printhelp(); h = make_ipq(); if (daemonize) { FILE *logfile = 0; int pid; logfile = fopen(LOGFILE, "a"); if (!logfile) { perror("Failed to open " LOGFILE); exit(1); } if ( daemon(0, 0) < 0 ) { perror("Failed to daemonize"); exit(1); } if ( dup2(fileno(logfile), STDERR_FILENO) < 0 ) abort(); fclose(logfile); pid = writepid(); if (pid < 0) return -1; /* disable low water mark check for io pages */ if (setpriority(PRIO_PROCESS, pid, PRIO_SPECIAL_IO)) { perror("Unable to prioritize tapdisk proc"); exit(1); } TRACE("Start pfilter PID %d\n", pid); } do { ssize_t status; int type; status = ipq_read(h, buf, BUFSIZE, 0); if (status < 0) fail_retry(&h); type = ipq_message_type(buf); switch (type) { case NLMSG_ERROR: TRACE("pfilter: Received error message %d\n", ipq_get_msgerr(buf)); break; case IPQM_PACKET: { ipq_packet_msg_t *m = ipq_get_packet(buf); verdict = filter(); status = ipq_set_verdict(h, m->packet_id, verdict, 0, NULL); if (status < 0) fail_retry(&h); trace_data(verdict); break; } default: TRACE("pfilter: Unknown message type: %d\n", type); break; } } while (1); ipq_destroy_handle(h); return 0; }