Changeset d7d3267 for lib/trace.c
- Timestamp:
- 11/29/18 13:37:20 (2 years ago)
- Branches:
- develop
- Children:
- 50e9c6b
- Parents:
- 54642da (diff), fdf23b8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/trace.c
r4161a69 rd7d3267 122 122 char *ret=(char*)malloc(n+1); 123 123 if (ret==NULL) { 124 fprintf(stderr,"Out of memory ");124 fprintf(stderr,"Out of memory\n"); 125 125 exit(EXIT_FAILURE); 126 126 } … … 201 201 202 202 libtrace->io = wandio_create(filename); 203 if (!libtrace->io) 203 if (!libtrace->io) { 204 trace_set_err(libtrace,TRACE_ERR_URI_NOT_FOUND,"Unable to find URI (%s)", filename); 204 205 return; 206 } 205 207 206 208 /* Try and guess based on file magic */ … … 216 218 * used to probe the file magic */ 217 219 wandio_destroy(libtrace->io); 220 trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,"Unable to guess format (%s)", filename); 218 221 return; 219 222 } … … 247 250 trace_init(); 248 251 249 assert(uri && "Passing NULL to trace_create makes me a very sad program");250 251 252 if (!libtrace) { 252 /* Out of memory */ 253 return NULL; 253 fprintf(stderr, "Unable to allocate memory in trace_create()\n"); 254 return NULL; 255 } 256 257 if(!uri) { 258 trace_set_err(libtrace, TRACE_ERR_URI_NULL, "NULL uri passed to trace_create()"); 259 return libtrace; 254 260 } 255 261 … … 272 278 libtrace->accepted_packets = 0; 273 279 libtrace->last_packet = NULL; 274 280 275 281 /* Parallel inits */ 276 282 ASSERT_RET(pthread_mutex_init(&libtrace->libtrace_lock, NULL), == 0); … … 306 312 /* Could not parse the URI nicely */ 307 313 guess_format(libtrace,uri); 308 if (!libtrace->format) { 309 trace_set_err(libtrace,TRACE_ERR_BAD_FORMAT,"Unable to guess format (%s)",uri); 314 if (trace_is_err(libtrace)) { 310 315 return libtrace; 311 316 } … … 339 344 if (libtrace->format->init_input) { 340 345 int err=libtrace->format->init_input(libtrace); 341 assert (err==-1 || err==0);342 346 if (err==-1) { 343 347 /* init_input should call trace_set_err to set the … … 398 402 libtrace->accepted_packets = 0; 399 403 libtrace->last_packet = NULL; 400 404 401 405 /* Parallel inits */ 402 406 ASSERT_RET(pthread_mutex_init(&libtrace->libtrace_lock, NULL), == 0); … … 498 502 499 503 if (libtrace->format->init_output) { 500 /* 0 on success, -1 on failure */ 501 switch(libtrace->format->init_output(libtrace)) { 502 case -1: /* failure */ 503 return libtrace; 504 case 0: /* success */ 505 break; 506 default: 507 assert(!"Internal error: init_output() should return -1 for failure, or 0 for success"); 504 int err = libtrace->format->init_output(libtrace); 505 if (err == -1) { 506 /* init_output should call trace_set_err to set the 507 * error message 508 */ 509 return libtrace; 508 510 } 509 511 } else { … … 527 529 DLLEXPORT int trace_start(libtrace_t *libtrace) 528 530 { 529 assert(libtrace); 531 if(!libtrace) { 532 fprintf(stderr, "NULL trace passed to trace_start()\n"); 533 return TRACE_ERR_NULL_TRACE; 534 } 535 530 536 if (trace_is_err(libtrace)) 531 537 return -1; … … 544 550 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 545 551 { 546 assert(libtrace); 552 if(!libtrace) { 553 fprintf(stderr, "NULL trace passed to trace_start_output()\n"); 554 return TRACE_ERR_NULL_TRACE; 555 } 547 556 if (libtrace->format->start_output) { 548 557 int ret=libtrace->format->start_output(libtrace); … … 558 567 DLLEXPORT int trace_pause(libtrace_t *libtrace) 559 568 { 560 assert(libtrace); 569 if(!libtrace) { 570 fprintf(stderr, "NULL trace passed to trace_pause()\n"); 571 return TRACE_ERR_NULL_TRACE; 572 } 561 573 if (!libtrace->started) { 562 574 trace_set_err(libtrace,TRACE_ERR_BAD_STATE, "You must call trace_start() before calling trace_pause()"); … … 567 579 if (!libtrace_parallel && libtrace->last_packet) 568 580 trace_fin_packet(libtrace->last_packet); 569 assert(libtrace->last_packet == NULL); 581 if(libtrace->last_packet != NULL) { 582 trace_set_err(libtrace, TRACE_ERR_PAUSE_FIN, "Unable to remove all data stored against trace in trace_pause()"); 583 return -1; 584 } 570 585 571 586 if (libtrace->format->pause_input) … … 707 722 DLLEXPORT void trace_destroy(libtrace_t *libtrace) { 708 723 int i; 709 assert(libtrace); 724 725 if(!libtrace) { 726 fprintf(stderr, "NULL trace passed to trace_destroy()\n"); 727 return; 728 } 710 729 711 730 ASSERT_RET(pthread_mutex_destroy(&libtrace->libtrace_lock), == 0); … … 728 747 trace_fin_packet(libtrace->last_packet); 729 748 } 730 assert(libtrace->last_packet == NULL); 749 if (libtrace->last_packet != NULL) { 750 trace_set_err(libtrace, TRACE_ERR_PAUSE_FIN, "Unable to remove all data stored against trace in trace_destroy()"); 751 return; 752 } 731 753 732 754 if (libtrace->format) { … … 742 764 if (libtrace->stats) 743 765 free(libtrace->stats); 744 766 745 767 /* Empty any packet memory */ 746 768 if (libtrace->state != STATE_NEW) { … … 796 818 797 819 DLLEXPORT void trace_destroy_dead(libtrace_t *libtrace) { 798 assert(libtrace); 820 if(!libtrace) { 821 fprintf(stderr, "NULL trace passed to trace_destroy_dead()\n"); 822 return; 823 } 799 824 800 825 ASSERT_RET(pthread_mutex_destroy(&libtrace->libtrace_lock), == 0); … … 813 838 * @param libtrace the output trace file to be destroyed 814 839 */ 815 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 816 { 817 assert(libtrace); 840 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) { 841 if(!libtrace) { 842 fprintf(stderr, "NULL trace passed to trace_destroy_output()\n"); 843 return; 844 } 818 845 if (libtrace->format && libtrace->format->fin_output) 819 846 libtrace->format->fin_output(libtrace); … … 825 852 DLLEXPORT int trace_flush_output(libtrace_out_t *libtrace) { 826 853 if (!libtrace) { 827 return -1; 854 fprintf(stderr, "NULL trace passed to trace_flush_output()\n"); 855 return TRACE_ERR_NULL_TRACE; 828 856 } 829 857 if (libtrace->format && libtrace->format->flush_output) { 830 858 return libtrace->format->flush_output(libtrace); 831 859 } 832 return 0; 860 861 return 0; 833 862 } 834 863 … … 897 926 packet->trace->last_packet = NULL; 898 927 } 899 928 900 929 if (packet->buf_control == TRACE_CTRL_PACKET && packet->buffer) { 901 930 free(packet->buffer); … … 958 987 DLLEXPORT int trace_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet) { 959 988 960 assert(libtrace && "You called trace_read_packet() with a NULL libtrace parameter!\n"); 989 if (!libtrace) { 990 fprintf(stderr, "NULL trace passed to trace_read_packet()\n"); 991 return TRACE_ERR_NULL_TRACE; 992 } 993 961 994 if (trace_is_err(libtrace)) 962 995 return -1; 996 963 997 if (!libtrace->started) { 964 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"You must call libtrace_start() before trace_read_packet() \n");998 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"You must call libtrace_start() before trace_read_packet()"); 965 999 return -1; 966 1000 } 1001 1002 if (!packet) { 1003 trace_set_err(libtrace, TRACE_ERR_NULL_PACKET, "NULL packet passed into trace_read_packet()"); 1004 return -1; 1005 } 1006 967 1007 if (!(packet->buf_control==TRACE_CTRL_PACKET 968 1008 || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 969 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid \n");1009 trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid"); 970 1010 return -1; 971 1011 } 972 assert(packet);973 1012 974 1013 if (libtrace->format->read_packet) { … … 1052 1091 void *buffer, libtrace_rt_types_t rt_type, uint32_t flags) { 1053 1092 1054 assert(packet); 1055 assert(trace); 1056 1057 /* XXX Proper error handling?? */ 1058 if (buffer == NULL) 1093 if (!trace) { 1094 fprintf(stderr, "NULL trace passed into trace_prepare_packet()\n"); 1095 return TRACE_ERR_NULL_TRACE; 1096 } 1097 1098 if (!packet) { 1099 trace_set_err(trace, TRACE_ERR_NULL_TRACE, "NULL packet passed into trace_prepare_packet()"); 1059 1100 return -1; 1101 } 1102 1103 if (!buffer) { 1104 trace_set_err(trace, TRACE_ERR_NULL_BUFFER, "NULL buffer passed into trace_prepare_packet()"); 1105 return -1; 1106 } 1060 1107 1061 1108 if (!(packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)) { 1062 trace_set_err(trace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid \n");1109 trace_set_err(trace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid"); 1063 1110 return -1; 1064 1111 } … … 1075 1122 } 1076 1123 trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 1077 "This format does not support preparing packets \n");1124 "This format does not support preparing packets"); 1078 1125 return -1; 1079 1126 … … 1087 1134 */ 1088 1135 DLLEXPORT int trace_write_packet(libtrace_out_t *libtrace, libtrace_packet_t *packet) { 1089 assert(libtrace); 1090 assert(packet); 1136 1137 if (!libtrace) { 1138 fprintf(stderr, "NULL trace passed into trace_write_packet()\n"); 1139 return TRACE_ERR_NULL_TRACE; 1140 } 1141 if (!packet) { 1142 trace_set_err_out(libtrace, TRACE_ERR_NULL_PACKET, "NULL trace passed into trace_write_packet()"); 1143 return -1; 1144 } 1091 1145 /* Verify the packet is valid */ 1092 1146 if (!libtrace->started) { 1093 1147 trace_set_err_out(libtrace,TRACE_ERR_BAD_STATE, 1094 " Trace is not started before trace_write_packet");1148 "You must call trace_start_output() before calling trace_write_packet()"); 1095 1149 return -1; 1096 1150 } … … 1117 1171 libtrace_linktype_t ltype; 1118 1172 1119 assert(packet != NULL); 1173 if (!packet) { 1174 fprintf(stderr, "NULL packet passed into trace_get_packet_buffer()\n"); 1175 return NULL; 1176 } 1120 1177 ltype = trace_get_link_type(packet); 1121 1178 … … 1149 1206 wire_len = trace_get_wire_length(packet); 1150 1207 1151 assert(cap_len >= 0); 1208 if (!(cap_len >= 0)) { 1209 fprintf(stderr, "Was expecting capture length of atleast 0 in trace_get_packet_buffer()\n"); 1210 return NULL; 1211 } 1152 1212 1153 1213 /* There is the odd corrupt packet, e.g. in IPLS II, that have … … 1341 1401 } 1342 1402 1343 assert(packet->capture_length < LIBTRACE_PACKET_BUFSIZE); 1403 if (!(packet->capture_length < LIBTRACE_PACKET_BUFSIZE)) { 1404 fprintf(stderr, "Capture length is greater than the buffer size in trace_get_capture_length()\n"); 1405 return 0; 1406 /* should we be returning ~OU here? */ 1407 } 1344 1408 1345 1409 return packet->capture_length; … … 1366 1430 } 1367 1431 1368 assert(packet->wire_length < LIBTRACE_PACKET_BUFSIZE); 1432 if (!(packet->wire_length < LIBTRACE_PACKET_BUFSIZE)) { 1433 fprintf(stderr, "Wire length is greater than the buffer size in trace_get_wire_length()\n"); 1434 return 0; 1435 /* should we be returning ~OU here? */ 1436 } 1369 1437 return packet->wire_length; 1370 1438 … … 1432 1500 1433 1501 if (!trace) { 1434 fprintf(stderr,"You called trace_event() with a NULL trace object!\n"); 1435 } 1436 assert(trace); 1437 assert(packet); 1502 fprintf(stderr, "NULL trace passed into trace_event()"); 1503 /* Return default event on error? */ 1504 return event; 1505 } 1506 if (!packet) { 1507 trace_set_err(trace, TRACE_ERR_NULL_PACKET, "NULL packet passed into trace_event()"); 1508 /* Return default event on error? */ 1509 return event; 1510 } 1438 1511 1439 1512 /* Free the last packet */ … … 1537 1610 */ 1538 1611 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 1539 assert(filter); 1612 1613 if (!packet) { 1614 fprintf(stderr, "NULL packet passed into trace_bpf_compile()"); 1615 return TRACE_ERR_NULL_PACKET; 1616 } 1617 1618 if (!filter) { 1619 trace_set_err(packet->trace, 1620 TRACE_ERR_NULL_FILTER, "Filter is NULL trace_bpf_compile()"); 1621 return -1; 1622 } 1540 1623 1541 1624 /* If this isn't a real packet, then fail */ … … 1559 1642 return -1; 1560 1643 } 1561 assert (pthread_mutex_lock(&mutex) == 0);1644 pthread_mutex_lock(&mutex); 1562 1645 /* Make sure not one bet us to this */ 1563 1646 if (filter->flag) { 1564 assert (pthread_mutex_unlock(&mutex) == 0);1565 return 1;1647 pthread_mutex_unlock(&mutex); 1648 return -1; 1566 1649 } 1567 1650 pcap=(pcap_t *)pcap_open_dead( … … 1569 1652 1500U); 1570 1653 /* build filter */ 1571 assert(pcap); 1654 if (!pcap) { 1655 trace_set_err(packet->trace, TRACE_ERR_BAD_FILTER, 1656 "Unable to open pcap_t for compiling filters trace_bpf_compile()"); 1657 return -1; 1658 } 1572 1659 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 1573 1660 1, 0)) { … … 1577 1664 pcap_geterr(pcap)); 1578 1665 pcap_close(pcap); 1579 assert (pthread_mutex_unlock(&mutex) == 0);1666 pthread_mutex_unlock(&mutex); 1580 1667 return -1; 1581 1668 } 1582 1669 pcap_close(pcap); 1583 1670 filter->flag=1; 1584 assert (pthread_mutex_unlock(&mutex) == 0);1671 pthread_mutex_unlock(&mutex); 1585 1672 } 1586 1673 return 0; 1587 1674 #else 1588 assert(!"Internal bug: This should never be called when BPF not enabled");1589 1675 trace_set_err(packet->trace,TRACE_ERR_OPTION_UNAVAIL, 1590 1676 "Feature unavailable"); … … 1606 1692 #endif 1607 1693 1608 assert(filter); 1609 assert(packet); 1694 if (!packet) { 1695 fprintf(stderr, "NULL packet passed into trace_apply_filter()\n"); 1696 return TRACE_ERR_NULL_PACKET; 1697 } 1698 if (!filter) { 1699 trace_set_err(packet->trace, TRACE_ERR_NULL_FILTER, 1700 "NULL filter passed into trace_apply_filter()"); 1701 return -1; 1702 } 1610 1703 1611 1704 /* Match all non-data packets as we probably want them to pass … … 1677 1770 #endif 1678 1771 1679 assert(filter->flag); 1772 if (!filter->flag) { 1773 trace_set_err(packet->trace, TRACE_ERR_BAD_FILTER, 1774 "Bad filter passed into trace_apply_filter()"); 1775 return -1; 1776 } 1680 1777 /* Now execute the filter */ 1681 1778 #if HAVE_LLVM … … 1704 1801 libtrace_direction_t direction) 1705 1802 { 1706 assert(packet); 1803 if (!packet) { 1804 fprintf(stderr, "NULL packet passed into trace_set_direction()\n"); 1805 return (libtrace_direction_t)~0U; 1806 } 1707 1807 if (packet->trace->format->set_direction) { 1708 1808 return packet->trace->format->set_direction(packet,direction); … … 1721 1821 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 1722 1822 { 1723 assert(packet); 1823 if (!packet) { 1824 fprintf(stderr, "NULL packet passed into trace_set_direction()\n"); 1825 return (libtrace_direction_t)~0U; 1826 } 1724 1827 if (packet->which_trace_start != packet->trace->startcount) { 1725 1828 return (libtrace_direction_t)~0U; … … 1858 1961 */ 1859 1962 DLLEXPORT size_t trace_set_capture_length(libtrace_packet_t *packet, size_t size) { 1860 assert(packet); 1963 if (!packet) { 1964 fprintf(stderr, "NULL packet passed into trace_set_capture_length()\n"); 1965 return ~0U; 1966 } 1861 1967 1862 1968 if (packet->trace->format->set_capture_length) { … … 1898 2004 } 1899 2005 1900 enum base_format_t trace_get_format(libtrace_packet_t *packet) 1901 { 1902 assert(packet); 2006 enum base_format_t trace_get_format(libtrace_packet_t *packet) { 2007 if (!packet) { 2008 fprintf(stderr, "NULL packet passed into trace_get_format()\n"); 2009 return TRACE_FORMAT_UNKNOWN; 2010 } 1903 2011 1904 2012 return packet->trace->format->type; … … 2102 2210 libtrace_linktype_t linktype, 2103 2211 const void *data, 2104 uint16_t len) 2105 { 2212 uint16_t len) { 2213 2214 if (!packet) { 2215 fprintf(stderr, "NULL packet passed into trace_contruct_packet()\n"); 2216 return; 2217 } 2218 /* Check a valid linktype was supplied */ 2219 if (linktype == TRACE_TYPE_UNKNOWN || linktype == TRACE_TYPE_CONTENT_INVALID) { 2220 fprintf(stderr, "Unknown or invalid linktype passed into trace_construct_packet()\n"); 2221 return; 2222 } 2223 2106 2224 size_t size; 2107 2225 static libtrace_t *deadtrace=NULL; … … 2133 2251 2134 2252 /* Now fill in the libtrace packet itself */ 2135 assert(deadtrace); 2253 if (!deadtrace) { 2254 fprintf(stderr, "Unable to create dummy trace for use within trace_construct_packet()\n"); 2255 return; 2256 } 2136 2257 packet->trace=deadtrace; 2137 2258 size=len+sizeof(hdr); … … 2165 2286 uint64_t trace_get_received_packets(libtrace_t *trace) 2166 2287 { 2167 assert(trace);2168 2288 uint64_t ret; 2289 2290 if (!trace) { 2291 fprintf(stderr, "NULL trace passed to trace_get_received_packets()\n"); 2292 /* When the number of received packets is not known we return UINT64_MAX */ 2293 return UINT64_MAX; 2294 } 2169 2295 2170 2296 if (trace->format->get_received_packets) { … … 2188 2314 uint64_t trace_get_filtered_packets(libtrace_t *trace) 2189 2315 { 2190 assert(trace); 2316 if (!trace) { 2317 fprintf(stderr, "NULL trace passed to trace_get_filtered_packets()\n"); 2318 return UINT64_MAX; 2319 } 2191 2320 int i = 0; 2192 2321 uint64_t lib_filtered = trace->filtered_packets; … … 2219 2348 uint64_t trace_get_dropped_packets(libtrace_t *trace) 2220 2349 { 2221 assert(trace); 2350 if (!trace) { 2351 fprintf(stderr, "NULL trace passed into trace_get_dropped_packets()\n"); 2352 return UINT64_MAX; 2353 } 2222 2354 uint64_t ret; 2223 2355 … … 2242 2374 uint64_t trace_get_accepted_packets(libtrace_t *trace) 2243 2375 { 2244 assert(trace); 2376 if (!trace) { 2377 fprintf(stderr, "NULL trace passed into trace_get_accepted_packets()\n"); 2378 return UINT64_MAX; 2379 } 2245 2380 int i = 0; 2246 2381 uint64_t ret = 0; … … 2260 2395 uint64_t ret = 0; 2261 2396 int i; 2262 assert(trace); 2397 if (!trace) { 2398 fprintf(stderr, "NULL trace passed into trace_get_statistics()\n"); 2399 return NULL; 2400 } 2263 2401 if (stat == NULL) { 2264 2402 if (trace->stats == NULL) … … 2266 2404 stat = trace->stats; 2267 2405 } 2268 assert(stat->magic == LIBTRACE_STAT_MAGIC && "Please use" 2269 "trace_create_statistics() to allocate statistics"); 2406 if (stat->magic != LIBTRACE_STAT_MAGIC) { 2407 trace_set_err(trace, TRACE_ERR_STAT, "Use trace_create_statistics() to allocate " 2408 "statistics prior to calling trace_get_statistics()"); 2409 return NULL; 2410 } 2270 2411 2271 2412 /* If the trace has paused or finished get the cached results */ … … 2313 2454 libtrace_stat_t *stat) 2314 2455 { 2315 assert(trace && stat); 2316 assert(stat->magic == LIBTRACE_STAT_MAGIC && "Please use" 2317 "trace_create_statistics() to allocate statistics"); 2456 if (!trace) { 2457 fprintf(stderr, "NULL trace passed into trace_get_thread_statistics()\n"); 2458 return; 2459 } 2460 if (!stat) { 2461 trace_set_err(trace, TRACE_ERR_STAT, "NULL statistics structure passed into " 2462 "trace_get_thread_statistics()"); 2463 return; 2464 } 2465 if (stat->magic != LIBTRACE_STAT_MAGIC) { 2466 trace_set_err(trace, TRACE_ERR_STAT, "Use trace_create_statistics() to " 2467 "allocate statistics prior to calling trace_get_thread_statistics()"); 2468 return; 2469 } 2318 2470 stat->reserved1 = 0; 2319 2471 stat->reserved2 = 0; … … 2328 2480 trace->format->get_thread_statistics(trace, t, stat); 2329 2481 } 2330 return;2331 2482 } 2332 2483 … … 2348 2499 void trace_subtract_statistics(const libtrace_stat_t *a, const libtrace_stat_t *b, 2349 2500 libtrace_stat_t *c) { 2350 assert(a->magic == LIBTRACE_STAT_MAGIC && "Please use" 2351 "trace_create_statistics() to allocate statistics"); 2352 assert(b->magic == LIBTRACE_STAT_MAGIC && "Please use" 2353 "trace_create_statistics() to allocate statistics"); 2354 assert(c->magic == LIBTRACE_STAT_MAGIC && "Please use" 2355 "trace_create_statistics() to allocate statistics"); 2501 2502 if (a->magic != LIBTRACE_STAT_MAGIC 2503 || b->magic != LIBTRACE_STAT_MAGIC 2504 || c->magic != LIBTRACE_STAT_MAGIC) { 2505 fprintf(stderr, "Use trace_create_statistics() to allocate statistics prior to " 2506 "calling trace_subtract_statistics()\n"); 2507 return; 2508 } 2356 2509 2357 2510 #define X(x) \ … … 2368 2521 void trace_add_statistics(const libtrace_stat_t *a, const libtrace_stat_t *b, 2369 2522 libtrace_stat_t *c) { 2370 assert(a->magic == LIBTRACE_STAT_MAGIC && "Please use" 2371 "trace_create_statistics() to allocate statistics"); 2372 assert(b->magic == LIBTRACE_STAT_MAGIC && "Please use" 2373 "trace_create_statistics() to allocate statistics"); 2374 assert(c->magic == LIBTRACE_STAT_MAGIC && "Please use" 2375 "trace_create_statistics() to allocate statistics"); 2523 if (a->magic != LIBTRACE_STAT_MAGIC 2524 || b->magic != LIBTRACE_STAT_MAGIC 2525 || c->magic != LIBTRACE_STAT_MAGIC) { 2526 fprintf(stderr, "Use trace_create_statistics() to allocate statistics prior to " 2527 "calling trace_add_statistics()\n"); 2528 return; 2529 } 2376 2530 2377 2531 #define X(x) \ … … 2387 2541 2388 2542 int trace_print_statistics(const libtrace_stat_t *s, FILE *f, const char *format) { 2389 assert(s->magic == LIBTRACE_STAT_MAGIC && "Please use" 2390 "trace_create_statistics() to allocate statistics"); 2543 if (s->magic != LIBTRACE_STAT_MAGIC) { 2544 fprintf(stderr, "Use trace_create_statistics() to allocate statistics prior to " 2545 "calling trace_print_statistics\n"); 2546 return TRACE_ERR_STAT; 2547 } 2391 2548 if (format == NULL) 2392 2549 format = "%s: %"PRIu64"\n"; … … 2427 2584 2428 2585 void register_format(struct libtrace_format_t *f) { 2429 assert(f->next==NULL); /* Can't register a format twice */ 2586 if (f->next != NULL) { 2587 fprintf(stderr, "You cannot register a format twice in register_format()"); 2588 return; 2589 } 2430 2590 f->next=formats_list; 2431 2591 formats_list=f;
Note: See TracChangeset
for help on using the changeset viewer.