The "trylock" test patch.
[lcr.git] / chan_lcr.c
index 6a953a2..5968733 100644 (file)
@@ -223,6 +223,13 @@ struct admin_list {
 
 static struct ast_channel_tech lcr_tech;
 
+void lock_debug(char *text)
+{
+       pthread_t tid = pthread_self();
+//     printf("%s|%03x\n", text, ((tid>>6) | (tid>>3) | tid) & 0xfff); fflush(stdout);
+       printf(" %s(%x) ", text, (int)tid); fflush(stdout);
+}
+
 /*
  * logging
  */
@@ -233,7 +240,9 @@ void chan_lcr_log(int type, const char *file, int line, const char *function, st
        char ast_text[128] = "NULL";
        va_list args;
 
+       lock_debug("L+");
        ast_mutex_lock(&log_lock);
+       lock_debug("L-");
 
        va_start(args,fmt);
        vsnprintf(buffer,sizeof(buffer)-1,fmt,args);
@@ -245,10 +254,12 @@ void chan_lcr_log(int type, const char *file, int line, const char *function, st
        if (ast)
                strncpy(ast_text, ast->name, sizeof(ast_text)-1);
        ast_text[sizeof(ast_text)-1] = '\0';
-       
-       ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer);
+
+printf("\n[call=%s ast=%s] %s\n", call_text, ast_text, buffer);
+//     ast_log(type, file, line, function, "[call=%s ast=%s] %s", call_text, ast_text, buffer);
 
        ast_mutex_unlock(&log_lock);
+       lock_debug("l");
 }
 
 /*
@@ -884,7 +895,7 @@ static void lcr_in_setup(struct chan_call *call, int message_type, union paramet
        if (param->setup.callerinfo.name[0])
                ast->cid.cid_name = strdup(param->setup.callerinfo.name);
        if (param->setup.redirinfo.id[0])
-               ast->cid.cid_name = strdup(numberrize_callerinfo(param->setup.callerinfo.id, param->setup.callerinfo.ntype, options.national, options.international));
+               ast->cid.cid_rdnis = strdup(numberrize_callerinfo(param->setup.redirinfo.id, param->setup.redirinfo.ntype, options.national, options.international));
        switch (param->setup.callerinfo.present) {
                case INFO_PRESENT_ALLOWED:
                        ast->cid.cid_pres = AST_PRES_ALLOWED;
@@ -1254,6 +1265,7 @@ int receive_message(int message_type, unsigned int ref, union parameter *param)
        if (message_type == MESSAGE_BCHANNEL) {
                switch(param->bchannel.type) {
                        case BCHANNEL_ASSIGN:
+lock_debug("rx1");
                        CDEBUG(NULL, NULL, "Received BCHANNEL_ASSIGN message. (handle=%08lx) for ref %d\n", param->bchannel.handle, ref);
                        if ((bchannel = find_bchannel_handle(param->bchannel.handle))) {
                                CERROR(NULL, NULL, "bchannel handle %x already assigned.\n", (int)param->bchannel.handle);
@@ -1518,16 +1530,23 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
        struct admin_list *admin;
        struct admin_message msg;
 
+       lock_debug("handle+");
        if ((what & LCR_FD_READ)) {
                /* read from socket */
+               lock_debug("handle1");
                len = read(lcr_sock, &msg, sizeof(msg));
+               lock_debug("handle2");
                if (len == 0) {
                        CERROR(NULL, NULL, "Socket closed.\n");
                        error:
                        CERROR(NULL, NULL, "Handling of socket failed - closing for some seconds.\n");
+                       lock_debug("handle3");
                        close_socket();
+                       lock_debug("handle4");
                        release_all_calls();
+                       lock_debug("handle5");
                        schedule_timer(&socket_retry, SOCKET_RETRY_TIMER, 0);
+                       lock_debug("handle-");
                        return 0;
                }
                if (len > 0) {
@@ -1539,7 +1558,9 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                                CERROR(NULL, NULL, "Socket received illegal message %d.\n", msg.message);
                                goto error;
                        }
+                       lock_debug("handleX");
                        receive_message(msg.u.msg.type, msg.u.msg.ref, &msg.u.msg.param);
+                       lock_debug("handleY");
                } else {
                        CERROR(NULL, NULL, "Socket failed (errno %d).\n", errno);
                        goto error;
@@ -1550,10 +1571,13 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                /* write to socket */
                if (!admin_first) {
                        socket_fd.when &= ~LCR_FD_WRITE;
+                       lock_debug("handle-");
                        return 0;
                }
+               lock_debug("handle6");
                admin = admin_first;
                len = write(lcr_sock, &admin->msg, sizeof(msg));
+               lock_debug("handle7");
                if (len == 0) {
                        CERROR(NULL, NULL, "Socket closed.\n");
                        goto error;
@@ -1564,6 +1588,7 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                                goto error;
                        }
                        /* free head */
+                       lock_debug("handle8");
                        admin_first = admin->next;
                        free(admin);
                        global_change = 1;
@@ -1573,6 +1598,7 @@ static int handle_socket(struct lcr_fd *fd, unsigned int what, void *instance, i
                }
        }
 
