Changeset 8f18776


Ignore:
Timestamp:
11/06/07 14:55:03 (13 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
dc6dc11
Parents:
e53fbe1
Message:

Avoid using assert() to report errors

Location:
lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • lib/libtrace.h.in

    r37592ce r8f18776  
    202202        TRACE_ERR_OPTION_UNAVAIL= -6,
    203203        /** This feature is unsupported */
    204         TRACE_ERR_UNSUPPORTED   = -7
     204        TRACE_ERR_UNSUPPORTED   = -7,
     205        /** Illegal use of the API */
     206        TRACE_ERR_BAD_STATE     = -8
    205207};
    206208
  • lib/protocols_l2.c

    r7daeab9 r8f18776  
    3232                uint32_t *remaining)
    3333{
    34         assert(type && "You must pass a type in!");
    35 
    3634        if (*type == 0x8100) {
    3735                libtrace_8021q_t *vlanhdr = (libtrace_8021q_t *)ethernet;
     
    5957                uint16_t *type, uint32_t *remaining)
    6058{
    61         assert(type && "You must pass a type in!");
    62 
    6359        if (*type == 0x8847) {
    6460                if ((((char*)ethernet)[2]&0x01)==0) {
  • lib/trace.c

    rca1272c r8f18776  
    130130
    131131void register_format(struct libtrace_format_t *f) {
    132         assert(f->next==NULL);
     132        assert(f->next==NULL); /* Can't register a format twice */
    133133        f->next=formats_list;
    134134        formats_list=f;
     
    463463                                break;
    464464                        default:
    465                                 assert(!"init_output() should return -1 for failure, or 0 for success");
     465                                assert(!"Internal error: init_output() should return -1 for failure, or 0 for success");
    466466                }
    467467        } else {
     
    486486{
    487487        assert(libtrace);
    488         assert(!trace_is_err(libtrace) && "Please use trace_is_err to check for errors after calling trace_create!");
     488        if (trace_is_err(libtrace))
     489                return -1;
    489490        if (libtrace->format->start_input) {
    490491                int ret=libtrace->format->start_input(libtrace);
     
    515516{
    516517        assert(libtrace);
    517         assert(libtrace->started && "BUG: Called trace_pause without calling trace_start first");
     518        if (!libtrace->started) {
     519                trace_set_err(libtrace,TRACE_ERR_BAD_STATE, "You must call trace_start() before calling trace_pause()");
     520                return -1;
     521        }
    518522        if (libtrace->format->pause_input)
    519523                libtrace->format->pause_input(libtrace);
     
    528532        int ret;
    529533        libtrace_err_t err;
    530        
    531         assert(!trace_is_err(libtrace) && "Please use trace_is_err to check for errors after calling trace_create!");
     534
     535        if (trace_is_err(libtrace)) {
     536                return -1;
     537        }
    532538       
    533539        if (libtrace->format->config_input) {
     
    698704
    699705        assert(libtrace && "You called trace_read_packet() with a NULL libtrace parameter!\n");
    700         assert(libtrace->started && "BUG: You must call libtrace_start() before trace_read_packet()\n");
     706        if (trace_is_err(libtrace))
     707                return -1;
     708        if (!libtrace->started) {
     709                trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"You must call libtrace_start() before trace_read_packet()\n");
     710                return -1;
     711        }
     712        if (packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL) {
     713                trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid\n");
     714                return -1;
     715        }
    701716        assert(packet);
    702         assert((packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)&&
    703                 "BUG: You must allocate a packet using packet_create()");
    704717     
    705718        /* Store the trace we are reading from into the packet opaque
     
    758771        assert(packet);
    759772        /* Verify the packet is valid */
    760         assert(libtrace->started);
     773        if (!libtrace->started) {
     774                trace_set_err_out(libtrace,TRACE_ERR_BAD_STATE,
     775                        "Trace is not started before trace_write_packet");
     776                return -1;
     777        }
    761778
    762779        if (libtrace->format->write_packet) {
     
    10851102        return 0;
    10861103#else
    1087         assert(!"This should never be called when BPF not enabled");
     1104        assert(!"Internal bug: This never be called when BPF not enabled");
    10881105        trace_set_err(packet->trace,TRACE_ERR_OPTION_UNAVAIL,
    10891106                                "Feature unavailable");
Note: See TracChangeset for help on using the changeset viewer.