]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
openr2(2/6): Stop polling channels when DAHDI returns -ENODEV (e.g: plug-out)
authorTzafrir Cohen <tzafrir.cohen@xorcom.com>
Mon, 22 Apr 2019 12:33:16 +0000 (15:33 +0300)
committerGeorge Joseph <gjoseph@digium.com>
Tue, 23 Jul 2019 19:24:42 +0000 (14:24 -0500)
Otherwise, OpenR2 threads go crazy and consume almost all CPU resources

Change-Id: I10a41f617613fe7399c5bdced5c64a2751173f28
Signed-off-by: Oron Peled <oron.peled@xorcom.com>
channels/chan_dahdi.c

index fb633073f4c0446e7f803a0fdf069272582467bc..6340d7f414496975bcca79e00526486c98f8a4f8 100644 (file)
@@ -761,6 +761,7 @@ struct dahdi_mfcr2 {
        openr2_context_t *protocol_context;    /*!< OpenR2 context handle */
        struct dahdi_pvt *pvts[SIG_MFCR2_MAX_CHANNELS];     /*!< Member channel pvt structs */
        int numchans;                          /*!< Number of channels in this R2 block */
+       int nodev;                             /*!< Link disconnected? */
        struct dahdi_mfcr2_conf conf;         /*!< Configuration used to setup this pseudo-link */
 };
 
@@ -3703,7 +3704,19 @@ static void dahdi_r2_on_hardware_alarm(openr2_chan_t *r2chan, int alarm)
 
 static void dahdi_r2_on_os_error(openr2_chan_t *r2chan, int errorcode)
 {
+       struct dahdi_pvt *p = openr2_chan_get_client_data(r2chan);
+
        ast_log(LOG_ERROR, "OS error on chan %d: %s\n", openr2_chan_get_number(r2chan), strerror(errorcode));
+       ast_mutex_lock(&p->lock);
+       /* Disconnected? */
+       if (errorcode == ENODEV) {
+               struct dahdi_mfcr2 *r2link = p->mfcr2;
+               p->mfcr2call = 0;
+               if (r2link) {
+                       r2link->nodev = 1;
+               }
+       }
+       ast_mutex_unlock(&p->lock);
 }
 
 static void dahdi_r2_on_protocol_error(openr2_chan_t *r2chan, openr2_protocol_error_t reason)
@@ -13844,6 +13857,9 @@ static void *mfcr2_monitor(void *data)
                        if (mfcr2->pvts[i]->owner) {
                                continue;
                        }
+                       if (mfcr2->nodev) {
+                               continue;
+                       }
                        if (!mfcr2->pvts[i]->r2chan) {
                                ast_debug(1, "Wow, no r2chan on channel %d\n", mfcr2->pvts[i]->channel);
                                quit_loop = 1;