+       lock_debug("handle-");
        return 0;
 }
 
@@ -1645,9 +1671,11 @@ static int wake_event(struct lcr_fd *fd, unsigned int what, void *instance, int
 {
        char byte;
 
+       lock_debug("wake+");
        read(wake_pipe[0], &byte, 1);
 
        wake_global = 0;
+       lock_debug("wake-");
 
        return 0;
 }
@@ -1664,7 +1692,13 @@ static void handle_queue()
                p = call->queue_string;
                ast = call->ast;
                if (*p && ast) {
-                       ast_channel_lock(ast);
+                       lock_debug("A1+");
+                       while (ast_channel_trylock(ast)) {
+                               lock_debug("<trylock failed>");
+                               usleep(1000);
+                               lock_debug("A1++");
+                       }
+                       lock_debug("A1-");
                        while(*p) {
                                switch (*p) {
                                case 'T':
@@ -1721,6 +1755,7 @@ static void handle_queue()
                        }
                        call->queue_string[0] = '\0';
                        ast_channel_unlock(ast);
+                       lock_debug("a1");
                }
                call = call->next;
        }
@@ -1737,12 +1772,15 @@ static int handle_retry(struct lcr_timer *timer, void *instance, int index)
 
 void lock_chan(void)
 {
+       lock_debug("C+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("C-");
 }
 
 void unlock_chan(void)
 {
        ast_mutex_unlock(&chan_lock);
+       lock_debug("c");
 }
 
 /* chan_lcr thread */
@@ -1764,7 +1802,9 @@ static void *chan_thread(void *arg)
        /* open socket the first time */
        handle_retry(NULL, NULL, 0);
 
+       lock_debug("A2+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A2-");
 
        while(!quit) {
                handle_queue();
@@ -1782,6 +1822,7 @@ static void *chan_thread(void *arg)
        CERROR(NULL, NULL, "Thread exit.\n");
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a2");
 
        return NULL;
 }
@@ -1796,13 +1837,16 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c
        struct ast_channel *ast;
         struct chan_call *call;
 
+       lock_debug("A3+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A3-");
        CDEBUG(NULL, NULL, "Received request from Asterisk. (data=%s)\n", (char *)data);
 
        /* if socket is closed */
        if (lcr_sock < 0) {
                CERROR(NULL, NULL, "Rejecting call from Asterisk, because LCR not running.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a3");
                return NULL;
        }
 
@@ -1811,6 +1855,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c
        if (!call) {
                /* failed to create instance */
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a3");
                return NULL;
        }
 
@@ -1829,6 +1874,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c
                free_call(call);
                /* failed to create instance */
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a3");
                return NULL;
        }
        ast->tech = &lcr_tech;
@@ -1874,6 +1920,7 @@ struct ast_channel *lcr_request(const char *type, int format, void *data, int *c
        apply_opt(call, (char *)opt);
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a3");
        return ast;
 }
 
@@ -1885,7 +1932,9 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout)
        union parameter newparam;
         struct chan_call *call;
 
+       lock_debug("A4+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A4-");
         call = ast->tech_pvt;
         
         #ifdef LCR_FOR_CALLWEAVER
@@ -1896,6 +1945,7 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout)
        if (!call) {
                CERROR(NULL, ast, "Received call from Asterisk, but call instance does not exist.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a4");
                return -1;
        }
 
@@ -1936,6 +1986,7 @@ static int lcr_call(struct ast_channel *ast, char *dest, int timeout)
                        sizeof(call->cid_rdnis)-1);
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a4");
        return 0; 
 }
 
@@ -1969,8 +2020,8 @@ static void send_digit_to_chan(struct ast_channel * ast, char digit )
                 ast_playtones_start(ast,0,dtmf_tones[15], 0);
         else {
                 /* not handled */
-                ast_log(LOG_DEBUG, "Unable to handle DTMF tone "
-                       "'%c' for '%s'\n", digit, ast->name);
+//                ast_log(LOG_DEBUG, "Unable to handle DTMF tone "
+//                     "'%c' for '%s'\n", digit, ast->name);
         }
 }
 
@@ -1993,11 +2044,14 @@ static int lcr_digit(struct ast_channel *ast, char digit)
        if (digit > 126 || digit < 32)
                return 0;
 
+       lock_debug("A5+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A5-");
         call = ast->tech_pvt;
        if (!call) {
                CERROR(NULL, ast, "Received digit from Asterisk, but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a5");
                return -1;
        }
 
@@ -2024,6 +2078,7 @@ static int lcr_digit(struct ast_channel *ast, char digit)
        }
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a5");
 
 #ifdef LCR_FOR_ASTERISK
        return 0;
@@ -2035,7 +2090,9 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat
         struct chan_call *call;
 #endif
 
+       lock_debug("A6+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A6-");
 
         call = ast->tech_pvt;
 
@@ -2044,6 +2101,7 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat
                       "Received digit from Asterisk, "
                       "but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a6");
                return -1;
        }
 
@@ -2054,6 +2112,7 @@ static int lcr_digit_end(struct ast_channel *ast, char digit, unsigned int durat
        }
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a6");
 
        if (inband_dtmf) {
                CDEBUG(call, ast, "-> sending '%c' inband.\n", digit);
@@ -2068,11 +2127,14 @@ static int lcr_answer(struct ast_channel *ast)
        union parameter newparam;
         struct chan_call *call;
 
+       lock_debug("A7+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A7-");
         call = ast->tech_pvt;
        if (!call) {
                CERROR(NULL, ast, "Received answer from Asterisk, but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a7");
                return -1;
        }
        
@@ -2101,6 +2163,7 @@ static int lcr_answer(struct ast_channel *ast)
 //     send_message(MESSAGE_ENABLEKEYPAD, call->ref, &newparam);
        
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a7");
         return 0;
 }
 
@@ -2109,13 +2172,18 @@ static int lcr_hangup(struct ast_channel *ast)
         struct chan_call *call;
        pthread_t tid = pthread_self();
 
-       if (!pthread_equal(tid, chan_tid))
+       if (!pthread_equal(tid, chan_tid)) {
+               lock_debug("H+");
                ast_mutex_lock(&chan_lock);
+               lock_debug("H-");
+       }
         call = ast->tech_pvt;
        if (!call) {
                CERROR(NULL, ast, "Received hangup from Asterisk, but no call instance exists.\n");
-               if (!pthread_equal(tid, chan_tid))
+               if (!pthread_equal(tid, chan_tid)) {
                        ast_mutex_unlock(&chan_lock);
+                       lock_debug("h");
+               }
                return -1;
        }
 
@@ -2136,8 +2204,10 @@ static int lcr_hangup(struct ast_channel *ast)
                        send_release_and_import(call, CAUSE_NORMAL, LOCATION_PRIVATE_LOCAL);
                /* remove call */
                free_call(call);
-               if (!pthread_equal(tid, chan_tid))
+               if (!pthread_equal(tid, chan_tid)) {
                        ast_mutex_unlock(&chan_lock);
+                       lock_debug("h");
+               }
                return 0;
        } else {
                /* ref is not set, due to prepare setup or release */
@@ -2152,8 +2222,10 @@ static int lcr_hangup(struct ast_channel *ast)
                        call->ast = NULL;
                }
        } 
-       if (!pthread_equal(tid, chan_tid))
+       if (!pthread_equal(tid, chan_tid)) {
                ast_mutex_unlock(&chan_lock);
+               lock_debug("h");
+       }
        return 0;
 }
 
@@ -2166,15 +2238,19 @@ static int lcr_write(struct ast_channel *ast, struct ast_frame *f)
        if (!(f->subclass & ast->nativeformats))
                CDEBUG(NULL, ast, "Unexpected format.\n");
        
+       lock_debug("A8+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A8-");
         call = ast->tech_pvt;
        if (!call) {
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a8");
                return -1;
        }
        if (call->bchannel && f->samples)
                bchannel_transmit(call->bchannel, *((unsigned char **)&(f->data)), f->samples);
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a8");
        return 0;
 }
 
@@ -2184,24 +2260,31 @@ static struct ast_frame *lcr_read(struct ast_channel *ast)
         struct chan_call *call;
        int len;
 
+       lock_debug("A9+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A9-");
         call = ast->tech_pvt;
        if (!call) {
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a9");
                return NULL;
        }
        if (call->pipe[0] > -1) {
                if (call->rebuffer && !call->hdlc) {
                        /* Make sure we have a complete 20ms (160byte) frame */
+                       lock_debug("*1");
                        len=read(call->pipe[0],call->read_buff + call->framepos, 160 - call->framepos);
                        if (len > 0) {
                                call->framepos += len;
                        }
                } else {
+                       lock_debug("*2");
                        len = read(call->pipe[0], call->read_buff, sizeof(call->read_buff));
                }
+               lock_debug("*3");
                if (len < 0 && errno == EAGAIN) {
                        ast_mutex_unlock(&chan_lock);
+                       lock_debug("a9");
 
                        #ifdef LCR_FOR_ASTERISK
                        return &ast_null_frame;
@@ -2217,10 +2300,12 @@ static struct ast_frame *lcr_read(struct ast_channel *ast)
                        call->pipe[0] = -1;
                        global_change = 1;
                        ast_mutex_unlock(&chan_lock);
+                       lock_debug("a9");
                        return NULL;
                } else if (call->rebuffer && call->framepos < 160) {
                        /* Not a complete frame, so we send a null-frame */
                        ast_mutex_unlock(&chan_lock);
+                       lock_debug("a9");
                        return &ast_null_frame;
                }
        }
@@ -2238,6 +2323,7 @@ static struct ast_frame *lcr_read(struct ast_channel *ast)
        call->read_fr.delivery = ast_tv(0,0);
        *((unsigned char **)&(call->read_fr.data)) = call->read_buff;
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a9");
 
        return &call->read_fr;
 }
@@ -2247,12 +2333,16 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
        union parameter newparam;
         int res = 0;
         struct chan_call *call;
+       const struct tone_zone_sound *ts = NULL;
 
+       lock_debug("A0+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("A0-");
         call = ast->tech_pvt;
        if (!call) {
                CERROR(NULL, ast, "Received indicate from Asterisk, but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("a0");
                return -1;
        }
 
@@ -2268,6 +2358,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
                                send_message(MESSAGE_DISCONNECT, call->ref, &newparam);
                                /* change state */
                                call->state = CHAN_LCR_STATE_OUT_DISCONNECT;
+                       } else {
+                               CDEBUG(call, ast, "Using Asterisk 'busy' indication\n");
+                               ts = ast_get_indication_tone(ast->zone, "busy");
                        }
                        break;
                 case AST_CONTROL_CONGESTION:
@@ -2280,6 +2373,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
                                send_message(MESSAGE_DISCONNECT, call->ref, &newparam);
                                /* change state */
                                call->state = CHAN_LCR_STATE_OUT_DISCONNECT;
+                       } else {
+                               CDEBUG(call, ast, "Using Asterisk 'congestion' indication\n");
+                               ts = ast_get_indication_tone(ast->zone, "congestion");
                        }
                        break;
                 case AST_CONTROL_PROCEEDING:
@@ -2304,6 +2400,9 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
                                send_message(MESSAGE_ALERTING, call->ref, &newparam);
                                /* change state */
                                call->state = CHAN_LCR_STATE_IN_ALERTING;
+                       } else {
+                               CDEBUG(call, ast, "Using Asterisk 'ring' indication\n");
+                               ts = ast_get_indication_tone(ast->zone, "ring");
                        }
                        break;
                case AST_CONTROL_PROGRESS:
@@ -2318,6 +2417,7 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
                        break;
                 case -1:
                        CDEBUG(call, ast, "Received indicate -1.\n");
+                       ast_playtones_stop(ast);
                         res = -1;
                        break;
 
@@ -2367,8 +2467,13 @@ static int lcr_indicate(struct ast_channel *ast, int cond, const void *data, siz
                        break;
         }
 
+       if (ts && ts->data[0]) {
+               ast_playtones_start(ast, 0, ts->data, 1);
+       }
+
        /* return */
        ast_mutex_unlock(&chan_lock);
+       lock_debug("a0");
         return res;
 }
 
@@ -2383,17 +2488,21 @@ static int lcr_fixup(struct ast_channel *oldast, struct ast_channel *ast)
                return -1;
        }
 
+       lock_debug("Af+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("Af-");
        call = ast->tech_pvt;
        if (!call) {
                CERROR(NULL, ast, "Received fixup from Asterisk, but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("af");
                return -1;
        }
 
        CDEBUG(call, ast, "Received fixup from Asterisk.\n");
        call->ast = ast;
        ast_mutex_unlock(&chan_lock);
+       lock_debug("af");
        return 0;
 }
 
@@ -2405,11 +2514,14 @@ static int lcr_send_text(struct ast_channel *ast, const char *text)
         struct chan_call *call;
        union parameter newparam;
 
+       lock_debug("At+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("At-");
        call = ast->tech_pvt;
        if (!call) {
                CERROR(NULL, ast, "Received send_text from Asterisk, but no call instance exists.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("at");
                return -1;
        }
 
@@ -2417,7 +2529,8 @@ static int lcr_send_text(struct ast_channel *ast, const char *text)
        memset(&newparam, 0, sizeof(union parameter));
        strncpy(newparam.notifyinfo.display, text, sizeof(newparam.notifyinfo.display)-1);
        send_message(MESSAGE_NOTIFY, call->ref, &newparam);
-       ast_mutex_lock(&chan_lock);
+       ast_mutex_unlock(&chan_lock);
+       lock_debug("at");
        return 0;
 }
 
@@ -2442,12 +2555,15 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1,
        carr[1] = ast2;
 
        /* join via dsp (if the channels are currently open) */
+       lock_debug("Ab+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("Ab-");
        call1 = ast1->tech_pvt;
        call2 = ast2->tech_pvt;
        if (!call1 || !call2) {
                CDEBUG(NULL, NULL, "Bridge, but we don't have two call instances, exitting.\n");
                ast_mutex_unlock(&chan_lock);
+               lock_debug("ab");
                return AST_BRIDGE_COMPLETE;
        }
 
@@ -2515,6 +2631,7 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1,
        }
        
        ast_mutex_unlock(&chan_lock);
+       lock_debug("ab");
        
        while(1) {
                to = -1;
@@ -2557,7 +2674,9 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1,
        CDEBUG(NULL, NULL, "Releasing bridge.\n");
 
        /* split channels */
+       lock_debug("Ab+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("Ab-");
        call1 = ast1->tech_pvt;
        call2 = ast2->tech_pvt;
        if (call1 && call1->bridge_id) {
@@ -2578,6 +2697,7 @@ enum ast_bridge_result lcr_bridge(struct ast_channel *ast1,
        call2->bridge_call = NULL;
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("ab");
        return AST_BRIDGE_COMPLETE;
 }
 static struct ast_channel_tech lcr_tech = {
@@ -2708,7 +2828,9 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv)
 {
        struct chan_call *call;
 
+       lock_debug("Ae+");
        ast_mutex_lock(&chan_lock);
+       lock_debug("Ae-");
 
        #ifdef LCR_FOR_ASTERISK
        CDEBUG(NULL, ast, "Received lcr_config (data=%s)\n", (char *)data);
@@ -2739,6 +2861,7 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv)
                CERROR(NULL, ast, "lcr_config app not called by chan_lcr channel.\n");
 
        ast_mutex_unlock(&chan_lock);
+       lock_debug("ae");
        return 0;
 }
 
@@ -2748,13 +2871,14 @@ static int lcr_config_exec(struct ast_channel *ast, void *data, char **argv)
 int load_module(void)
 {
        u_short i;
+       char options_error[256];
 
        for (i = 0; i < 256; i++) {
                flip_bits[i] = (i>>7) | ((i>>5)&2) | ((i>>3)&4) | ((i>>1)&8)
                             | (i<<7) | ((i&2)<<5) | ((i&4)<<3) | ((i&8)<<1);
        }
 
-       if (read_options() == 0) {
+       if (read_options(options_error) == 0) {
                CERROR(NULL, NULL, "%s", options_error);
 
                #ifdef LCR_FOR_ASTERISK
@@ -2908,9 +3032,12 @@ int usecount(void)
 hae
 {
        int res;
+       lock_debug("U+");
        ast_mutex_lock(&usecnt_lock);
+       lock_debug("U-");
        res = usecnt;
        ast_mutex_unlock(&usecnt_lock);
+       lock_debug("u");
        return res;
 }
 #endif